From 64215d69cb5bce15b31a8ebd93473038d3cb378d Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Sun, 15 Nov 2026 23:30:21 -0800 Subject: [PATCH 1/6] test(server): a subagent child should not inherit its parent's group A delegated child copies its parent's group, so Stop and End group on the child reach the parent's seat. The test gives the parent an active group, a snooze wake, an active order key, and open stats. The child must have none of them. grok-4.7 via Cursor Co-authored-by: Cursor --- .../SubagentProjection.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/apps/server/src/orchestration-v2/SubagentProjection.test.ts b/apps/server/src/orchestration-v2/SubagentProjection.test.ts index c8c764ac27865..695bebbfc0981 100644 --- a/apps/server/src/orchestration-v2/SubagentProjection.test.ts +++ b/apps/server/src/orchestration-v2/SubagentProjection.test.ts @@ -92,6 +92,25 @@ it("resets a subagent child's snooze, title job and remote delegation but keeps threadId: ThreadId.make("linked-parent"), title: "Linked parent", }, + lastSnoozeWakeAt: snoozedAt, + activeOrderKey: "parent-active", + opens: { openedAt: 1_753_348_800_000, score: 4, picks: [] }, + group: { + status: "active", + primary: { model: "gpt-5.4", label: "GPT", handle: "gpt" }, + seats: [ + { + threadId: ThreadId.make("thread:parent-seat"), + handle: "claude", + label: "Claude", + status: "seated", + joinedAfterRun: 1, + }, + ], + discussion: { mode: "everyone", turnsLeft: 2, delivering: ["primary"] }, + closedBecause: null, + closedAt: null, + }, }; const childProviderThreadId = ProviderThreadId.make("provider-thread:subagent-awake-child"); const parentNodeId = NodeId.make("node:subagent-parent"); @@ -110,6 +129,10 @@ it("resets a subagent child's snooze, title job and remote delegation but keeps assert.isNull(childThread.snoozedUntil); assert.isNull(childThread.snoozedAt); + assert.isNull(childThread.lastSnoozeWakeAt); + assert.isNull(childThread.activeOrderKey); + assert.isNull(childThread.opens); + assert.isNull(childThread.group); assert.isNull(childThread.titleRegeneration); assert.isUndefined(childThread.delegatedFrom); assert.equal(childThread.projectId, parentThread.projectId); From 52632bb14afe9e3408e1b1f811c937eb98d6d06f Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Sun, 15 Nov 2026 23:32:06 -0800 Subject: [PATCH 2/6] fix(server): subagent children no longer inherit the parent's group makeSubagentChildThread copied every parent field except delegatedFrom. Stop and End group on that child then reached the parent's seat. The child now clears group, lastSnoozeWakeAt, activeOrderKey, and opens, the same fields a fork already clears. grok-4.7 via Cursor Co-authored-by: Cursor --- packages/provider-core/src/server/subagentProjection.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/provider-core/src/server/subagentProjection.ts b/packages/provider-core/src/server/subagentProjection.ts index b10a3147eeee8..a3175f64464f4 100644 --- a/packages/provider-core/src/server/subagentProjection.ts +++ b/packages/provider-core/src/server/subagentProjection.ts @@ -96,12 +96,17 @@ export function makeSubagentChildThread(input: { settledAt: null, snoozedUntil: null, snoozedAt: null, + lastSnoozeWakeAt: null, pinnedAt: null, pinOrderKey: null, + activeOrderKey: null, autoSettleDisabledAt: null, // A guest link belongs to the thread it was made for. guestShare: null, + // Seats belong to the thread that invited them. + group: null, lastVisitedAt: null, + opens: null, deletedAt: null, }; } From 659ff80602a4b7023db1b0ef3623ba177fd49f2b Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Sun, 15 Nov 2026 23:39:11 -0800 Subject: [PATCH 3/6] fix(server): clear groups copied into existing subagent threads Existing subagent rows still carry the parent's group, so Stop on those children reaches the parent's seat. Migration 113 removes that group from subagent thread payloads. Owner threads and fork seats keep theirs. grok-4.7 via Cursor Co-authored-by: Cursor --- apps/server/src/persistence/Migrations.ts | 2 + .../113_RepairSubagentGroups.test.ts | 150 ++++++++++++++++++ .../Migrations/113_RepairSubagentGroups.ts | 13 ++ 3 files changed, 165 insertions(+) create mode 100644 apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts create mode 100644 apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts diff --git a/apps/server/src/persistence/Migrations.ts b/apps/server/src/persistence/Migrations.ts index e5b04315655ed..308f2d6d7478b 100644 --- a/apps/server/src/persistence/Migrations.ts +++ b/apps/server/src/persistence/Migrations.ts @@ -123,6 +123,7 @@ import Migration0109 from "./Migrations/109_QueuedTurnInputIndexJsonValid.ts"; import Migration0110 from "./Migrations/110_ProviderTurnAttemptIndex.ts"; import Migration0111 from "./Migrations/111_TurnItemMessageOrdinalIndex.ts"; import Migration0112 from "./Migrations/112_TurnItemInlineWorkOutput.ts"; +import Migration0113 from "./Migrations/113_RepairSubagentGroups.ts"; const migrationEntries = [ [1, "OrchestrationEvents", Migration0001], @@ -238,6 +239,7 @@ const migrationEntries = [ [110, "ProviderTurnAttemptIndex", Migration0110], [111, "TurnItemMessageOrdinalIndex", Migration0111], [112, "TurnItemInlineWorkOutput", Migration0112], + [113, "RepairSubagentGroups", Migration0113], ] as const; export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const); diff --git a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts new file mode 100644 index 0000000000000..bcd3d8d4a8e5e --- /dev/null +++ b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts @@ -0,0 +1,150 @@ +import { assert, it } from "@effect/vitest"; +import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +import { runMigrations } from "../Migrations.ts"; + +const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" })); +const createdAt = "2026-11-15T00:00:00.000Z"; +const group = { + status: "active", + primary: { model: "gpt-5.4", label: "GPT", handle: "gpt" }, + seats: [ + { + threadId: "thread:seat", + handle: "claude", + label: "Claude", + status: "seated", + joinedAfterRun: 1, + }, + ], + discussion: { mode: "everyone", turnsLeft: 2, delivering: ["primary"] }, + closedBecause: null, + closedAt: null, +}; + +function threadPayload(id: string, lineage: object, extras: object = {}) { + return { + id, + projectId: "project-1", + title: id, + providerInstanceId: "codex", + modelSelection: { instanceId: "codex", model: "gpt-5.4" }, + runtimeMode: "full-access", + interactionMode: "default", + createdBy: "user", + creationSource: "web", + branch: null, + worktreePath: null, + activeProviderThreadId: null, + lineage, + forkedFrom: null, + createdAt, + updatedAt: createdAt, + archivedAt: null, + deletedAt: null, + settledOverride: null, + settledAt: null, + group, + ...extras, + }; +} + +layer("113_RepairSubagentGroups", (it) => { + it.effect("removes a copied group from a subagent and leaves the owner and the seat", () => + Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* runMigrations({ toMigrationInclusive: 112 }); + const rows: ReadonlyArray = [ + [ + "owner", + threadPayload("owner", { + parentThreadId: null, + relationshipToParent: null, + rootThreadId: "owner", + }), + ], + [ + "seat", + threadPayload("seat", { + parentThreadId: "owner", + relationshipToParent: "fork", + rootThreadId: "owner", + sideChat: true, + }), + ], + [ + "subagent", + threadPayload( + "subagent", + { + parentThreadId: "owner", + relationshipToParent: "subagent", + rootThreadId: "owner", + }, + { + lastSnoozeWakeAt: createdAt, + activeOrderKey: "parent-active", + opens: { openedAt: 1_753_348_800_000, score: 4, picks: [] }, + }, + ), + ], + ]; + for (const [id, payload] of rows) { + yield* sql` + INSERT INTO orchestration_v2_projection_threads ( + thread_id, project_id, title, default_provider, runtime_mode, interaction_mode, + created_at, updated_at, payload_json + ) VALUES ( + ${id}, 'project-1', ${id}, 'codex', 'full-access', 'default', + ${createdAt}, ${createdAt}, ${JSON.stringify(payload)} + ) + `; + } + + const read = sql<{ + readonly thread_id: string; + readonly payload_json: string; + readonly group_type: string | null; + }>` + SELECT thread_id, payload_json, json_type(payload_json, '$.group') AS group_type + FROM orchestration_v2_projection_threads + ORDER BY thread_id + `; + const before = yield* read; + assert.deepStrictEqual( + before.map((row) => [row.thread_id, row.group_type]), + [ + ["owner", "object"], + ["seat", "object"], + ["subagent", "object"], + ], + ); + + yield* runMigrations({ toMigrationInclusive: 113 }); + const after = new Map((yield* read).map((row) => [row.thread_id, row])); + for (const id of ["owner", "seat"]) { + const earlier = before.find((row) => row.thread_id === id); + assert.strictEqual(after.get(id)?.payload_json, earlier?.payload_json); + assert.strictEqual(after.get(id)?.group_type, "object"); + } + const subagent = after.get("subagent"); + assert.strictEqual(subagent?.group_type, null); + const kept = yield* sql<{ + readonly wake: string | null; + readonly order_key: string | null; + readonly opens_score: number | null; + }>` + SELECT json_extract(payload_json, '$.lastSnoozeWakeAt') AS wake, + json_extract(payload_json, '$.activeOrderKey') AS order_key, + json_extract(payload_json, '$.opens.score') AS opens_score + FROM orchestration_v2_projection_threads + WHERE thread_id = 'subagent' + `; + assert.deepStrictEqual(kept, [ + { wake: createdAt, order_key: "parent-active", opens_score: 4 }, + ]); + }), + ); +}); diff --git a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts new file mode 100644 index 0000000000000..83737e9390fe7 --- /dev/null +++ b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts @@ -0,0 +1,13 @@ +import * as Effect from "effect/Effect"; +import * as SqlClient from "effect/sql/SqlClient"; + +export default Effect.gen(function* () { + const sql = yield* SqlClient.SqlClient; + yield* sql` + UPDATE orchestration_v2_projection_threads + SET payload_json = json_remove(payload_json, '$.group') + WHERE json_valid(payload_json) + AND json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent' + AND json_type(payload_json, '$.group') IS NOT NULL + `; +}); From 41c699cae2cb1cf6bbd1ef03feb9a5dfa465b6ef Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Mon, 16 Nov 2026 00:46:28 -0800 Subject: [PATCH 4/6] test(server): migration history lists RepairSubagentGroups Co-Authored-By: Claude Opus 5.5 --- apps/server/src/persistence/reconcileV2PreviewMigration.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts index 6fa1b398dbe25..c20fc6509518d 100644 --- a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts +++ b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts @@ -92,6 +92,7 @@ describe("V2 preview upgrade", () => { [110, "ProviderTurnAttemptIndex"], [111, "TurnItemMessageOrdinalIndex"], [112, "TurnItemInlineWorkOutput"], + [113, "RepairSubagentGroups"], ]); assert.deepStrictEqual(yield* runMigrations(), []); assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports); @@ -227,6 +228,7 @@ describe("V2 preview upgrade", () => { [110, "ProviderTurnAttemptIndex"], [111, "TurnItemMessageOrdinalIndex"], [112, "TurnItemInlineWorkOutput"], + [113, "RepairSubagentGroups"], ]); }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))), ); From 11a1fef29c1839e13ddef934da06abaef7031e7b Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Mon, 16 Nov 2026 02:57:40 -0800 Subject: [PATCH 5/6] test(server): migration 113 leaves a subagent whose group is null Co-Authored-By: Claude Opus 5.5 --- .../Migrations/113_RepairSubagentGroups.test.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts index bcd3d8d4a8e5e..1894feadde8d8 100644 --- a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts +++ b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.test.ts @@ -90,6 +90,18 @@ layer("113_RepairSubagentGroups", (it) => { }, ), ], + [ + "subagent-null", + threadPayload( + "subagent-null", + { + parentThreadId: "owner", + relationshipToParent: "subagent", + rootThreadId: "owner", + }, + { group: null }, + ), + ], ]; for (const [id, payload] of rows) { yield* sql` @@ -119,15 +131,15 @@ layer("113_RepairSubagentGroups", (it) => { ["owner", "object"], ["seat", "object"], ["subagent", "object"], + ["subagent-null", "null"], ], ); yield* runMigrations({ toMigrationInclusive: 113 }); const after = new Map((yield* read).map((row) => [row.thread_id, row])); - for (const id of ["owner", "seat"]) { + for (const id of ["owner", "seat", "subagent-null"]) { const earlier = before.find((row) => row.thread_id === id); assert.strictEqual(after.get(id)?.payload_json, earlier?.payload_json); - assert.strictEqual(after.get(id)?.group_type, "object"); } const subagent = after.get("subagent"); assert.strictEqual(subagent?.group_type, null); From c9adc8414d7b0f1d5eab70fc4cd3872c1943be7d Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Mon, 16 Nov 2026 02:58:50 -0800 Subject: [PATCH 6/6] fix(server): migration 113 touches only groups that are objects json_type returns the string 'null' for a JSON null, so subagents whose group was already null were rewritten for nothing. Co-Authored-By: Claude Opus 5.5 --- .../src/persistence/Migrations/113_RepairSubagentGroups.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts index 83737e9390fe7..1f42083e1808e 100644 --- a/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts +++ b/apps/server/src/persistence/Migrations/113_RepairSubagentGroups.ts @@ -8,6 +8,6 @@ export default Effect.gen(function* () { SET payload_json = json_remove(payload_json, '$.group') WHERE json_valid(payload_json) AND json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent' - AND json_type(payload_json, '$.group') IS NOT NULL + AND json_type(payload_json, '$.group') = 'object' `; });