Skip to content

Commit c2fb438

Browse files
fix(server): keep corrupt plan JSON in the typed read error (#21969)
1 parent 8dec2ff commit c2fb438

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type OrchestrationV2ProviderThread,
1212
type OrchestrationV2ThreadShellSnapshot,
1313
NodeId,
14+
PlanId,
1415
ProjectId,
1516
ProviderDriverKind,
1617
ProviderInstanceId,
@@ -997,6 +998,30 @@ it.effect("memory shell snapshots scope to one project", () =>
997998
);
998999

9991000
it.layer(layerTest)("ProjectionStoreV2", (it) => {
1001+
it.effect("returns a typed read error for malformed stored plan JSON", () =>
1002+
Effect.gen(function* () {
1003+
const store = yield* ProjectionStore.ProjectionStoreV2;
1004+
const sql = yield* SqlClient.SqlClient;
1005+
const threadId = yield* addRolledBackRecoveryCandidate("corrupt-plan");
1006+
const planId = PlanId.make("plan:corrupt");
1007+
yield* sql`INSERT INTO orchestration_v2_projection_plans
1008+
(plan_id, thread_id, node_id, kind, status, payload_json)
1009+
VALUES (${planId}, ${threadId}, 'node:corrupt-plan', 'proposed_plan', 'active', '{broken')`;
1010+
1011+
const failure = yield* store
1012+
.getPlan(threadId, planId)
1013+
.pipe(
1014+
Effect.flip,
1015+
Effect.ensuring(
1016+
Effect.orDie(
1017+
sql`DELETE FROM orchestration_v2_projection_plans WHERE plan_id = ${planId}`,
1018+
),
1019+
),
1020+
);
1021+
assert.strictEqual(failure._tag, "ProjectionStoreReadError");
1022+
}),
1023+
);
1024+
10001025
it.effect(
10011026
"SQL recovery selects unfinished runless native subagents",
10021027
() => runlessNativeSubagentNeedsRecovery,

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ const encodeMessagePayload = Schema.encodeEffect(
11481148
const encodePlanPayload = Schema.encodeEffect(
11491149
Schema.fromJsonString(OrchestrationV2PlanArtifactSchema),
11501150
);
1151+
const decodePlanPayload = (json: string) => decodePlanJson(json);
11511152
const encodeTurnItemPayload = Schema.encodeEffect(
11521153
Schema.fromJsonString(OrchestrationV2TurnItemJsonSchema),
11531154
);
@@ -1194,8 +1195,9 @@ const decodeRuntimeRequestPayload = Schema.decodeUnknownEffect(
11941195
const decodeMessagePayload = Schema.decodeUnknownEffect(
11951196
Schema.fromJsonString(OrchestrationV2ConversationMessageJsonSchema),
11961197
);
1197-
const decodePlanArtifact = Schema.decodeUnknownEffect(OrchestrationV2PlanArtifactSchema);
1198-
const decodePlanPayload = (json: string) => decodePlanArtifact(parseEncodedPayload(json));
1198+
const decodePlanJson = Schema.decodeUnknownEffect(
1199+
Schema.fromJsonString(OrchestrationV2PlanArtifactSchema),
1200+
);
11991201
const decodeTurnItemPayload = Schema.decodeUnknownEffect(
12001202
Schema.fromJsonString(OrchestrationV2TurnItemJsonSchema),
12011203
);

0 commit comments

Comments
 (0)