Skip to content

Commit 1973e0a

Browse files
fix(server): a stored boolean settledOverride no longer stops startup (pingdotgg#28314)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 83d2b8e commit 1973e0a

4 files changed

Lines changed: 106 additions & 0 deletions

File tree

‎apps/server/src/persistence/Migrations.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import Migration0073 from "./Migrations/073_ActiveTurnItemIndexes.ts";
7979
import Migration0074 from "./Migrations/074_ExcludeAttachmentPlaceholdersFromSearch.ts";
8080
import Migration0075 from "./Migrations/075_SubagentDeliveryState.ts";
8181
import Migration0076 from "./Migrations/076_ProjectionProjectsPinArchive.ts";
82+
import Migration0077 from "./Migrations/077_RepairBooleanSettledOverride.ts";
8283

8384
const migrationEntries = [
8485
[1, "OrchestrationEvents", Migration0001],
@@ -158,6 +159,7 @@ const migrationEntries = [
158159
[74, "ExcludeAttachmentPlaceholdersFromSearch", Migration0074],
159160
[75, "SubagentDeliveryState", Migration0075],
160161
[76, "ProjectionProjectsPinArchive", Migration0076],
162+
[77, "RepairBooleanSettledOverride", Migration0077],
161163
] as const;
162164

163165
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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-09-01T00:00:00.000Z";
12+
const decodeThreadPayload = Schema.decodeUnknownEffect(
13+
Schema.fromJsonString(OrchestrationV2AppThreadJson),
14+
);
15+
16+
layer("077_RepairBooleanSettledOverride", (it) => {
17+
it.effect("canonicalizes boolean settled overrides so recovery can decode them", () =>
18+
Effect.gen(function* () {
19+
const sql = yield* SqlClient.SqlClient;
20+
yield* runMigrations({ toMigrationInclusive: 76 });
21+
const overrides: ReadonlyArray<readonly [string, unknown]> = [
22+
["true", true],
23+
["false", false],
24+
["settled", "settled"],
25+
["active", "active"],
26+
["null", null],
27+
["absent", undefined],
28+
];
29+
for (const [id, settledOverride] of overrides) {
30+
const payload = {
31+
id,
32+
projectId: "project-1",
33+
title: id,
34+
providerInstanceId: "codex",
35+
modelSelection: { instanceId: "codex", model: "gpt-5.4" },
36+
runtimeMode: "full-access",
37+
interactionMode: "default",
38+
createdBy: "user",
39+
creationSource: "web",
40+
branch: null,
41+
worktreePath: null,
42+
activeProviderThreadId: null,
43+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: id },
44+
forkedFrom: null,
45+
createdAt,
46+
updatedAt: createdAt,
47+
archivedAt: null,
48+
deletedAt: null,
49+
settledOverride,
50+
settledAt: settledOverride === true ? createdAt : null,
51+
};
52+
yield* sql`
53+
INSERT INTO orchestration_v2_projection_threads (
54+
thread_id, project_id, title, default_provider, runtime_mode, interaction_mode,
55+
created_at, updated_at, payload_json
56+
) VALUES (
57+
${id}, 'project-1', ${id}, 'codex', 'full-access', 'default',
58+
${createdAt}, ${createdAt}, ${JSON.stringify(payload)}
59+
)
60+
`;
61+
}
62+
const rows = sql<{ readonly thread_id: string; readonly payload_json: string }>`
63+
SELECT thread_id, payload_json FROM orchestration_v2_projection_threads ORDER BY thread_id
64+
`;
65+
const before = new Map((yield* rows).map((row) => [row.thread_id, row.payload_json]));
66+
67+
yield* runMigrations({ toMigrationInclusive: 77 });
68+
const after = new Map((yield* rows).map((row) => [row.thread_id, row.payload_json]));
69+
for (const id of ["settled", "active", "null", "absent"]) {
70+
assert.strictEqual(after.get(id), before.get(id));
71+
}
72+
const repaired = yield* sql`
73+
SELECT thread_id,
74+
json_type(payload_json, '$.settledOverride') AS type,
75+
json_extract(payload_json, '$.settledOverride') AS settled_override,
76+
json_extract(payload_json, '$.settledAt') AS settled_at
77+
FROM orchestration_v2_projection_threads WHERE thread_id IN ('true', 'false')
78+
ORDER BY thread_id
79+
`;
80+
assert.deepStrictEqual(repaired, [
81+
{ thread_id: "false", type: "null", settled_override: null, settled_at: null },
82+
{ thread_id: "true", type: "text", settled_override: "settled", settled_at: createdAt },
83+
]);
84+
const thread = yield* decodeThreadPayload(after.get("true"));
85+
assert.strictEqual(thread.settledOverride, "settled");
86+
}),
87+
);
88+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Effect from "effect/Effect";
2+
import * as SqlClient from "effect/sql/SqlClient";
3+
4+
// Thread projections may hold a boolean settledOverride, which the thread schema rejects.
5+
export default Effect.gen(function* () {
6+
const sql = yield* SqlClient.SqlClient;
7+
yield* sql`
8+
UPDATE orchestration_v2_projection_threads
9+
SET payload_json = json_set(payload_json, '$.settledOverride',
10+
IIF(json_type(payload_json, '$.settledOverride') = 'true', 'settled', NULL))
11+
WHERE json_valid(payload_json)
12+
AND json_type(payload_json, '$.settledOverride') IN ('true', 'false')
13+
`;
14+
});

‎apps/server/src/persistence/reconcileV2PreviewMigration.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe("V2 preview upgrade", () => {
5656
[74, "ExcludeAttachmentPlaceholdersFromSearch"],
5757
[75, "SubagentDeliveryState"],
5858
[76, "ProjectionProjectsPinArchive"],
59+
[77, "RepairBooleanSettledOverride"],
5960
]);
6061
assert.deepStrictEqual(yield* runMigrations(), []);
6162
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -155,6 +156,7 @@ describe("V2 preview upgrade", () => {
155156
[74, "ExcludeAttachmentPlaceholdersFromSearch"],
156157
[75, "SubagentDeliveryState"],
157158
[76, "ProjectionProjectsPinArchive"],
159+
[77, "RepairBooleanSettledOverride"],
158160
]);
159161
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
160162
);

0 commit comments

Comments
 (0)