@devries-cameron20 / t3code-1 / commits / 044f07257c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): sidebar follows the active thread after history navigation (#23519)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 22, 2026 at 12:11 UTC 044f07257c9684ae4543bd1e1ebf9c394e9e3830
12 files changed +1119 -17
apps/web/src/components/AppSidebarLayout.tsx
+7 -2
@@ -43,6 +43,7 @@ import ThreadSidebar from "./Sidebar";
43 import { SettingsSidebarNav } from "./settings/SettingsSidebarNav";
44 import { SidebarBrandWidthProbe, SidebarChromeHeader } from "./sidebar/SidebarChrome";
45 import { MainAppLocationTracker } from "./sidebar/mainAppLocation";
46 +import type { SidebarRouteReveal } from "./sidebar/routeReveal";
47 import { useSidebarStageBackdropVariant } from "./SidebarStageBackdrop";
48 import { useProjects } from "../state/entities";
49 import {
@@ -330,6 +331,10 @@ function ProjectProjectionRetention() {
331 export function AppSidebarLayout({ children }: { children: ReactNode }) {
332 const navigate = useNavigate();
333 const legacySidebarEnabled = useLegacySidebarEnabled();
334 + const [sidebarRouteReveal] = useState<SidebarRouteReveal>(() => ({
335 + observedKey: null,
336 + pendingKey: null,
337 + }));
338 const { active: panelAnimationsActive, durationMs: panelAnimationDurationMs } =
339 usePanelAnimationSettings();
340 useThreadVisitedMigration();
@@ -422,9 +427,9 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
427 <SettingsSidebarNav pathname={pathname} />
428 </>
429 ) : legacySidebarEnabled ? (
425 - <LegacyThreadSidebar />
430 + <LegacyThreadSidebar routeReveal={sidebarRouteReveal} />
431 ) : (
427 - <ThreadSidebar />
432 + <ThreadSidebar routeReveal={sidebarRouteReveal} />
433 )}
434 <SidebarRail onDoubleClick={resetSidebarWidth} />
435 </Sidebar>
apps/web/src/components/LegacySidebar.tsx
+51 -14
@@ -223,6 +223,11 @@ import {
223 } from "../sidebarProjectGrouping";
224 import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
225 import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
226 +import {
227 + completeSidebarRouteReveal,
228 + pendingSidebarRouteReveal,
229 + type SidebarRouteReveal,
230 +} from "./sidebar/routeReveal";
231 const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = {
232 updated_at: "Last user message",
233 created_at: "Created at",
@@ -1199,20 +1204,26 @@ function useProjectThreadPanel(input: {
1204 (settings) => settings.sidebarThreadPreviewCount,
1205 );
1206 const activeThreadKey = activeRouteThreadKey ?? undefined;
1202 - const pinnedCollapsedThread =
1203 - !activeThreadKey || projectExpanded
1204 - ? null
1205 - : (visibleProjectThreads.find(
1206 - (thread) =>
1207 - scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)) === activeThreadKey,
1208 - ) ?? null);
1209 - const hasOverflowingThreads = visibleProjectThreads.length > sidebarThreadPreviewCount;
1207 + const activeThread = activeThreadKey
1208 + ? (visibleProjectThreads.find(
1209 + (thread) =>
1210 + scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)) === activeThreadKey,
1211 + ) ?? null)
1212 + : null;
1213 + const pinnedCollapsedThread = projectExpanded ? null : activeThread;
1214 + // The open thread stays listed past the preview cut, as it does in a
1215 + // collapsed project, so it alone does not overflow the preview.
1216 + const hasOverflowingThreads = visibleProjectThreads.some(
1217 + (thread, index) =>
1218 + index >= sidebarThreadPreviewCount &&
1219 + scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)) !== activeThreadKey,
1220 + );
1221 const previewThreads =
1222 isThreadListExpanded || !hasOverflowingThreads
1223 ? visibleProjectThreads
1224 : visibleProjectThreads.slice(0, sidebarThreadPreviewCount);
1225 const visibleThreadKeys = new Set(
1215 - [...previewThreads, ...(pinnedCollapsedThread ? [pinnedCollapsedThread] : [])].map((thread) =>
1226 + [...previewThreads, ...(activeThread ? [activeThread] : [])].map((thread) =>
1227 scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
1228 ),
1229 );
@@ -3202,10 +3213,17 @@ function useLegacySidebarThreads(input: {
3213 isThreadListExpanded || !hasOverflowingThreads
3214 ? projectThreads
3215 : projectThreads.slice(0, sidebarThreadPreviewCount);
3205 - const renderedThreads = pinnedCollapsedThread ? [pinnedCollapsedThread] : previewThreads;
3206 - return renderedThreads.map((thread) =>
3207 - scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
3208 - );
3216 + if (pinnedCollapsedThread) {
3217 + return [
3218 + scopedThreadKey(
3219 + scopeThreadRef(pinnedCollapsedThread.environmentId, pinnedCollapsedThread.id),
3220 + ),
3221 + ];
3222 + }
3223 + return projectThreads.flatMap((thread, index) => {
3224 + const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
3225 + return index < previewThreads.length || threadKey === activeThreadKey ? [threadKey] : [];
3226 + });
3227 });
3228 const threadJumpCommandByKey = new Map<
3229 string,
@@ -3234,7 +3252,7 @@ function useLegacySidebarThreads(input: {
3252 };
3253 }
3254
3237 -export default function LegacySidebar() {
3255 +export default function LegacySidebar({ routeReveal }: { routeReveal: SidebarRouteReveal }) {
3256 const reorderProjects = useUiStateStore((store) => store.reorderProjects);
3257 const navigate = useNavigate();
3258 const sidebarThreadSortOrder = useClientSettings((s) => s.sidebarThreadSortOrder);
@@ -3298,6 +3316,25 @@ export default function LegacySidebar() {
3316 sidebarThreadPreviewCount,
3317 expandedThreadListsByProject,
3318 });
3319 + // History and the command palette can open a thread scrolled out of view,
3320 + // and a remount starts the list at the top, so each route change and each
3321 + // mount scroll to the open thread once. Its row can mount after the route
3322 + // does, once its environment's shells arrive, so the reveal waits for it.
3323 + const mountRevealOwed = useRef(true);
3324 + const routeRowRendered =
3325 + routeThreadKey !== null && visibleSidebarThreadKeys.includes(routeThreadKey);
3326 + const revealRouteRow = useStableCallback(() => {
3327 + const pendingKey = pendingSidebarRouteReveal(routeReveal, routeThreadKey);
3328 + if (pendingKey === null && (!mountRevealOwed.current || routeThreadKey === null)) return;
3329 + const activeRow = document.querySelector(
3330 + '[data-sidebar="content"] [data-thread-item] [data-active="true"]',
3331 + );
3332 + if (!activeRow) return;
3333 + completeSidebarRouteReveal(routeReveal);
3334 + mountRevealOwed.current = false;
3335 + activeRow.scrollIntoView({ block: "nearest" });
3336 + });
3337 + useEffect(revealRouteRow, [revealRouteRow, routeThreadKey, routeRowRendered]);
3338 const newThreadShortcutLabelOptions = {
3339 platform,
3340 context: {
apps/web/src/components/Sidebar.logic.test.ts
+22
@@ -44,6 +44,7 @@ import {
44 type Thread,
45 } from "../types";
46 import { makeThreadFixture, type ThreadFixtureOverrides } from "../test-fixtures";
47 +import { completeSidebarRouteReveal, pendingSidebarRouteReveal } from "./sidebar/routeReveal";
48
49 const localEnvironmentId = EnvironmentId.make("environment-local");
50
@@ -1216,3 +1217,24 @@ describe("Working shelf (beta)", () => {
1217 });
1218 });
1219 });
1220 +
1221 +describe("pendingSidebarRouteReveal", () => {
1222 + it("keeps a revealed thread settled across a mount that reads no route params", () => {
1223 + const reveal = { observedKey: null, pendingKey: null };
1224 + expect(pendingSidebarRouteReveal(reveal, "env:a1")).toBe("env:a1");
1225 + completeSidebarRouteReveal(reveal);
1226 +
1227 + // Back from Settings: location commits before the thread match does.
1228 + expect(pendingSidebarRouteReveal(reveal, null)).toBeNull();
1229 + expect(pendingSidebarRouteReveal(reveal, "env:a1")).toBeNull();
1230 +
1231 + expect(pendingSidebarRouteReveal(reveal, "env:b1")).toBe("env:b1");
1232 + });
1233 +
1234 + it("keeps a pending reveal through a render without route params", () => {
1235 + const reveal = { observedKey: null, pendingKey: null };
1236 + pendingSidebarRouteReveal(reveal, "env:a1");
1237 + expect(pendingSidebarRouteReveal(reveal, null)).toBeNull();
1238 + expect(pendingSidebarRouteReveal(reveal, "env:a1")).toBe("env:a1");
1239 + });
1240 +});
apps/web/src/components/Sidebar.tsx
+44 -1
@@ -179,6 +179,11 @@ import { resolveSnoozePresets, snoozeWakeLabel, type SnoozePreset } from "./Side
179 import { ProjectFavicon } from "./ProjectFavicon";
180 import { deriveProviderEntriesByEnvironment } from "../providerInstances";
181 import { useStableCallback } from "../hooks/useStableCallback";
182 +import {
183 + completeSidebarRouteReveal,
184 + pendingSidebarRouteReveal,
185 + type SidebarRouteReveal,
186 +} from "./sidebar/routeReveal";
187 import { stackedThreadToast, toastManager } from "./ui/toast";
188 import { Button } from "./ui/button";
189 import {
@@ -741,7 +746,7 @@ const SIDEBAR_DRAG_DISTANCE = 6;
746
747 const SIDEBAR_DRAG_LABEL_HEIGHT = 24;
748
744 -export default function Sidebar() {
749 +export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReveal }) {
750 const {
751 projects,
752 serverConfigs,
@@ -1061,6 +1066,44 @@ export default function Sidebar() {
1066 });
1067
1068 const isSearchingThreads = threadSearchQuery.trim().length > 0;
1069 +
1070 + // History, the command palette, and links can open a thread the project
1071 + // scope hides or the list has scrolled away. A remount starts the list at
1072 + // the top, so each mount also scrolls to the open thread once, without
1073 + // widening the scope.
1074 + const mountRevealOwed = useRef(true);
1075 + const revealRouteRow = useStableCallback(() => {
1076 + const pendingKey = pendingSidebarRouteReveal(routeReveal, routeRowThreadKey);
1077 + // Search results replace the thread list; reveal once the list returns.
1078 + if (isSearchingThreads) return;
1079 + const revealKey = pendingKey ?? (mountRevealOwed.current ? routeRowThreadKey : null);
1080 + if (revealKey === null) return;
1081 + const thread = threads.find((candidate) => threadShellKey(candidate) === revealKey);
1082 + if (thread === undefined) return;
1083 + if (
1084 + pendingKey !== null &&
1085 + scopedProjectKeys !== null &&
1086 + filterSidebarV2VisibleThreads([thread], scopedProjectKeys).length === 0 &&
1087 + filterSidebarV2VisibleThreads([thread], null).length === 1
1088 + ) {
1089 + // The row renders under the widened scope; scroll on that pass.
1090 + setProjectScopeKey(null);
1091 + return;
1092 + }
1093 + const activeRow = document.querySelector('[data-sidebar="content"] [aria-current="page"]');
1094 + if (!activeRow) return;
1095 + completeSidebarRouteReveal(routeReveal);
1096 + mountRevealOwed.current = false;
1097 + activeRow.scrollIntoView({ block: "nearest" });
1098 + });
1099 + useEffect(revealRouteRow, [
1100 + revealRouteRow,
1101 + routeRowThreadKey,
1102 + threads,
1103 + projectScopeKey,
1104 + isSearchingThreads,
1105 + ]);
1106 +
1107 const threadSearchMatchByKey = new Map(
1108 threadSearch.matches.map((match) => [threadSearchMatchKey(match), match] as const),
1109 );
apps/web/src/components/sidebar/routeReveal.ts new
+28
@@ -0,0 +1,28 @@
1 +// Owned by AppSidebarLayout because the narrow drawer and Settings unmount the
2 +// thread sidebar without changing the route. Only a route change requests a
3 +// reveal that may widen the project scope, so a scope chosen while one thread
4 +// stays open survives a remount. Scroll position does not survive one.
5 +//
6 +// A null key is not an observation: leaving Settings commits the router's
7 +// location before its matches, so the sidebar's first render can read no
8 +// thread params. Recording that would make the same thread look new.
9 +export interface SidebarRouteReveal {
10 + observedKey: string | null;
11 + pendingKey: string | null;
12 +}
13 +
14 +export function pendingSidebarRouteReveal(
15 + reveal: SidebarRouteReveal,
16 + routeKey: string | null,
17 +): string | null {
18 + if (routeKey === null) return null;
19 + if (reveal.observedKey !== routeKey) {
20 + reveal.observedKey = routeKey;
21 + reveal.pendingKey = routeKey;
22 + }
23 + return reveal.pendingKey;
24 +}
25 +
26 +export function completeSidebarRouteReveal(reveal: SidebarRouteReveal): void {
27 + reveal.pendingKey = null;
28 +}
knip.jsonc
+2
@@ -22,6 +22,8 @@
22 // Windows verify script with esbuild through a path knip does not trace, and
23 // electron-builder loads the macOS signer by path.
24 "entry": [
25 + // These fixture scripts are injected into a browser page by path.
26 + "fixtures/issue-16534/*.js",
27 "knip-schemas.ts",
28 "mobile-native-client.ts",
29 "setup-worktree.ts",
scripts/fixtures/issue-16534/README.md new
+32
@@ -0,0 +1,32 @@
1 +These fixtures reconstruct synthetic sidebar projections and client reset inputs.
2 +They never start a provider or read personal application data. Projection-only
3 +fixtures prove rendering/navigation, not event-sourced backend behavior.
4 +
5 +Generate with `python3 scripts/fixtures/issue-16534/seed.py --output /tmp/sidebar-seed
6 +--variant all`. Stop the isolated server before applying reset-threads.sql,
7 +archive-unrelated-threads.sql, hide-v1-threads.sql, hide-unrelated-projects.sql,
8 +projects.sql, threads.sql, messages.sql, turn-items.sql, transcript-runs.sql,
9 +transcript-messages.sql and transcript-turn-items.sql, in that order, with the documented
10 +`t3-sqlite-state.ts exec` helper, once per file. Never target the live T3 home.
11 +
12 +`all` includes two eight-thread projects, forty spacers, child/grandchild/fork
13 +lineage and synthetic markdown navigation messages. Other variants isolate shelf,
14 +archive and lineage states. `fixture.json` records deterministic clock/settings.
15 +The replay option records stopped synthetic shell representations for working,
16 +status and delayed arrival without spawning providers. `replay.js` transforms
17 +only real shell frames before the real RPC decoder/reducer receives them; delayed
18 +shell frames are released explicitly through `__sidebarReplay.release()`.
19 +
20 +Install bootstrap.js and replay.js as identical pre-module scripts in the served
21 +HTML only for capture. Remove both before committing or switching checkouts.
22 +Use a fresh navigation, never document.write over an evaluated module graph.
23 +Configure `sessionStorage['sidebar-capture-config']` with `{storage, replay}`.
24 +Clear only projection caches (shell/thread/vcs-refs in t3code:connection-runtime)
25 +from a same-origin inert document before navigating to the app. Preserve auth.
26 +Timers and performance.now remain native; only Date is frozen. Record the exact
27 +injection externally with the artifacts.
28 +
29 +For grouping, initialize the three synthetic /tmp/triage-16534-{A,B,Spacer}
30 +paths as git repositories with the same synthetic origin, then use repository
31 +grouping and an explicit separate override for Spacer. No network fetch needed.
32 +All navigation links are synthetic t3-thread links rendered by the real client.
scripts/fixtures/issue-16534/bootstrap.js new
+23
@@ -0,0 +1,23 @@
1 +(() => {
2 + const NativeDate = Date,
3 + epoch = NativeDate.parse("2026-10-22T00:00:00.000Z");
4 + globalThis.Date = new Proxy(NativeDate, {
5 + apply() {
6 + return new NativeDate(epoch).toString();
7 + },
8 + construct(target, args, newTarget) {
9 + return Reflect.construct(target, args.length ? args : [epoch], newTarget);
10 + },
11 + get(target, property, receiver) {
12 + return property === "now" ? () => epoch : Reflect.get(target, property, receiver);
13 + },
14 + });
15 + globalThis.__sidebarCaptureClock = {
16 + epoch,
17 + readyState: document.readyState,
18 + moduleScripts: document.querySelectorAll('script[type="module"]').length,
19 + };
20 + const config = JSON.parse(sessionStorage.getItem("sidebar-capture-config") || "{}");
21 + for (const [key, value] of Object.entries(config.storage || {}))
22 + localStorage.setItem(key, typeof value === "string" ? value : JSON.stringify(value));
23 +})();
scripts/fixtures/issue-16534/plain.json new
+483
@@ -0,0 +1,483 @@
1 +{
2 + "clock": "2026-10-22T00:00:00.000Z",
3 + "settings": {
4 + "legacySidebarEnabled": false,
5 + "sidebarProjectGroupingMode": "separate",
6 + "sidebarProjectSortOrder": "manual",
7 + "sidebarThreadPreviewCount": 6,
8 + "sidebarThreadSortOrder": "updated_at"
9 + },
10 + "threads": [
11 + {
12 + "activeProviderThreadId": null,
13 + "archivedAt": null,
14 + "branch": null,
15 + "createdAt": "2026-10-21T20:01:00.000Z",
16 + "createdBy": "user",
17 + "creationSource": "web",
18 + "deletedAt": null,
19 + "forkedFrom": null,
20 + "id": "triage-A-1",
21 + "interactionMode": "default",
22 + "lastVisitedAt": null,
23 + "lineage": {
24 + "parentThreadId": null,
25 + "relationshipToParent": null,
26 + "rootThreadId": "triage-A-1"
27 + },
28 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
29 + "projectId": "triage-project-A",
30 + "providerInstanceId": "codex",
31 + "runtimeMode": "full-access",
32 + "settledAt": null,
33 + "settledOverride": null,
34 + "snoozedAt": null,
35 + "snoozedUntil": null,
36 + "title": "Triage A thread 1",
37 + "updatedAt": "2026-10-21T20:01:00.000Z",
38 + "worktreePath": null
39 + },
40 + {
41 + "activeProviderThreadId": null,
42 + "archivedAt": null,
43 + "branch": null,
44 + "createdAt": "2026-10-21T20:02:00.000Z",
45 + "createdBy": "user",
46 + "creationSource": "web",
47 + "deletedAt": null,
48 + "forkedFrom": null,
49 + "id": "triage-A-2",
50 + "interactionMode": "default",
51 + "lastVisitedAt": null,
52 + "lineage": {
53 + "parentThreadId": null,
54 + "relationshipToParent": null,
55 + "rootThreadId": "triage-A-2"
56 + },
57 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
58 + "projectId": "triage-project-A",
59 + "providerInstanceId": "codex",
60 + "runtimeMode": "full-access",
61 + "settledAt": null,
62 + "settledOverride": null,
63 + "snoozedAt": null,
64 + "snoozedUntil": null,
65 + "title": "Triage A thread 2",
66 + "updatedAt": "2026-10-21T20:02:00.000Z",
67 + "worktreePath": null
68 + },
69 + {
70 + "activeProviderThreadId": null,
71 + "archivedAt": null,
72 + "branch": null,
73 + "createdAt": "2026-10-21T20:03:00.000Z",
74 + "createdBy": "user",
75 + "creationSource": "web",
76 + "deletedAt": null,
77 + "forkedFrom": null,
78 + "id": "triage-A-3",
79 + "interactionMode": "default",
80 + "lastVisitedAt": null,
81 + "lineage": {
82 + "parentThreadId": null,
83 + "relationshipToParent": null,
84 + "rootThreadId": "triage-A-3"
85 + },
86 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
87 + "projectId": "triage-project-A",
88 + "providerInstanceId": "codex",
89 + "runtimeMode": "full-access",
90 + "settledAt": null,
91 + "settledOverride": null,
92 + "snoozedAt": null,
93 + "snoozedUntil": null,
94 + "title": "Triage A thread 3",
95 + "updatedAt": "2026-10-21T20:03:00.000Z",
96 + "worktreePath": null
97 + },
98 + {
99 + "activeProviderThreadId": null,
100 + "archivedAt": null,
101 + "branch": null,
102 + "createdAt": "2026-10-21T20:04:00.000Z",
103 + "createdBy": "user",
104 + "creationSource": "web",
105 + "deletedAt": null,
106 + "forkedFrom": null,
107 + "id": "triage-A-4",
108 + "interactionMode": "default",
109 + "lastVisitedAt": null,
110 + "lineage": {
111 + "parentThreadId": null,
112 + "relationshipToParent": null,
113 + "rootThreadId": "triage-A-4"
114 + },
115 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
116 + "projectId": "triage-project-A",
117 + "providerInstanceId": "codex",
118 + "runtimeMode": "full-access",
119 + "settledAt": null,
120 + "settledOverride": null,
121 + "snoozedAt": null,
122 + "snoozedUntil": null,
123 + "title": "Triage A thread 4",
124 + "updatedAt": "2026-10-21T20:04:00.000Z",
125 + "worktreePath": null
126 + },
127 + {
128 + "activeProviderThreadId": null,
129 + "archivedAt": null,
130 + "branch": null,
131 + "createdAt": "2026-10-21T20:05:00.000Z",
132 + "createdBy": "user",
133 + "creationSource": "web",
134 + "deletedAt": null,
135 + "forkedFrom": null,
136 + "id": "triage-A-5",
137 + "interactionMode": "default",
138 + "lastVisitedAt": null,
139 + "lineage": {
140 + "parentThreadId": null,
141 + "relationshipToParent": null,
142 + "rootThreadId": "triage-A-5"
143 + },
144 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
145 + "projectId": "triage-project-A",
146 + "providerInstanceId": "codex",
147 + "runtimeMode": "full-access",
148 + "settledAt": null,
149 + "settledOverride": null,
150 + "snoozedAt": null,
151 + "snoozedUntil": null,
152 + "title": "Triage A thread 5",
153 + "updatedAt": "2026-10-21T20:05:00.000Z",
154 + "worktreePath": null
155 + },
156 + {
157 + "activeProviderThreadId": null,
158 + "archivedAt": null,
159 + "branch": null,
160 + "createdAt": "2026-10-21T20:06:00.000Z",
161 + "createdBy": "user",
162 + "creationSource": "web",
163 + "deletedAt": null,
164 + "forkedFrom": null,
165 + "id": "triage-A-6",
166 + "interactionMode": "default",
167 + "lastVisitedAt": null,
168 + "lineage": {
169 + "parentThreadId": null,
170 + "relationshipToParent": null,
171 + "rootThreadId": "triage-A-6"
172 + },
173 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
174 + "projectId": "triage-project-A",
175 + "providerInstanceId": "codex",
176 + "runtimeMode": "full-access",
177 + "settledAt": null,
178 + "settledOverride": null,
179 + "snoozedAt": null,
180 + "snoozedUntil": null,
181 + "title": "Triage A thread 6",
182 + "updatedAt": "2026-10-21T20:06:00.000Z",
183 + "worktreePath": null
184 + },
185 + {
186 + "activeProviderThreadId": null,
187 + "archivedAt": null,
188 + "branch": null,
189 + "createdAt": "2026-10-21T20:07:00.000Z",
190 + "createdBy": "user",
191 + "creationSource": "web",
192 + "deletedAt": null,
193 + "forkedFrom": null,
194 + "id": "triage-A-7",
195 + "interactionMode": "default",
196 + "lastVisitedAt": null,
197 + "lineage": {
198 + "parentThreadId": null,
199 + "relationshipToParent": null,
200 + "rootThreadId": "triage-A-7"
201 + },
202 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
203 + "projectId": "triage-project-A",
204 + "providerInstanceId": "codex",
205 + "runtimeMode": "full-access",
206 + "settledAt": null,
207 + "settledOverride": null,
208 + "snoozedAt": null,
209 + "snoozedUntil": null,
210 + "title": "Triage A thread 7",
211 + "updatedAt": "2026-10-21T20:07:00.000Z",
212 + "worktreePath": null
213 + },
214 + {
215 + "activeProviderThreadId": null,
216 + "archivedAt": null,
217 + "branch": null,
218 + "createdAt": "2026-10-21T20:08:00.000Z",
219 + "createdBy": "user",
220 + "creationSource": "web",
221 + "deletedAt": null,
222 + "forkedFrom": null,
223 + "id": "triage-A-8",
224 + "interactionMode": "default",
225 + "lastVisitedAt": null,
226 + "lineage": {
227 + "parentThreadId": null,
228 + "relationshipToParent": null,
229 + "rootThreadId": "triage-A-8"
230 + },
231 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
232 + "projectId": "triage-project-A",
233 + "providerInstanceId": "codex",
234 + "runtimeMode": "full-access",
235 + "settledAt": null,
236 + "settledOverride": null,
237 + "snoozedAt": null,
238 + "snoozedUntil": null,
239 + "title": "Triage A thread 8",
240 + "updatedAt": "2026-10-21T20:08:00.000Z",
241 + "worktreePath": null
242 + },
243 + {
244 + "activeProviderThreadId": null,
245 + "archivedAt": null,
246 + "branch": null,
247 + "createdAt": "2026-10-21T20:01:00.000Z",
248 + "createdBy": "user",
249 + "creationSource": "web",
250 + "deletedAt": null,
251 + "forkedFrom": null,
252 + "id": "triage-B-1",
253 + "interactionMode": "default",
254 + "lastVisitedAt": null,
255 + "lineage": {
256 + "parentThreadId": null,
257 + "relationshipToParent": null,
258 + "rootThreadId": "triage-B-1"
259 + },
260 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
261 + "projectId": "triage-project-B",
262 + "providerInstanceId": "codex",
263 + "runtimeMode": "full-access",
264 + "settledAt": null,
265 + "settledOverride": null,
266 + "snoozedAt": null,
267 + "snoozedUntil": null,
268 + "title": "Triage B thread 1",
269 + "updatedAt": "2026-10-21T20:01:00.000Z",
270 + "worktreePath": null
271 + },
272 + {
273 + "activeProviderThreadId": null,
274 + "archivedAt": null,
275 + "branch": null,
276 + "createdAt": "2026-10-21T20:02:00.000Z",
277 + "createdBy": "user",
278 + "creationSource": "web",
279 + "deletedAt": null,
280 + "forkedFrom": null,
281 + "id": "triage-B-2",
282 + "interactionMode": "default",
283 + "lastVisitedAt": null,
284 + "lineage": {
285 + "parentThreadId": null,
286 + "relationshipToParent": null,
287 + "rootThreadId": "triage-B-2"
288 + },
289 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
290 + "projectId": "triage-project-B",
291 + "providerInstanceId": "codex",
292 + "runtimeMode": "full-access",
293 + "settledAt": null,
294 + "settledOverride": null,
295 + "snoozedAt": null,
296 + "snoozedUntil": null,
297 + "title": "Triage B thread 2",
298 + "updatedAt": "2026-10-21T20:02:00.000Z",
299 + "worktreePath": null
300 + },
301 + {
302 + "activeProviderThreadId": null,
303 + "archivedAt": null,
304 + "branch": null,
305 + "createdAt": "2026-10-21T20:03:00.000Z",
306 + "createdBy": "user",
307 + "creationSource": "web",
308 + "deletedAt": null,
309 + "forkedFrom": null,
310 + "id": "triage-B-3",
311 + "interactionMode": "default",
312 + "lastVisitedAt": null,
313 + "lineage": {
314 + "parentThreadId": null,
315 + "relationshipToParent": null,
316 + "rootThreadId": "triage-B-3"
317 + },
318 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
319 + "projectId": "triage-project-B",
320 + "providerInstanceId": "codex",
321 + "runtimeMode": "full-access",
322 + "settledAt": null,
323 + "settledOverride": null,
324 + "snoozedAt": null,
325 + "snoozedUntil": null,
326 + "title": "Triage B thread 3",
327 + "updatedAt": "2026-10-21T20:03:00.000Z",
328 + "worktreePath": null
329 + },
330 + {
331 + "activeProviderThreadId": null,
332 + "archivedAt": null,
333 + "branch": null,
334 + "createdAt": "2026-10-21T20:04:00.000Z",
335 + "createdBy": "user",
336 + "creationSource": "web",
337 + "deletedAt": null,
338 + "forkedFrom": null,
339 + "id": "triage-B-4",
340 + "interactionMode": "default",
341 + "lastVisitedAt": null,
342 + "lineage": {
343 + "parentThreadId": null,
344 + "relationshipToParent": null,
345 + "rootThreadId": "triage-B-4"
346 + },
347 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
348 + "projectId": "triage-project-B",
349 + "providerInstanceId": "codex",
350 + "runtimeMode": "full-access",
351 + "settledAt": null,
352 + "settledOverride": null,
353 + "snoozedAt": null,
354 + "snoozedUntil": null,
355 + "title": "Triage B thread 4",
356 + "updatedAt": "2026-10-21T20:04:00.000Z",
357 + "worktreePath": null
358 + },
359 + {
360 + "activeProviderThreadId": null,
361 + "archivedAt": null,
362 + "branch": null,
363 + "createdAt": "2026-10-21T20:05:00.000Z",
364 + "createdBy": "user",
365 + "creationSource": "web",
366 + "deletedAt": null,
367 + "forkedFrom": null,
368 + "id": "triage-B-5",
369 + "interactionMode": "default",
370 + "lastVisitedAt": null,
371 + "lineage": {
372 + "parentThreadId": null,
373 + "relationshipToParent": null,
374 + "rootThreadId": "triage-B-5"
375 + },
376 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
377 + "projectId": "triage-project-B",
378 + "providerInstanceId": "codex",
379 + "runtimeMode": "full-access",
380 + "settledAt": null,
381 + "settledOverride": null,
382 + "snoozedAt": null,
383 + "snoozedUntil": null,
384 + "title": "Triage B thread 5",
385 + "updatedAt": "2026-10-21T20:05:00.000Z",
386 + "worktreePath": null
387 + },
388 + {
389 + "activeProviderThreadId": null,
390 + "archivedAt": null,
391 + "branch": null,
392 + "createdAt": "2026-10-21T20:06:00.000Z",
393 + "createdBy": "user",
394 + "creationSource": "web",
395 + "deletedAt": null,
396 + "forkedFrom": null,
397 + "id": "triage-B-6",
398 + "interactionMode": "default",
399 + "lastVisitedAt": null,
400 + "lineage": {
401 + "parentThreadId": null,
402 + "relationshipToParent": null,
403 + "rootThreadId": "triage-B-6"
404 + },
405 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
406 + "projectId": "triage-project-B",
407 + "providerInstanceId": "codex",
408 + "runtimeMode": "full-access",
409 + "settledAt": null,
410 + "settledOverride": null,
411 + "snoozedAt": null,
412 + "snoozedUntil": null,
413 + "title": "Triage B thread 6",
414 + "updatedAt": "2026-10-21T20:06:00.000Z",
415 + "worktreePath": null
416 + },
417 + {
418 + "activeProviderThreadId": null,
419 + "archivedAt": null,
420 + "branch": null,
421 + "createdAt": "2026-10-21T20:07:00.000Z",
422 + "createdBy": "user",
423 + "creationSource": "web",
424 + "deletedAt": null,
425 + "forkedFrom": null,
426 + "id": "triage-B-7",
427 + "interactionMode": "default",
428 + "lastVisitedAt": null,
429 + "lineage": {
430 + "parentThreadId": null,
431 + "relationshipToParent": null,
432 + "rootThreadId": "triage-B-7"
433 + },
434 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
435 + "projectId": "triage-project-B",
436 + "providerInstanceId": "codex",
437 + "runtimeMode": "full-access",
438 + "settledAt": null,
439 + "settledOverride": null,
440 + "snoozedAt": null,
441 + "snoozedUntil": null,
442 + "title": "Triage B thread 7",
443 + "updatedAt": "2026-10-21T20:07:00.000Z",
444 + "worktreePath": null
445 + },
446 + {
447 + "activeProviderThreadId": null,
448 + "archivedAt": null,
449 + "branch": null,
450 + "createdAt": "2026-10-21T20:08:00.000Z",
451 + "createdBy": "user",
452 + "creationSource": "web",
453 + "deletedAt": null,
454 + "forkedFrom": null,
455 + "id": "triage-B-8",
456 + "interactionMode": "default",
457 + "lastVisitedAt": null,
458 + "lineage": {
459 + "parentThreadId": null,
460 + "relationshipToParent": null,
461 + "rootThreadId": "triage-B-8"
462 + },
463 + "modelSelection": { "instanceId": "codex", "model": "gpt-6.1-sol" },
464 + "projectId": "triage-project-B",
465 + "providerInstanceId": "codex",
466 + "runtimeMode": "full-access",
467 + "settledAt": null,
468 + "settledOverride": null,
469 + "snoozedAt": null,
470 + "snoozedUntil": null,
471 + "title": "Triage B thread 8",
472 + "updatedAt": "2026-10-21T20:08:00.000Z",
473 + "worktreePath": null
474 + }
475 + ],
476 + "uiState": {
477 + "projectExpandedById": {},
478 + "projectOrder": [],
479 + "sidebarProjectScopeKey": null,
480 + "threadLastVisitedAtById": {}
481 + },
482 + "variant": "plain"
483 +}
scripts/fixtures/issue-16534/replay.js new
+292
@@ -0,0 +1,292 @@
1 +/** Capture-only protocol fixture. Install before modules; never import in product code.
2 + * Pass options through sessionStorage sidebar-capture-config.replay. Real server
3 + * frames still travel through the real RPC decoder and client reducers.
4 + */
5 +(() => {
6 + const options = JSON.parse(sessionStorage.getItem("sidebar-capture-config") || "{}").replay || {};
7 + const NativeWebSocket = WebSocket;
8 + const held = [];
9 + globalThis.__sidebarWire = [];
10 + const frames = [];
11 + globalThis.__sidebarReplay = {
12 + frames,
13 + held,
14 + release() {
15 + if (delayedThread && delayedStream) {
16 + releaseThread(delayedStream, delayedThread);
17 + delayedThread = null;
18 + delayedStream = null;
19 + }
20 + for (const run of held.splice(0)) run();
21 + },
22 + };
23 +
24 + let delayedThread = null;
25 + let delayedStream = null;
26 + let latestShellStream = null;
27 + let shellSequence = 0;
28 + const releaseThread = (stream, thread, emit = stream.emit) => {
29 + // Insert one fixture event into this subscription's sequence space; later
30 + // server events must carry the same offset or the reducer drops the next one.
31 + stream.offset++;
32 + emit({
33 + kind: "thread.updated",
34 + sequence: ++stream.sequence,
35 + location: "active",
36 + thread,
37 + });
38 + };
39 + const parseFrame = (data) => {
40 + try {
41 + const value = JSON.parse(data);
42 + const ndjson = data.endsWith("\n") && !Array.isArray(value);
43 + return { value: ndjson ? [value] : value, ndjson };
44 + } catch {
45 + return {
46 + value: data
47 + .trim()
48 + .split("\n")
49 + .map((line) => JSON.parse(line)),
50 + ndjson: true,
51 + };
52 + }
53 + };
54 + const transformSnapshot = (
55 + snapshot,
56 + hold = (thread) => {
57 + delayedThread = thread;
58 + },
59 + ) => {
60 + snapshot.threads = snapshot.threads.filter(
61 + (t) =>
62 + t.id.startsWith("triage-") && (options.lineage || !/^triage-A-(9|10|11|12)$/.test(t.id)),
63 + );
64 + if (options.shelf === "settled") {
65 + const source = snapshot.threads.find((t) => t.id === "triage-A-8");
66 + if (source)
67 + for (let i = 13; i <= 26; i++)
68 + snapshot.threads.push({
69 + ...source,
70 + id: "triage-A-" + i,
71 + title: "Triage A thread " + i,
72 + latestMessageAt: "2026-10-21T23:" + String(i).padStart(2, "0") + ":00.000Z",
73 + updatedAt: "2026-10-21T23:" + String(i).padStart(2, "0") + ":00.000Z",
74 + });
75 + }
76 + snapshot.projects = snapshot.projects?.filter((p) => p.id?.startsWith("triage-")) || [];
77 + for (const thread of snapshot.threads) {
78 + if (thread.id === "triage-A-1" && options.shelf) {
79 + Object.assign(thread, {
80 + pinnedAt: null,
81 + snoozedUntil: null,
82 + settledOverride: null,
83 + settledAt: null,
84 + });
85 + if (options.shelf === "pinned")
86 + Object.assign(thread, { pinnedAt: "2026-10-22T00:00:00.000Z", pinOrderKey: "a0" });
87 + if (options.shelf === "snoozed")
88 + Object.assign(thread, {
89 + snoozedUntil: "2099-01-01T00:00:00.000Z",
90 + snoozedAt: "2026-10-22T00:00:00.000Z",
91 + });
92 + if (options.shelf === "working")
93 + Object.assign(thread, {
94 + status: "running",
95 + activeRunId: "triage-run-working",
96 + latestRunId: "triage-run-working",
97 + activityRunStatus: "running",
98 + latestRunRequestedAt: "2026-10-21T23:00:00.000Z",
99 + latestRunStartedAt: "2026-10-21T23:00:00.000Z",
100 + });
101 + }
102 + if (options.shelf === "settled" && thread.projectId === "triage-project-A") {
103 + Object.assign(thread, { settledOverride: "settled", settledAt: thread.createdAt });
104 + }
105 + if (options.status && ["triage-A-1", "triage-A-2"].includes(thread.id)) {
106 + Object.assign(thread, {
107 + status: thread.id === "triage-A-1" ? "failed" : "completed",
108 + latestRunId: "triage-run-" + thread.id,
109 + latestRunRequestedAt: "2026-10-21T23:00:00.000Z",
110 + latestRunCompletedAt: "2026-10-21T23:01:00.000Z",
111 + lastVisitedAt: null,
112 + });
113 + }
114 + }
115 + if (options.delay) {
116 + const target = snapshot.threads.find((t) => t.id === "triage-A-1");
117 + if (target) hold(target);
118 + snapshot.threads = snapshot.threads.filter((t) => t.id !== "triage-A-1");
119 + }
120 + return snapshot;
121 + };
122 + const nativeFetch = fetch;
123 + globalThis.fetch = async (...args) => {
124 + const response = await nativeFetch(...args);
125 + const url = String(args[0]?.url ?? args[0]);
126 + if (!options.enabled || !url.includes("/api/orchestration/shell") || !response.ok)
127 + return response;
128 + const value = await response.clone().json();
129 + if (!Array.isArray(value.threads)) return response;
130 + frames.push({
131 + kind: "http.shell",
132 + count: value.threads.length,
133 + sequence: value.snapshotSequence,
134 + });
135 + shellSequence = value.snapshotSequence;
136 + transformSnapshot(value);
137 + if (delayedThread && latestShellStream) {
138 + delayedStream = latestShellStream;
139 + delayedStream.sequence = Math.max(delayedStream.sequence, shellSequence);
140 + }
141 + return new Response(JSON.stringify(value), {
142 + status: response.status,
143 + headers: { "content-type": "application/json" },
144 + });
145 + };
146 +
147 + globalThis.WebSocket = class extends NativeWebSocket {
148 + send(data) {
149 + if (!options.enabled || typeof data !== "string") return super.send(data);
150 + try {
151 + const { value, ndjson } = parseFrame(data);
152 + let changed = false;
153 + for (const request of Array.isArray(value) ? value : [value]) {
154 + if (request?._tag === "Request" && request.tag === "orchestration.subscribeShell") {
155 + const afterSequence = request.payload?.afterSequence;
156 + // Foreground resumes reuse this socket's client cursor. A new RPC
157 + // session owns a new socket and reloads the authoritative HTTP shell.
158 + const offset =
159 + typeof afterSequence === "number" ? (this.latestShellStream?.offset ?? 0) : 0;
160 + if (offset !== 0) {
161 + request.payload.afterSequence -= offset;
162 + changed = true;
163 + }
164 + const stream = {
165 + sequence: afterSequence ?? shellSequence,
166 + offset,
167 + emit: (node) =>
168 + this.replayDeliver({
169 + _tag: "Chunk",
170 + requestId: request.id,
171 + values: [node],
172 + }),
173 + };
174 + this.shellStreams.set(request.id, stream);
175 + this.latestShellStream = stream;
176 + latestShellStream = stream;
177 + if (delayedThread && !delayedStream) delayedStream = stream;
178 + } else if (
179 + request?._tag === "Request" &&
180 + request.tag === "orchestration.subscribeThread"
181 + ) {
182 + this.threadRequests.add(request.id);
183 + }
184 + }
185 + if (changed)
186 + data = ndjson
187 + ? value.map((item) => JSON.stringify(item)).join("\n") + "\n"
188 + : JSON.stringify(value);
189 + } catch {
190 + // Non-JSON socket traffic belongs to the native protocol handler.
191 + }
192 + super.send(data);
193 + }
194 + latestShellStream = null;
195 + shellStreams = new Map();
196 + threadRequests = new Set();
197 + replayDeliver;
198 + constructor(...args) {
199 + super(...args);
200 + let replaying = false;
201 + this.replayDeliver = (data) => {
202 + replaying = true;
203 + try {
204 + this.dispatchEvent(new MessageEvent("message", { data: JSON.stringify(data) }));
205 + } finally {
206 + replaying = false;
207 + }
208 + };
209 + this.addEventListener("message", (event) => {
210 + if (replaying) return;
211 + frames.push({
212 + kind: "frame",
213 + type: typeof event.data,
214 + constructor: event.data?.constructor?.name,
215 + length: event.data?.length,
216 + });
217 + if (typeof event.data !== "string") return;
218 + let value;
219 + let ndjson;
220 + try {
221 + ({ value, ndjson } = parseFrame(event.data));
222 + } catch {
223 + frames.push({ kind: "unparsed", length: event.data.length });
224 + return;
225 + }
226 + globalThis.__sidebarWire.push(value);
227 + frames.push({
228 + kind: "parsed",
229 + tag: value?._tag,
230 + keys: Object.keys(value || {}),
231 + count: Array.isArray(value) ? value.length : undefined,
232 + });
233 + let changed = false;
234 + const deliver = (data) => {
235 + replaying = true;
236 + try {
237 + this.dispatchEvent(
238 + new MessageEvent("message", {
239 + data: ndjson
240 + ? data.map((item) => JSON.stringify(item)).join("\n") + "\n"
241 + : JSON.stringify(data),
242 + }),
243 + );
244 + } finally {
245 + replaying = false;
246 + }
247 + };
248 + if (options.enabled) {
249 + for (const chunk of Array.isArray(value) ? value : [value]) {
250 + if (chunk?._tag !== "Chunk" || !Array.isArray(chunk.values)) continue;
251 + if (this.threadRequests.has(chunk.requestId)) continue;
252 + let stream = this.shellStreams.get(chunk.requestId);
253 + if (!stream && chunk.values.some((node) => Array.isArray(node?.snapshot?.threads))) {
254 + stream = { sequence: 0, offset: 0 };
255 + this.shellStreams.set(chunk.requestId, stream);
256 + }
257 + if (!stream) continue;
258 + stream.emit = (node) => {
259 + const update = { ...chunk, values: [node] };
260 + deliver(Array.isArray(value) ? [update] : update);
261 + };
262 + for (const node of chunk.values) {
263 + if (typeof node?.sequence === "number") {
264 + node.sequence += stream.offset;
265 + stream.sequence = Math.max(stream.sequence, node.sequence);
266 + changed ||= stream.offset !== 0;
267 + }
268 + if (node?.kind !== "snapshot" || !Array.isArray(node.snapshot?.threads)) continue;
269 + node.snapshot.snapshotSequence += stream.offset;
270 + stream.sequence = Math.max(stream.sequence, node.snapshot.snapshotSequence);
271 + const snapshot = node.snapshot;
272 + frames.push({
273 + kind: "shell.snapshot",
274 + count: snapshot.threads.length,
275 + sequence: snapshot.snapshotSequence,
276 + });
277 + transformSnapshot(snapshot, (thread) => {
278 + const emit = stream.emit;
279 + held.push(() => releaseThread(stream, thread, emit));
280 + });
281 + changed = true;
282 + }
283 + }
284 + }
285 + if (changed) {
286 + event.stopImmediatePropagation();
287 + deliver(value);
288 + }
289 + });
290 + }
291 + };
292 +})();
scripts/fixtures/issue-16534/seed.py new
+110
@@ -0,0 +1,110 @@
1 +#!/usr/bin/env python3
2 +"""Generate synthetic sidebar projections without reading personal application data.
3 +
4 +Generation never touches a database. Apply the generated SQL files with the documented SQLite
5 +helper only after the environment owner has stopped the isolated server. These
6 +are projection fixtures, not event-history or provider integration fixtures.
7 +"""
8 +import argparse
9 +import hashlib
10 +import json
11 +from pathlib import Path
12 +
13 +CLOCK = '2026-10-22T00:00:00.000Z'
14 +
15 +
16 +def encoded(value):
17 + return json.dumps(value, sort_keys=True, separators=(',', ':'))
18 +
19 +
20 +def quote(value):
21 + return 'NULL' if value is None else "'" + str(value).replace("'", "''") + "'"
22 +
23 +
24 +def thread(group, number):
25 + key = f'triage-{group}-{number}'
26 + stamp = f'2026-10-21T20:{number:02d}:00.000Z'
27 + return dict(createdBy='user', creationSource='web', id=key,
28 + projectId=f'triage-project-{group}', title=f'Triage {group} thread {number}',
29 + providerInstanceId='codex', modelSelection=dict(instanceId='codex', model='gpt-6.1-sol'),
30 + runtimeMode='full-access', interactionMode='default', branch=None,
31 + worktreePath=None, activeProviderThreadId=None,
32 + lineage=dict(parentThreadId=None, relationshipToParent=None, rootThreadId=key),
33 + forkedFrom=None, createdAt=stamp, updatedAt=stamp, archivedAt=None,
34 + settledOverride=None, settledAt=None, snoozedUntil=None, snoozedAt=None,
35 + lastVisitedAt=None, deletedAt=None)
36 +
37 +
38 +def main():
39 + parser = argparse.ArgumentParser(description=__doc__)
40 + parser.add_argument('--output', type=Path, required=True)
41 + parser.add_argument('--variant', choices=['plain', 'spacers', 'pinned', 'snoozed', 'settled', 'lineage', 'archived', 'orphan', 'working', 'status', 'grouped', 'all'], default='plain')
42 + parser.add_argument('--legacy', action='store_true')
43 + args = parser.parse_args()
44 + args.output.mkdir(parents=True, exist_ok=True)
45 + threads = [thread(group, n) for group in ['A', 'B'] for n in range(1, 9)]
46 + projects = ['A', 'B']
47 + target = threads[0]
48 + if args.variant in ['spacers', 'all']:
49 + projects.append('Spacer')
50 + threads += [thread('Spacer', n) for n in range(1, 41)]
51 + if args.variant == 'pinned':
52 + target.update(pinnedAt=CLOCK, pinOrderKey='a0')
53 + if args.variant == 'snoozed':
54 + target.update(snoozedAt=CLOCK, snoozedUntil='2099-01-01T00:00:00.000Z')
55 + if args.variant == 'settled':
56 + target.update(settledOverride='settled', settledAt=CLOCK)
57 + for n in range(2, 17):
58 + settled = threads[n-1] if n <= 8 else thread('A', n)
59 + settled.update(settledOverride='settled', settledAt=f'2026-10-21T21:{n:02d}:00.000Z')
60 + if n > 8:
61 + threads.append(settled)
62 + if args.variant == 'archived':
63 + target['archivedAt'] = CLOCK
64 + if args.variant in ['lineage', 'orphan', 'all']:
65 + for n, parent, relationship in [(9, target['id'], 'subagent'), (10, 'triage-A-9', 'subagent'), (11, target['id'], 'fork'), (12, target['id'], 'subagent')]:
66 + child = thread('A', n)
67 + child['lineage'] = dict(parentThreadId=parent, relationshipToParent=relationship, rootThreadId=target['id'])
68 + threads.append(child)
69 + if args.variant == 'orphan':
70 + threads[16]['lineage']['parentThreadId'] = 'triage-missing-root'
71 + threads[16]['lineage']['rootThreadId'] = 'triage-missing-root'
72 + messages = []
73 + for group in ['A', 'B']:
74 + text = "Synthetic navigation links: " + " | ".join(f"[Open {label}](t3-thread://v1/{target_id})" for label,target_id in [('A1','triage-A-1'),('A8','triage-A-8'),('child','triage-A-9'),('grandchild','triage-A-10'),('sibling','triage-A-12'),('fork','triage-A-11'),('missing','triage-missing')])
75 + messages.append(dict(id=f'triage-link-{group}',threadId=f'triage-{group}-8',runId=None,nodeId=None,role='assistant',text=text,attachments=[],streaming=False,createdAt=CLOCK,updatedAt=CLOCK,createdBy='agent',creationSource='web'))
76 + message_values = ['(' + ','.join(map(quote,[m['id'],m['threadId'],None,None,m['role'],0,CLOCK,CLOCK,encoded(m)])) + ')' for m in messages]
77 + (args.output/'messages.sql').write_text('INSERT OR REPLACE INTO orchestration_v2_projection_messages (message_id,thread_id,run_id,node_id,role,streaming,created_at,updated_at,payload_json) VALUES ' + ','.join(message_values) + ';\n')
78 + item_values = []
79 + for m in messages:
80 + item=dict(id=m['id']+'-item',threadId=m['threadId'],runId=None,nodeId=None,providerThreadId=None,providerTurnId=None,nativeItemRef=None,parentItemId=None,ordinal=0,status='completed',title=None,startedAt=CLOCK,completedAt=CLOCK,updatedAt=CLOCK,type='assistant_message',messageId=m['id'],text=m['text'],streaming=False)
81 + item_values.append('(' + ','.join(map(quote,[item['id'],item['threadId'],None,None,None,None,None,0,'assistant_message','completed',CLOCK,encoded(item)])) + ')')
82 + (args.output/'turn-items.sql').write_text('INSERT OR REPLACE INTO orchestration_v2_projection_turn_items (turn_item_id,thread_id,run_id,node_id,provider_thread_id,provider_turn_id,parent_item_id,ordinal,type,status,updated_at,payload_json) VALUES '+','.join(item_values)+';\n')
83 + # One statement, so the state helper can apply it as one atomic transaction.
84 + project_values = []
85 + for group in projects:
86 + project_values.append('(' + ','.join(map(quote, [f'triage-project-{group}', f'Triage {group}', f'/tmp/triage-16534-{group}', '[]', '2026-10-21T20:00:00.000Z', '2026-10-21T20:00:00.000Z'])) + ')')
87 + project_sql = 'INSERT OR REPLACE INTO projection_projects (project_id,title,workspace_root,scripts_json,created_at,updated_at) VALUES ' + ',\n'.join(project_values) + ';\n'
88 + values = []
89 + for t in threads:
90 + values.append('(' + ','.join(map(quote, [t['id'],t['projectId'],t['title'],'codex','full-access','default',None,t['createdAt'],t['updatedAt'],t['archivedAt'],None,encoded(t),'codex'])) + ')')
91 + sql = 'INSERT OR REPLACE INTO orchestration_v2_projection_threads (thread_id,project_id,title,default_provider,runtime_mode,interaction_mode,active_provider_thread_id,created_at,updated_at,archived_at,deleted_at,payload_json,provider_instance_id) VALUES ' + ',\n'.join(values) + ';\n'
92 + fixture = dict(clock=CLOCK, variant=args.variant, threads=threads,
93 + settings=dict(legacySidebarEnabled=args.legacy,sidebarThreadSortOrder='updated_at',sidebarProjectSortOrder='manual',sidebarThreadPreviewCount=6,sidebarProjectGroupingMode='separate'),
94 + uiState=dict(projectExpandedById={},projectOrder=[],threadLastVisitedAtById={},sidebarProjectScopeKey=None))
95 + (args.output/'reset-threads.sql').write_text("DELETE FROM orchestration_v2_projection_threads WHERE thread_id LIKE 'triage-%';\n")
96 + (args.output/'hide-unrelated-projects.sql').write_text("UPDATE projection_projects SET deleted_at=" + quote(CLOCK) + " WHERE project_id NOT IN (" + ','.join(quote('triage-project-' + group) for group in projects) + ");\n")
97 + (args.output/'archive-unrelated-threads.sql').write_text("UPDATE orchestration_v2_projection_threads SET archived_at=" + quote(CLOCK) + ",payload_json=json_set(payload_json,'$.archivedAt'," + quote(CLOCK) + ") WHERE thread_id NOT LIKE 'triage-%';\n")
98 + (args.output/'hide-v1-threads.sql').write_text("UPDATE projection_threads SET deleted_at="+quote(CLOCK)+" WHERE thread_id NOT LIKE 'triage-%';\n")
99 + (args.output/'projects.sql').write_text(project_sql)
100 + (args.output/'threads.sql').write_text(sql)
101 + (args.output/'fixture.json').write_text(encoded(fixture)+'\n')
102 + digest = hashlib.sha256(encoded(fixture).encode()).hexdigest()
103 + (args.output/'sha256.txt').write_text(digest+'\n')
104 + from transcript import write_transcript
105 + write_transcript(args.output)
106 + print(digest)
107 +
108 +
109 +if __name__ == '__main__':
110 + main()
scripts/fixtures/issue-16534/transcript.py new
+25
@@ -0,0 +1,25 @@
1 +"""Emit stopped synthetic runs and transcript items for real thread-link rendering."""
2 +import json
3 +from pathlib import Path
4 +
5 +def write_transcript(output):
6 + clock='2026-10-21T23:00:00.000Z'
7 + def q(v): return 'NULL' if v is None else "'"+str(v).replace("'","''")+"'"
8 + def enc(v):return json.dumps(v,separators=(',',':'))
9 + runs=[];messages=[];items=[]
10 + for group in ['A','B']:
11 + tid=f'triage-{group}-8';rid=f'triage-fixture-run-{group}';uid=rid+'-user';aid=rid+'-assistant'
12 + run=dict(id=rid,threadId=tid,ordinal=1,providerInstanceId='codex',modelSelection=dict(instanceId='codex',model='gpt-6.1-sol'),providerThreadId=None,userMessageId=uid,rootNodeId=None,activeAttemptId=None,status='completed',requestedAt=clock,startedAt=clock,completedAt=clock,checkpointId=None,contextHandoffId=None)
13 + runs.append('('+','.join(map(q,[rid,tid,1,'codex',None,'completed',clock,clock,enc(run),'codex']))+')')
14 + linktext='Synthetic fixture navigation: '+' | '.join(f'[{label}](t3-thread://v1/{target})' for label,target in [('Open A1','triage-A-1'),('Open A8','triage-A-8'),('Open child','triage-A-9'),('Open grandchild','triage-A-10'),('Open sibling','triage-A-12'),('Open fork','triage-A-11'),('Open missing','triage-missing')])
15 + for ordinal,(mid,role,text) in enumerate([(uid,'user','Use these synthetic navigation links.'),(aid,'assistant',linktext)]):
16 + m=dict(id=mid,threadId=tid,runId=rid,nodeId=None,role=role,text=text,attachments=[],streaming=False,createdAt=clock,updatedAt=clock,createdBy='user' if role=='user' else 'agent',creationSource='web')
17 + messages.append('('+','.join(map(q,[mid,tid,rid,None,role,0,clock,clock,enc(m)]))+')')
18 + item=dict(id=mid+'-item',threadId=tid,runId=rid,nodeId=None,providerThreadId=None,providerTurnId=None,nativeItemRef=None,parentItemId=None,ordinal=ordinal,status='completed',title=None,startedAt=clock,completedAt=clock,updatedAt=clock,type=role+'_message',messageId=mid,text=text,streaming=False)
19 + if role=='user':item.update(createdBy='user',creationSource='web',inputIntent='turn_start',attachments=[])
20 + items.append('('+','.join(map(q,[item['id'],tid,rid,None,None,None,None,ordinal,item['type'],'completed',clock,enc(item)]))+')')
21 + tables=[('runs','run_id,thread_id,ordinal,provider,provider_thread_id,status,requested_at,completed_at,payload_json,provider_instance_id',runs),('messages','message_id,thread_id,run_id,node_id,role,streaming,created_at,updated_at,payload_json',messages),('turn_items','turn_item_id,thread_id,run_id,node_id,provider_thread_id,provider_turn_id,parent_item_id,ordinal,type,status,updated_at,payload_json',items)]
22 + for table,columns,values in tables:(output/('transcript-'+table.replace('_','-')+'.sql')).write_text(f'INSERT OR REPLACE INTO orchestration_v2_projection_{table} ({columns}) VALUES '+','.join(values)+';\n')
23 +if __name__=='__main__':
24 + import sys
25 + write_transcript(Path(sys.argv[1]))