@devries-cameron20 / t3code Mirror · read-only / commits / d7a8d6f320
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(server): avoid full shell read on resume (#23987)

Yash Singh committed Oct 23, 2026 at 03:23 UTC d7a8d6f32001444e013aa07c8a468ce3e987f9cf
9 files changed +84 -7
apps/server/integration/transferBudgetV2.integration.test.ts
+2
@@ -89,6 +89,8 @@ const layerManagement = Layer.unwrap(
89 projections.getThreadSnapshotWindow(id, options).pipe(Effect.orDie),
90 getThreadShell: (id) => projections.getThreadShell(id).pipe(Effect.orDie),
91 getShellSnapshot: (options) => projections.getShellSnapshot(options).pipe(Effect.orDie),
92 + listActiveSubagentThreadIds: () =>
93 + projections.listActiveSubagentThreadIds().pipe(Effect.orDie),
94 readShellSnapshot: (options) =>
95 projections.readShellSnapshot(options).pipe(Effect.map(Effect.orDie), Effect.orDie),
96 streamStoredEventsFrom: (input) =>
apps/server/src/orchestration-v2/Orchestrator.ts
+13
@@ -371,6 +371,10 @@ export interface OrchestratorV2Shape {
371 readonly getShellSnapshot: (
372 options?: ShellSnapshotOptions,
373 ) => Effect.Effect<OrchestrationV2ThreadShellSnapshot, OrchestratorV2Error>;
374 + readonly listActiveSubagentThreadIds: () => Effect.Effect<
375 + ReadonlyArray<ThreadId>,
376 + OrchestratorV2Error
377 + >;
378 readonly readShellSnapshot: (
379 options?: ShellSnapshotOptions,
380 ) => Effect.Effect<
@@ -12237,6 +12241,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12241 .pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause }))),
12242 getShellSnapshot: (options) =>
12243 projectionStore.getShellSnapshot(options).pipe(Effect.mapError(shellProjectionError)),
12244 + listActiveSubagentThreadIds: () =>
12245 + projectionStore.listActiveSubagentThreadIds().pipe(Effect.mapError(shellProjectionError)),
12246 readShellSnapshot: (options) =>
12247 projectionStore
12248 .readShellSnapshot(options)
@@ -12382,6 +12388,13 @@ const layerUnavailable: Layer.Layer<OrchestratorV2> = Layer.succeed(
12388 cause: "Orchestration V2 live runtime is not configured.",
12389 }),
12390 ),
12391 + listActiveSubagentThreadIds: () =>
12392 + Effect.fail(
12393 + new OrchestratorProjectionError({
12394 + threadId: ThreadId.make("thread:shell"),
12395 + cause: "Orchestration V2 live runtime is not configured.",
12396 + }),
12397 + ),
12398 readShellSnapshot: () =>
12399 Effect.fail(
12400 new OrchestratorProjectionError({
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+30
@@ -1105,6 +1105,36 @@ const assertProjectScopedShells = Effect.fn("assertProjectScopedShells")(functio
1105 return { projectId, activeThreadId, forkThreadId, otherThreadId };
1106 });
1107
1108 +it.effect("lists only active subagent IDs without loading shell data", () =>
1109 + Effect.gen(function* () {
1110 + const store = yield* ProjectionStore.ProjectionStoreV2;
1111 + const sql = yield* SqlClient.SqlClient;
1112 + const createdAt = "2026-01-05T00:00:00.000Z";
1113 + for (const [id, relationship, archivedAt, deletedAt] of [
1114 + ["parent", null, null, null],
1115 + ["active-subagent", "subagent", null, null],
1116 + ["archived-subagent", "subagent", createdAt, null],
1117 + ["deleted-subagent", "subagent", null, createdAt],
1118 + ] as const) {
1119 + yield* sql`
1120 + INSERT INTO orchestration_v2_projection_threads (
1121 + thread_id, project_id, title, default_provider, runtime_mode, interaction_mode,
1122 + created_at, updated_at, archived_at, deleted_at, payload_json
1123 + ) VALUES (
1124 + ${id}, 'project:test', ${id}, 'codex', 'full-access', 'default',
1125 + ${createdAt}, ${createdAt}, ${archivedAt}, ${deletedAt},
1126 + ${JSON.stringify({ lineage: { relationshipToParent: relationship }, archivedAt })}
1127 + )
1128 + `;
1129 + }
1130 +
1131 + assert.sameMembers(
1132 + [...(yield* store.listActiveSubagentThreadIds())],
1133 + [ThreadId.make("active-subagent")],
1134 + );
1135 + }).pipe(Effect.provide(layerTest)),
1136 +);
1137 +
1138 it.layer(layerTest)("ProjectionStoreV2", (it) => {
1139 // regression: #21969 keep corrupt plan JSON in the typed read error
1140 it.effect("returns a typed read error for malformed stored plan JSON", () =>
apps/server/src/orchestration-v2/ProjectionStore.ts
+32
@@ -424,6 +424,10 @@ export interface ProjectionStoreV2Shape {
424 readonly getShellSnapshot: (
425 options?: ShellSnapshotOptions,
426 ) => Effect.Effect<OrchestrationV2ThreadShellSnapshot, ProjectionStoreV2Error>;
427 + readonly listActiveSubagentThreadIds: () => Effect.Effect<
428 + ReadonlyArray<ThreadId>,
429 + ProjectionStoreV2Error
430 + >;
431 /**
432 * Callers that combine the shell with other reads run this inside their own
433 * transaction and the returned decode after it commits, so the shared
@@ -6430,6 +6434,20 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6434 .withTransaction(readShellSnapshotRows(options))
6435 .pipe(Effect.mapError(shellSnapshotReadError), Effect.flatMap(decodeShellSnapshot));
6436
6437 + const listActiveSubagentThreadIds = Effect.fn("ProjectionStore.listActiveSubagentThreadIds")(
6438 + function* () {
6439 + const rows = yield* sql<{ readonly thread_id: string }>`
6440 + SELECT thread_id
6441 + FROM orchestration_v2_projection_threads
6442 + WHERE deleted_at IS NULL
6443 + AND json_extract(payload_json, '$.archivedAt') IS NULL
6444 + AND json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent'
6445 + `;
6446 + return rows.map((row) => ThreadId.make(row.thread_id));
6447 + },
6448 + Effect.mapError(shellSnapshotReadError),
6449 + );
6450 +
6451 const getThreadShell: ProjectionStoreV2Shape["getThreadShell"] = (threadId) =>
6452 sql
6453 .withTransaction(
@@ -6522,6 +6540,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6540 return {
6541 apply,
6542 getShellSnapshot: readOnReader(getShellSnapshot),
6543 + listActiveSubagentThreadIds: readOnReader(listActiveSubagentThreadIds),
6544 readShellSnapshot: readOnReader(readShellSnapshot),
6545 getThreadShell: readOnReader(getThreadShell),
6546 getThread: readOnReader(getThread),
@@ -6630,6 +6649,19 @@ export const layerMemory: Layer.Layer<ProjectionStoreV2> = Layer.effect(
6649 archivedThreads: visible.filter((thread) => thread.archivedAt !== null),
6650 };
6651 }),
6652 + listActiveSubagentThreadIds: Effect.fn("ProjectionStore.listActiveSubagentThreadIds")(
6653 + function* () {
6654 + const existing = (yield* Ref.get(replayState)).projections;
6655 + return [...existing.values()]
6656 + .filter(
6657 + ({ thread }) =>
6658 + thread.deletedAt === null &&
6659 + thread.archivedAt === null &&
6660 + thread.lineage.relationshipToParent === "subagent",
6661 + )
6662 + .map(({ thread }) => thread.id);
6663 + },
6664 + ),
6665 readShellSnapshot: (options) =>
6666 service.getShellSnapshot(options).pipe(Effect.map(Effect.succeed)),
6667 getThreadShell: Effect.fn("ProjectionStore.getThreadShell")(function* (threadId) {
apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+1
@@ -211,6 +211,7 @@ it.effect(
211 apply: () => Effect.void,
212 getLimitRecoveryCandidates: () => Effect.die("unused getLimitRecoveryCandidates"),
213 getShellSnapshot: () => Effect.die("unused getShellSnapshot"),
214 + listActiveSubagentThreadIds: () => Effect.die("unused listActiveSubagentThreadIds"),
215 readShellSnapshot: () => Effect.die("unused readShellSnapshot"),
216 getThreadShell: () => Effect.die("unused getThreadShell"),
217 getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),
apps/server/src/orchestration-v2/ThreadManagementService.ts
+2
@@ -362,6 +362,7 @@ export interface ThreadManagementServiceShape {
362 readonly getShellSnapshot: (options?: {
363 readonly location?: "active" | "archive";
364 }) => Effect.Effect<OrchestrationV2ThreadShellSnapshot, Orchestrator.OrchestratorV2Error>;
365 + readonly listActiveSubagentThreadIds: Orchestrator.OrchestratorV2["Service"]["listActiveSubagentThreadIds"];
366 readonly readShellSnapshot: (options?: {
367 readonly location?: "active" | "archive";
368 }) => Effect.Effect<
@@ -1173,6 +1174,7 @@ const make = Effect.gen(function* () {
1174 getProjectThreadRecords,
1175 getProjectThread,
1176 getShellSnapshot: orchestrator.getShellSnapshot,
1177 + listActiveSubagentThreadIds: orchestrator.listActiveSubagentThreadIds,
1178 readShellSnapshot: orchestrator.readShellSnapshot,
1179 getThreadShell: orchestrator.getThreadShell,
1180 listProjectThreads,
apps/server/src/relay/AgentAwarenessRelay.test.ts
+1
@@ -187,6 +187,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
187 catchUp.shellSnapshotReads += 1;
188 return { schemaVersion: 2, snapshotSequence: 1, threads: [], archivedThreads: [] };
189 }),
190 + listActiveSubagentThreadIds: unused,
191 readShellSnapshot: unused,
192 ensureLegacyTranscript: unused,
193 dispatch: unused,
apps/server/src/ws.test.ts
+2 -1
@@ -252,7 +252,8 @@ it.live.each(["thread", "shell"] as const)(
252 const items = yield* subscription.pipe(
253 Effect.provideService(ThreadManagement.ThreadManagementService, {
254 ensureLegacyTranscript: () => Effect.void,
255 - getShellSnapshot: () => Effect.succeed({ threads: [] }),
255 + getShellSnapshot: () => Effect.die("shell resume must not load a full snapshot"),
256 + listActiveSubagentThreadIds: () => Effect.succeed([]),
257 streamStoredEventsFrom: (
258 input: Parameters<
259 ThreadManagement.ThreadManagementService["Service"]["streamStoredEventsFrom"]
apps/server/src/ws.ts
+1 -6
@@ -1172,12 +1172,7 @@ export const subscribeOrchestrationV2Shell = Effect.fn("ws.orchestrationV2.subsc
1172 });
1173 }
1174
1175 - const currentShell = yield* threadManagement.getShellSnapshot({ location: "active" });
1176 - subagentThreadIds = new Set(
1177 - currentShell.threads
1178 - .filter((thread) => thread.lineage.relationshipToParent === "subagent")
1179 - .map((thread) => thread.id),
1180 - );
1175 + subagentThreadIds = new Set(yield* threadManagement.listActiveSubagentThreadIds());
1176
1177 const loaded = yield* loadProjectMetadataSnapshot(highWater);
1178 const replay = toShellStream(