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

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

fix(server): clear title markers stuck on old subagent and fork threads (#37364)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Hatzenbuhler committed Nov 15, 2026 at 16:27 UTC f5d86e31e82ff5db595426c06598493a6d587f2b
4 files changed +145
apps/server/src/persistence/Migrations.ts
+2
@@ -103,6 +103,7 @@ import Migration0092 from "./Migrations/092_QueuedTurnInputIndexJsonValid.ts";
103 import Migration0093 from "./Migrations/093_ProviderTurnAttemptIndex.ts";
104 import Migration0094 from "./Migrations/094_TurnItemMessageOrdinalIndex.ts";
105 import Migration0095 from "./Migrations/095_TurnItemInlineWorkOutput.ts";
106 +import Migration0096 from "./Migrations/096_RepairStaleTitleRegeneration.ts";
107
108 const migrationEntries = [
109 [1, "OrchestrationEvents", Migration0001],
@@ -201,6 +202,7 @@ const migrationEntries = [
202 [93, "ProviderTurnAttemptIndex", Migration0093],
203 [94, "TurnItemMessageOrdinalIndex", Migration0094],
204 [95, "TurnItemInlineWorkOutput", Migration0095],
205 + [96, "RepairStaleTitleRegeneration", Migration0096],
206 ] as const;
207
208 export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
apps/server/src/persistence/Migrations/096_RepairStaleTitleRegeneration.test.ts new
+119
@@ -0,0 +1,119 @@
1 +import { assert, it } from "@effect/vitest";
2 +import { OrchestrationV2AppThreadJson } from "@t3tools/contracts";
3 +import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
4 +import * as Effect from "effect/Effect";
5 +import * as Schema from "effect/Schema";
6 +import * as SqlClient from "effect/sql/SqlClient";
7 +
8 +import { runMigrations } from "../Migrations.ts";
9 +
10 +const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" }));
11 +const createdAt = "2026-10-05T08:45:02.809Z";
12 +const decodeThreadPayload = Schema.decodeUnknownEffect(
13 + Schema.fromJsonString(OrchestrationV2AppThreadJson),
14 +);
15 +
16 +layer("096_RepairStaleTitleRegeneration", (it) => {
17 + it.effect("clears title markers that no pending or running title job will complete", () =>
18 + Effect.gen(function* () {
19 + const sql = yield* SqlClient.SqlClient;
20 + yield* runMigrations({ toMigrationInclusive: 95 });
21 +
22 + const insertThread = (id: string, titleRegeneration: unknown, parentThreadId?: string) => {
23 + const payload = {
24 + id,
25 + projectId: "project-1",
26 + title: id,
27 + providerInstanceId: "codex",
28 + modelSelection: { instanceId: "codex", model: "gpt-5.4" },
29 + runtimeMode: "full-access",
30 + interactionMode: "default",
31 + createdBy: parentThreadId === undefined ? "user" : "agent",
32 + creationSource: "web",
33 + branch: null,
34 + worktreePath: null,
35 + activeProviderThreadId: null,
36 + lineage: {
37 + parentThreadId: parentThreadId ?? null,
38 + relationshipToParent: parentThreadId === undefined ? null : "subagent",
39 + rootThreadId: parentThreadId ?? id,
40 + },
41 + forkedFrom: null,
42 + createdAt,
43 + updatedAt: createdAt,
44 + archivedAt: null,
45 + deletedAt: null,
46 + titleRegeneration,
47 + };
48 + return sql`
49 + INSERT INTO orchestration_v2_projection_threads (
50 + thread_id, project_id, title, default_provider, runtime_mode, interaction_mode,
51 + created_at, updated_at, payload_json
52 + ) VALUES (
53 + ${id}, 'project-1', ${id}, 'codex', 'full-access', 'default',
54 + ${createdAt}, ${createdAt}, ${JSON.stringify(payload)}
55 + )
56 + `;
57 + };
58 + const insertTitleJob = (threadId: string, commandId: string, status: string) =>
59 + sql`
60 + INSERT INTO orchestration_v2_effect_outbox (
61 + effect_id, command_id, thread_id, effect_type, payload_json, status,
62 + available_at, created_at, updated_at
63 + ) VALUES (
64 + ${`effect:${commandId}:${threadId}`}, ${commandId}, ${threadId},
65 + 'thread-title.generate', '{}', ${status}, ${createdAt}, ${createdAt}, ${createdAt}
66 + )
67 + `;
68 + const marker = (requestId: string) => ({ requestId, startedAt: createdAt });
69 +
70 + // A subagent copied its parent's marker, and only the parent had a title job.
71 + yield* insertThread("parent", null);
72 + yield* insertTitleJob("parent", "parent:initial-message", "succeeded");
73 + yield* insertThread("subagent", marker("parent:initial-message"), "parent");
74 + // A subagent whose parent's title job is still queued has no job of its own either.
75 + yield* insertThread("queued-parent", marker("queued:initial-message"));
76 + yield* insertTitleJob("queued-parent", "queued:initial-message", "pending");
77 + yield* insertThread("queued-subagent", marker("queued:initial-message"), "queued-parent");
78 + // Jobs that finished without clearing the marker will not run again.
79 + yield* insertThread("failed-job", marker("failed:regenerate"));
80 + yield* insertTitleJob("failed-job", "failed:regenerate", "failed");
81 + yield* insertThread("cancelled-job", marker("cancelled:regenerate"));
82 + yield* insertTitleJob("cancelled-job", "cancelled:regenerate", "cancelled");
83 + // A live job for an older request cannot clear a newer marker.
84 + yield* insertThread("superseded-job", marker("new:regenerate"));
85 + yield* insertTitleJob("superseded-job", "old:regenerate", "running");
86 + // Live jobs still complete their own marker.
87 + yield* insertThread("running-job", marker("running:regenerate"));
88 + yield* insertTitleJob("running-job", "running:regenerate", "running");
89 + yield* insertThread("absent", undefined);
90 +
91 + const rows = sql<{ readonly thread_id: string; readonly payload_json: string }>`
92 + SELECT thread_id, payload_json FROM orchestration_v2_projection_threads ORDER BY thread_id
93 + `;
94 + const before = new Map((yield* rows).map((row) => [row.thread_id, row.payload_json]));
95 +
96 + yield* runMigrations({ toMigrationInclusive: 96 });
97 + const after = new Map((yield* rows).map((row) => [row.thread_id, row.payload_json]));
98 + for (const id of ["parent", "queued-parent", "running-job", "absent"]) {
99 + assert.strictEqual(after.get(id), before.get(id));
100 + }
101 + const markers = yield* sql`
102 + SELECT thread_id, json_type(payload_json, '$.titleRegeneration') AS type
103 + FROM orchestration_v2_projection_threads
104 + WHERE thread_id NOT IN ('parent', 'queued-parent', 'running-job', 'absent')
105 + ORDER BY thread_id
106 + `;
107 + assert.deepStrictEqual(markers, [
108 + { thread_id: "cancelled-job", type: "null" },
109 + { thread_id: "failed-job", type: "null" },
110 + { thread_id: "queued-subagent", type: "null" },
111 + { thread_id: "subagent", type: "null" },
112 + { thread_id: "superseded-job", type: "null" },
113 + ]);
114 + const subagent = yield* decodeThreadPayload(after.get("subagent"));
115 + assert.strictEqual(subagent.titleRegeneration, null);
116 + assert.strictEqual(subagent.title, "subagent");
117 + }),
118 + );
119 +});
apps/server/src/persistence/Migrations/096_RepairStaleTitleRegeneration.ts new
+22
@@ -0,0 +1,22 @@
1 +import * as Effect from "effect/Effect";
2 +import * as SqlClient from "effect/sql/SqlClient";
3 +
4 +// Subagents and forks once copied their source's title marker without a title job of their own,
5 +// so only a pending or running job for the thread's current request can still clear it.
6 +export default Effect.gen(function* () {
7 + const sql = yield* SqlClient.SqlClient;
8 + yield* sql`
9 + UPDATE orchestration_v2_projection_threads
10 + SET payload_json = json_set(payload_json, '$.titleRegeneration', json('null'))
11 + WHERE json_valid(payload_json)
12 + AND json_type(payload_json, '$.titleRegeneration') = 'object'
13 + AND NOT EXISTS (
14 + SELECT 1 FROM orchestration_v2_effect_outbox AS job
15 + WHERE job.effect_type = 'thread-title.generate'
16 + AND job.thread_id = orchestration_v2_projection_threads.thread_id
17 + AND job.command_id =
18 + json_extract(orchestration_v2_projection_threads.payload_json, '$.titleRegeneration.requestId')
19 + AND job.status IN ('pending', 'running')
20 + )
21 + `;
22 +});
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+2
@@ -75,6 +75,7 @@ describe("V2 preview upgrade", () => {
75 [93, "ProviderTurnAttemptIndex"],
76 [94, "TurnItemMessageOrdinalIndex"],
77 [95, "TurnItemInlineWorkOutput"],
78 + [96, "RepairStaleTitleRegeneration"],
79 ]);
80 assert.deepStrictEqual(yield* runMigrations(), []);
81 assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -193,6 +194,7 @@ describe("V2 preview upgrade", () => {
194 [93, "ProviderTurnAttemptIndex"],
195 [94, "TurnItemMessageOrdinalIndex"],
196 [95, "TurnItemInlineWorkOutput"],
197 + [96, "RepairStaleTitleRegeneration"],
198 ]);
199 }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
200 );