Skip to content

Commit 3f8ba40

Browse files
shivamhwpclaude
andcommitted
fix(server): keep mixed interrupt causes cancelling the transcript loop
A cause with both an interruption and a failure now propagates instead of being recovered as a thread error. Add a test where one thread's hydration defects (an unparseable timestamp): it records last_error and later threads still hydrate. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent b2fb81c commit 3f8ba40

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/legacy/LegacyV1ThreadImporter.test.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,4 +682,76 @@ it.layer(TestLayer)("LegacyV1ThreadImporter unreadable message context", (it) =>
682682
);
683683
}),
684684
);
685+
686+
it.effect("records a failed thread and keeps hydrating the rest", () =>
687+
Effect.gen(function* () {
688+
const sql = yield* SqlClient.SqlClient;
689+
const importer = yield* LegacyV1ThreadImporter;
690+
const projections = yield* ProjectionStoreV2;
691+
const failingThreadId = ThreadId.make("thread:legacy-defect-failing");
692+
const laterThreadId = ThreadId.make("thread:legacy-defect-later");
693+
694+
yield* sql`
695+
INSERT INTO projection_projects (
696+
project_id, title, workspace_root, scripts_json, created_at, updated_at
697+
) VALUES (
698+
'project:legacy-defect', 'Legacy project', '/tmp/legacy-defect',
699+
'[]', '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z'
700+
)
701+
`;
702+
yield* sql`
703+
INSERT INTO projection_threads (
704+
thread_id, project_id, title, model_selection_json, runtime_mode,
705+
interaction_mode, created_at, updated_at
706+
) VALUES
707+
(${failingThreadId}, 'project:legacy-defect', 'Failing thread',
708+
'{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default',
709+
'2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z'),
710+
(${laterThreadId}, 'project:legacy-defect', 'Later thread',
711+
'{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default',
712+
'2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z')
713+
`;
714+
// The unparseable timestamp sorts before real ones, so it stays out of
715+
// the shell preview and fails only transcript hydration.
716+
yield* sql`
717+
INSERT INTO projection_thread_messages (
718+
message_id, thread_id, role, text, attachments_json, context_json,
719+
is_streaming, created_at, updated_at
720+
) VALUES
721+
('message:failing:1', ${failingThreadId}, 'user', 'Old question', '[]', NULL, 0,
722+
'0000-not-a-date', '0000-not-a-date'),
723+
('message:failing:2', ${failingThreadId}, 'user', 'Latest question', '[]', NULL, 0,
724+
'2026-01-02T01:00:00.000Z', '2026-01-02T01:00:00.000Z'),
725+
('message:later:1', ${laterThreadId}, 'user', 'Old question', '[]', NULL, 0,
726+
'2026-01-01T01:00:00.000Z', '2026-01-01T01:00:00.000Z'),
727+
('message:later:2', ${laterThreadId}, 'assistant', 'Old answer', '[]', NULL, 0,
728+
'2026-01-01T02:00:00.000Z', '2026-01-01T02:00:00.000Z'),
729+
('message:later:3', ${laterThreadId}, 'user', 'Latest question', '[]', NULL, 0,
730+
'2026-01-02T01:00:00.000Z', '2026-01-02T01:00:00.000Z')
731+
`;
732+
733+
assert.equal((yield* importer.reconcileShells).importedThreadCount, 2);
734+
assert.deepStrictEqual(yield* importer.importPendingTranscripts, {
735+
importedThreadCount: 1,
736+
importedMessageCount: 2,
737+
});
738+
assert.deepStrictEqual(
739+
yield* sql<{ readonly thread_id: string; readonly last_error: string | null }>`
740+
SELECT thread_id, last_error FROM orchestration_v2_legacy_imports
741+
WHERE transcript_imported_at IS NULL OR last_error IS NOT NULL
742+
`,
743+
[
744+
{
745+
thread_id: failingThreadId,
746+
last_error: "Transcript hydration failed; retry on next open.",
747+
},
748+
],
749+
);
750+
const laterProjection = yield* projections.getThreadProjection(laterThreadId);
751+
assert.deepStrictEqual(
752+
laterProjection.messages.map((message) => message.id),
753+
["message:later:1", "message:later:2", "message:later:3"],
754+
);
755+
}),
756+
);
685757
});

‎apps/server/src/orchestration-v2/legacy/LegacyV1ThreadImporter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ const make = Effect.gen(function* () {
779779
// interruption (shutdown) still propagates.
780780
const result = yield* ensureTranscript(ThreadId.make(row.thread_id)).pipe(
781781
Effect.catchCauseIf(
782-
(cause) => !Cause.hasInterruptsOnly(cause),
782+
(cause) => !Cause.hasInterrupts(cause),
783783
(cause) =>
784784
Effect.logWarning("Failed to hydrate migrated v1 thread transcript", {
785785
threadId: row.thread_id,

0 commit comments

Comments
 (0)