@devries-cameron20 / t3code-1 / commits / 144b78ae69
Fork 0

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

fix(server): usage-limit auto-resume no longer arms subagents of archived or deleted parents (#30363)

spoukyii committed Nov 5, 2026 at 20:26 UTC 144b78ae690bf9a7dde594f599ebb44fdb742cdb
2 files changed +29 -16
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+23 -14
@@ -6044,15 +6044,16 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
6044 }),
6045 );
6046
6047 - it.effect("does not freshly arm limit recovery for a subagent of a settled parent", () =>
6047 + it.effect("does not freshly arm limit recovery for a subagent of a put-away parent", () =>
6048 Effect.gen(function* () {
6049 const store = yield* ProjectionStore.ProjectionStoreV2;
6050 const now = yield* DateTime.now;
6051 const resetAt = DateTime.formatIso(DateTime.add(now, { hours: 1 }));
6052 + type ParentState = "settled" | "archived" | "deleted" | null;
6053 const threadPayload = (
6054 threadId: ThreadId,
6055 parentThreadId: ThreadId | null,
6055 - settledOverride: "settled" | null,
6056 + state: ParentState,
6057 ) =>
6058 ({
6059 createdBy: "user",
@@ -6075,30 +6076,30 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
6076 forkedFrom: null,
6077 createdAt: now,
6078 updatedAt: now,
6078 - archivedAt: null,
6079 - settledOverride,
6080 - settledAt: settledOverride === null ? null : now,
6079 + archivedAt: state === "archived" ? now : null,
6080 + settledOverride: state === "settled" ? ("settled" as const) : null,
6081 + settledAt: state === "settled" ? now : null,
6082 lastVisitedAt: null,
6082 - deletedAt: null,
6083 + deletedAt: state === "deleted" ? now : null,
6084 }) as const;
6085 const createThread = (
6086 threadId: ThreadId,
6087 parentThreadId: ThreadId | null,
6087 - settledOverride: "settled" | null,
6088 + state: ParentState,
6089 ) =>
6090 store.apply({
6091 id: EventId.make(`event:${threadId}:created`),
6092 type: "thread.created",
6093 threadId,
6094 occurredAt: now,
6094 - payload: threadPayload(threadId, parentThreadId, settledOverride),
6095 + payload: threadPayload(threadId, parentThreadId, state),
6096 });
6096 - const addLimitedChild = Effect.fnUntraced(function* (name: string, parentSettled: boolean) {
6097 + const addLimitedChild = Effect.fnUntraced(function* (name: string, parentState: ParentState) {
6098 const parentId = ThreadId.make(`thread:settled-parent-limit:${name}:parent`);
6099 const childId = ThreadId.make(`thread:settled-parent-limit:${name}:child`);
6100 const runId = RunId.make(`run:settled-parent-limit:${name}`);
6101 const rootNodeId = NodeId.make(`node:settled-parent-limit:${name}`);
6101 - yield* createThread(parentId, null, parentSettled ? "settled" : null);
6102 + yield* createThread(parentId, null, parentState);
6103 yield* createThread(childId, parentId, null);
6104 const run = {
6105 id: runId,
@@ -6160,14 +6161,22 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
6161 });
6162 return childId;
6163 });
6163 - const settledParentChild = yield* addLimitedChild("settled", true);
6164 - const activeParentChild = yield* addLimitedChild("active", false);
6164 + const settledParentChild = yield* addLimitedChild("settled", "settled");
6165 + const archivedParentChild = yield* addLimitedChild("archived", "archived");
6166 + const deletedParentChild = yield* addLimitedChild("deleted", "deleted");
6167 + const activeParentChild = yield* addLimitedChild("active", null);
6168 + const children = [
6169 + settledParentChild,
6170 + archivedParentChild,
6171 + deletedParentChild,
6172 + activeParentChild,
6173 + ];
6174 for (const options of [
6175 { now, autoResume: true, snooze: false },
6176 { now, autoResume: false, snooze: true },
6177 ]) {
6178 const armed = (yield* store.getLimitRecoveryCandidates(options))
6170 - .filter((row) => row.id === settledParentChild || row.id === activeParentChild)
6179 + .filter((row) => children.includes(row.id))
6180 .filter(
6181 (row) =>
6182 limitRecoveryCommand(
@@ -6181,7 +6190,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
6190 assert.deepEqual(
6191 armed,
6192 [activeParentChild],
6184 - `only the child of the unsettled parent is armed (${JSON.stringify(options)})`,
6193 + `only the child of the open parent is armed (${JSON.stringify(options)})`,
6194 );
6195 }
6196 // A recovery armed before the parent settled still resumes at its reset.
apps/server/src/orchestration-v2/ProjectionStore.ts
+6 -2
@@ -4042,12 +4042,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
4042 ${booleanInt(options.autoResume)}
4043 OR (${booleanInt(options.snooze)} AND julianday(json_extract(item.payload_json, '$.failure.resetAt')) > julianday(${DateTime.formatIso(options.now)}))
4044 )
4045 - -- A subagent of a settled parent is abandoned work; resuming it would wake the parent.
4045 + -- A subagent of a settled, archived or deleted parent is abandoned work.
4046 AND NOT EXISTS (
4047 SELECT 1 FROM orchestration_v2_projection_threads parent
4048 WHERE json_extract(t.payload_json, '$.lineage.relationshipToParent') = 'subagent'
4049 AND parent.thread_id = json_extract(t.payload_json, '$.lineage.parentThreadId')
4050 - AND json_extract(parent.payload_json, '$.settledOverride') = 'settled'
4050 + AND (
4051 + json_extract(parent.payload_json, '$.settledOverride') = 'settled'
4052 + OR json_extract(parent.payload_json, '$.archivedAt') IS NOT NULL
4053 + OR parent.deleted_at IS NOT NULL
4054 + )
4055 )
4056 )
4057 )