@devries-cameron20 / t3code-1 / commits / ff73c4c2e6
Fork 0

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

fix(server): forked Claude threads keep their compaction chain (#27577)

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

Julius Marminge committed Nov 2, 2026 at 17:59 UTC ff73c4c2e6639c718d112ffa384ee5063f830d4e
4 files changed +115 -27
apps/server/package.json
+1 -1
@@ -34,7 +34,7 @@
34 "generate:expo-schema": "node scripts/fetch-expo-schema.ts"
35 },
36 "dependencies": {
37 - "@anthropic-ai/claude-agent-sdk": "^0.3.276",
37 + "@anthropic-ai/claude-agent-sdk": "^0.3.284",
38 "@cursor/sdk": "1.2.0",
39 "@effect/platform-node": "catalog:",
40 "@effect/platform-node-shared": "catalog:",
apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts
+109 -20
@@ -37,32 +37,34 @@ vi.mock("@anthropic-ai/claude-agent-sdk", { spy: true });
37
38 const FORK_SESSION_ID = "11111111-1111-4111-8111-111111111111";
39
40 -const writeClaudeSession = Effect.fnUntraced(function* (configDir: string) {
40 +const sessionEntry = (uuid: string, parentUuid: string | null, message: unknown) => ({
41 + type: parentUuid === null ? "user" : "assistant",
42 + uuid,
43 + parentUuid,
44 + sessionId: FORK_SESSION_ID,
45 + cwd: "/repo",
46 + isSidechain: false,
47 + timestamp: "2026-10-01T00:00:00.000Z",
48 + message,
49 +});
50 +
51 +const writeClaudeSession = Effect.fnUntraced(function* (
52 + configDir: string,
53 + entries: ReadonlyArray<unknown> = [
54 + sessionEntry("aaaaaaaa-0000-4000-8000-000000000001", null, { role: "user", content: "hello" }),
55 + sessionEntry("aaaaaaaa-0000-4000-8000-000000000002", "aaaaaaaa-0000-4000-8000-000000000001", {
56 + role: "assistant",
57 + content: [{ type: "text", text: "hi" }],
58 + }),
59 + ],
60 +) {
61 const fileSystem = yield* FileSystem.FileSystem;
62 const path = yield* Path.Path;
63 const projectDir = path.join(configDir, "projects", "-repo");
44 - const entry = (uuid: string, parentUuid: string | null, message: unknown) => ({
45 - type: parentUuid === null ? "user" : "assistant",
46 - uuid,
47 - parentUuid,
48 - sessionId: FORK_SESSION_ID,
49 - cwd: "/repo",
50 - isSidechain: false,
51 - timestamp: "2026-10-01T00:00:00.000Z",
52 - message,
53 - });
64 yield* fileSystem.makeDirectory(projectDir, { recursive: true });
65 yield* fileSystem.writeFileString(
66 path.join(projectDir, `${FORK_SESSION_ID}.jsonl`),
57 - [
58 - entry("aaaaaaaa-0000-4000-8000-000000000001", null, { role: "user", content: "hello" }),
59 - entry("aaaaaaaa-0000-4000-8000-000000000002", "aaaaaaaa-0000-4000-8000-000000000001", {
60 - role: "assistant",
61 - content: [{ type: "text", text: "hi" }],
62 - }),
63 - ]
64 - .map((line) => JSON.stringify(line))
65 - .join("\n"),
67 + entries.map((line) => JSON.stringify(line)).join("\n"),
68 );
69 return projectDir;
70 });
@@ -112,6 +114,93 @@ it.effect("forks a session stored under the instance's own CLAUDE_CONFIG_DIR", (
114 }).pipe(Effect.provide(forkRunnerLayer)),
115 ).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
116 );
117 +it.effect("forked Claude sessions keep their compaction chain", () =>
118 + Effect.scoped(
119 + Effect.gen(function* () {
120 + const fileSystem = yield* FileSystem.FileSystem;
121 + const path = yield* Path.Path;
122 + const configDir = yield* fileSystem.makeTempDirectoryScoped({
123 + prefix: "t3-claude-fork-compact-",
124 + });
125 + const uuid = (n: number) => `bbbbbbbb-0000-4000-8000-00000000000${n}`;
126 + const turn = (id: number, parent: string | null, role: "user" | "assistant") => ({
127 + ...sessionEntry(uuid(id), parent, {
128 + role,
129 + content: role === "user" ? `question ${id}` : [{ type: "text", text: `answer ${id}` }],
130 + }),
131 + type: role,
132 + });
133 + const projectDir = yield* writeClaudeSession(configDir, [
134 + turn(1, null, "user"),
135 + turn(2, uuid(1), "assistant"),
136 + turn(3, uuid(2), "user"),
137 + turn(4, uuid(3), "assistant"),
138 + {
139 + ...sessionEntry(uuid(5), null, undefined),
140 + type: "system",
141 + subtype: "compact_boundary",
142 + content: "Conversation compacted",
143 + logicalParentUuid: uuid(4),
144 + compactMetadata: {
145 + trigger: "manual",
146 + preTokens: 19979,
147 + preservedSegment: { headUuid: uuid(3), anchorUuid: uuid(6), tailUuid: uuid(4) },
148 + preservedMessages: {
149 + anchorUuid: uuid(6),
150 + uuids: [uuid(3), uuid(4)],
151 + allUuids: [uuid(3), uuid(4)],
152 + },
153 + postTokens: 3589,
154 + },
155 + },
156 + {
157 + ...turn(6, uuid(5), "user"),
158 + isCompactSummary: true,
159 + isVisibleInTranscriptOnly: true,
160 + },
161 + turn(7, uuid(4), "user"),
162 + turn(8, uuid(7), "assistant"),
163 + ]);
164 +
165 + const runner = yield* ClaudeAgentSdkQueryRunner;
166 + const forked = yield* runner.forkSession({
167 + sessionId: FORK_SESSION_ID,
168 + options: { dir: "/repo" },
169 + environment: { ...process.env, CLAUDE_CONFIG_DIR: configDir },
170 + threadId: ThreadId.make("thread-fork-compaction"),
171 + providerSessionId: ProviderSessionId.make("session-fork-compaction"),
172 + });
173 +
174 + const entries: ReadonlyArray<{
175 + readonly uuid?: string;
176 + readonly subtype?: string;
177 + readonly compactMetadata?: {
178 + readonly preservedSegment: Record<"headUuid" | "anchorUuid" | "tailUuid", string>;
179 + readonly preservedMessages: {
180 + readonly anchorUuid: string;
181 + readonly uuids: string[];
182 + readonly allUuids: string[];
183 + };
184 + };
185 + }> = (yield* fileSystem.readFileString(path.join(projectDir, `${forked.sessionId}.jsonl`)))
186 + .trim()
187 + .split("\n")
188 + .map((line) => JSON.parse(line));
189 + const forkedUuids = new Set(entries.map((entry) => entry.uuid));
190 + const boundary = entries.find((entry) => entry.subtype === "compact_boundary");
191 + assert.isDefined(boundary?.compactMetadata);
192 + const { preservedSegment, preservedMessages } = boundary!.compactMetadata!;
193 + const danglingRefs = [
194 + ...Object.values(preservedSegment),
195 + preservedMessages.anchorUuid,
196 + ...preservedMessages.uuids,
197 + ...preservedMessages.allUuids,
198 + ].filter((ref) => !forkedUuids.has(ref));
199 + assert.deepEqual(danglingRefs, [], "compaction refs missing from the forked transcript");
200 + }).pipe(Effect.provide(forkRunnerLayer)),
201 + ).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
202 +);
203 +
204 const realQueryRunner = layerQueryRunner.pipe(
205 Layer.provide(PortScanner.layerTest),
206 Layer.provide(
pnpm-lock.yaml
+5 -5
@@ -834,8 +834,8 @@ importers:
834 apps/server:
835 dependencies:
836 '@anthropic-ai/claude-agent-sdk':
837 - specifier: ^0.3.276
838 - version: 0.3.276(@anthropic-ai/sdk@0.93.0(zod@4.6.5))(@modelcontextprotocol/sdk@1.29.0(supports-color@8.1.1)(zod@4.6.5))(zod@4.6.5)
837 + specifier: ^0.3.284
838 + version: 0.3.284(@anthropic-ai/sdk@0.93.0(zod@4.6.5))(@modelcontextprotocol/sdk@1.29.0(supports-color@8.1.1)(zod@4.6.5))(zod@4.6.5)
839 '@cursor/sdk':
840 specifier: 1.2.0
841 version: 1.2.0(zod@4.6.5)
@@ -2678,8 +2678,8 @@ packages:
2678 vitest:
2679 optional: true
2680
2681 - '@anthropic-ai/claude-agent-sdk@0.3.276':
2682 - resolution: {integrity: sha512-Dic43v4uuGLhibPAArWy3RSfq3zHdn+4Oh2AI2/18a5tlbNKkvChEpazyp8c+grUJvzxkzt0jETCa1wrADbkyw==}
2681 + '@anthropic-ai/claude-agent-sdk@0.3.284':
2682 + resolution: {integrity: sha512-NSoJwEq6nFSf8dtaacYx37QdGgqApI3eHFUlxclMLYi8irb6ZJwEaUnPnLUCyAyg9W/tMkgZC0GXWLRCc01I0w==}
2683 engines: {node: '>=18.0.0'}
2684 peerDependencies:
2685 '@anthropic-ai/sdk': '>=0.93.0'
@@ -12663,7 +12663,7 @@ snapshots:
12663 - bufferutil
12664 - utf-8-validate
12665
12666 - '@anthropic-ai/claude-agent-sdk@0.3.276(@anthropic-ai/sdk@0.93.0(zod@4.6.5))(@modelcontextprotocol/sdk@1.29.0(supports-color@8.1.1)(zod@4.6.5))(zod@4.6.5)':
12666 + '@anthropic-ai/claude-agent-sdk@0.3.284(@anthropic-ai/sdk@0.93.0(zod@4.6.5))(@modelcontextprotocol/sdk@1.29.0(supports-color@8.1.1)(zod@4.6.5))(zod@4.6.5)':
12667 dependencies:
12668 '@anthropic-ai/sdk': 0.93.0(zod@4.6.5)
12669 '@modelcontextprotocol/sdk': 1.29.0(supports-color@8.1.1)(zod@4.6.5)
pnpm-workspace.yaml
-1
@@ -175,7 +175,6 @@ minimumReleaseAgeExclude:
175 - expo-sqlite@58.0.13
176 - expo-symbols@58.0.4
177 - electron@44.10.0
178 - - "@anthropic-ai/claude-agent-sdk@0.3.276"
178 - "@shadcn/lint@0.1.5"
179 - cn@0.3.2
180 - uniwind@1.13.0