@devries-cameron20 / t3code Mirror · read-only / commits / e5c636219c
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 21, 13:30 UTC

fix(server): queued-input index no longer rejects user messages with non-JSON payloads (#36898)

Julius Marminge committed Nov 14, 2026 at 11:53 UTC e5c636219c7b0e3c27c6c3f03e16bb1db1ff9d80
6 files changed +87 -1
apps/server/src/orchestration-v2/ProjectionStore.ts
+2
@@ -7932,6 +7932,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7932 INDEXED BY orchestration_v2_projection_turn_items_queued_input_idx
7933 WHERE held.run_id = per_run.run_key
7934 AND held.type = 'user_message'
7935 + AND json_valid(held.payload_json)
7936 AND json_extract(held.payload_json, '$.inputIntent') = 'queued_turn'
7937 )
7938 ELSE 0
@@ -7951,6 +7952,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7952 INDEXED BY orchestration_v2_projection_turn_items_queued_input_idx
7953 WHERE held.run_id = counts.run_key
7954 AND held.type = 'user_message'
7955 + AND json_valid(held.payload_json)
7956 AND json_extract(held.payload_json, '$.inputIntent') = 'queued_turn'
7957 )
7958 ELSE 0
apps/server/src/persistence/Migrations.ts
+2
@@ -99,6 +99,7 @@ import Migration0088 from "./Migrations/088_TurnItemTypeStatusIndex.ts";
99 import Migration0089 from "./Migrations/089_ShellThreadReadIndexes.ts";
100 import Migration0090 from "./Migrations/090_AuthConnectDevices.ts";
101 import Migration0091 from "./Migrations/091_AuthConnectDeniedRequests.ts";
102 +import Migration0092 from "./Migrations/092_QueuedTurnInputIndexJsonValid.ts";
103
104 const migrationEntries = [
105 [1, "OrchestrationEvents", Migration0001],
@@ -193,6 +194,7 @@ const migrationEntries = [
194 [89, "ShellThreadReadIndexes", Migration0089],
195 [90, "AuthConnectDevices", Migration0090],
196 [91, "AuthConnectDeniedRequests", Migration0091],
197 + [92, "QueuedTurnInputIndexJsonValid", Migration0092],
198 ] as const;
199
200 export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
apps/server/src/persistence/Migrations/086_QueuedTurnInputIndex.test.ts new
+62
@@ -0,0 +1,62 @@
1 +import { assert, it } from "@effect/vitest";
2 +import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
3 +import * as Effect from "effect/Effect";
4 +import * as SqlClient from "effect/sql/SqlClient";
5 +
6 +import { runMigrations } from "../Migrations.ts";
7 +
8 +const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" }));
9 +
10 +layer("086_QueuedTurnInputIndex", (it) => {
11 + it.effect("keeps a user message with a malformed payload migratable and writable", () =>
12 + Effect.gen(function* () {
13 + const sql = yield* SqlClient.SqlClient;
14 + yield* runMigrations({ toMigrationInclusive: 85 });
15 + const insertUserMessage = (id: string) => sql`
16 + INSERT INTO orchestration_v2_projection_turn_items (
17 + turn_item_id, thread_id, run_id, ordinal, type, status, updated_at, payload_json
18 + )
19 + VALUES (
20 + ${id}, 'thread-1', 'run-1', 1, 'user_message', 'completed',
21 + '2026-11-14T00:00:00.000Z', '{not json'
22 + )
23 + `;
24 + yield* insertUserMessage("before-86");
25 +
26 + yield* runMigrations();
27 + yield* insertUserMessage("after-86");
28 +
29 + const rows = yield* sql<{ readonly turn_item_id: string }>`
30 + SELECT turn_item_id FROM orchestration_v2_projection_turn_items ORDER BY turn_item_id
31 + `;
32 + assert.deepEqual(
33 + rows.map((row) => row.turn_item_id),
34 + ["after-86", "before-86"],
35 + );
36 + }),
37 + );
38 +
39 + it.effect("re-guards the index on a database that ran the unguarded migration 86", () =>
40 + Effect.gen(function* () {
41 + const sql = yield* SqlClient.SqlClient;
42 + yield* runMigrations({ toMigrationInclusive: 91 });
43 + yield* sql`DROP INDEX orchestration_v2_projection_turn_items_queued_input_idx`;
44 + yield* sql`
45 + CREATE INDEX orchestration_v2_projection_turn_items_queued_input_idx
46 + ON orchestration_v2_projection_turn_items(run_id)
47 + WHERE type = 'user_message' AND json_extract(payload_json, '$.inputIntent') = 'queued_turn'
48 + `;
49 +
50 + yield* runMigrations();
51 + yield* sql`
52 + INSERT INTO orchestration_v2_projection_turn_items (
53 + turn_item_id, thread_id, run_id, ordinal, type, status, updated_at, payload_json
54 + )
55 + VALUES (
56 + 'malformed', 'thread-1', 'run-1', 1, 'user_message', 'completed',
57 + '2026-11-14T00:00:00.000Z', '{not json'
58 + )
59 + `;
60 + }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
61 + );
62 +});
apps/server/src/persistence/Migrations/086_QueuedTurnInputIndex.ts
+3 -1
@@ -8,6 +8,8 @@ export default Effect.gen(function* () {
8 yield* sql`
9 CREATE INDEX orchestration_v2_projection_turn_items_queued_input_idx
10 ON orchestration_v2_projection_turn_items(run_id)
11 - WHERE type = 'user_message' AND json_extract(payload_json, '$.inputIntent') = 'queued_turn'
11 + WHERE type = 'user_message'
12 + AND json_valid(payload_json)
13 + AND json_extract(payload_json, '$.inputIntent') = 'queued_turn'
14 `;
15 });
apps/server/src/persistence/Migrations/092_QueuedTurnInputIndexJsonValid.ts new
+16
@@ -0,0 +1,16 @@
1 +import * as Effect from "effect/Effect";
2 +import * as SqlClient from "effect/sql/SqlClient";
3 +
4 +export default Effect.gen(function* () {
5 + const sql = yield* SqlClient.SqlClient;
6 +
7 + // Databases that ran migration 86 before its json_valid guard reject malformed user messages.
8 + yield* sql`DROP INDEX IF EXISTS orchestration_v2_projection_turn_items_queued_input_idx`;
9 + yield* sql`
10 + CREATE INDEX orchestration_v2_projection_turn_items_queued_input_idx
11 + ON orchestration_v2_projection_turn_items(run_id)
12 + WHERE type = 'user_message'
13 + AND json_valid(payload_json)
14 + AND json_extract(payload_json, '$.inputIntent') = 'queued_turn'
15 + `;
16 +});
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+2
@@ -71,6 +71,7 @@ describe("V2 preview upgrade", () => {
71 [89, "ShellThreadReadIndexes"],
72 [90, "AuthConnectDevices"],
73 [91, "AuthConnectDeniedRequests"],
74 + [92, "QueuedTurnInputIndexJsonValid"],
75 ]);
76 assert.deepStrictEqual(yield* runMigrations(), []);
77 assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -185,6 +186,7 @@ describe("V2 preview upgrade", () => {
186 [89, "ShellThreadReadIndexes"],
187 [90, "AuthConnectDevices"],
188 [91, "AuthConnectDeniedRequests"],
189 + [92, "QueuedTurnInputIndexJsonValid"],
190 ]);
191 }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
192 );