@devries-cameron20 / t3code Mirror · read-only / commits / 37e0fd378a
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, 19:45 UTC

fix(server): a run whose recovery state can't be read fails instead of staying starting (#35013)

Julius Marminge committed Nov 12, 2026 at 02:29 UTC 37e0fd378abcd044924ef095d912139e3606a6ab
2 files changed +49 -12
apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
+36 -9
@@ -201,7 +201,7 @@ function startWithMissingWorktree(
201
202 const start = Effect.gen(function* () {
203 return yield* (yield* ProviderTurnStart.ProviderTurnStartServiceV2)
204 - .start({ threadId, runId })
204 + .start({ threadId, runId, willRetry: true })
205 .pipe(Effect.flip);
206 }).pipe(Effect.provide(layer), Effect.runPromise);
207 return {
@@ -288,6 +288,7 @@ function makeLocalCommandHarness(input: {
288 readonly interruptRunBeforeOpenFailure?: boolean;
289 readonly writeFailure?: unknown;
290 readonly failReadsAfterRunning?: boolean;
291 + readonly recoveryReadFailure?: string;
292 readonly previousTurn?: {
293 readonly runStatus: "failed" | "completed";
294 readonly turnStatus: "running" | "completed" | "interrupted";
@@ -924,14 +925,21 @@ function makeLocalCommandHarness(input: {
925 const getRuntimeRecoveryProjection = vi.fn<
926 ProjectionStore.ProjectionStoreV2Shape["getRuntimeRecoveryProjection"]
927 >(() =>
927 - Effect.as(failReadIfRunning, {
928 - ...projection,
929 - hasConversation: projection.messages.some(
930 - (m) =>
931 - m.role === "user" &&
932 - (m.text.trim().toLowerCase() !== "/compact" || m.attachments.length > 0),
933 - ),
934 - }),
928 + input.recoveryReadFailure !== undefined
929 + ? Effect.fail(
930 + new ProjectionStore.ProjectionStoreReadError({
931 + threadId,
932 + cause: input.recoveryReadFailure,
933 + }),
934 + )
935 + : Effect.as(failReadIfRunning, {
936 + ...projection,
937 + hasConversation: projection.messages.some(
938 + (m) =>
939 + m.role === "user" &&
940 + (m.text.trim().toLowerCase() !== "/compact" || m.attachments.length > 0),
941 + ),
942 + }),
943 );
944 const layer = ProviderTurnStart.layer.pipe(
945 Layer.provide(
@@ -1660,6 +1668,25 @@ effectIt.effect("starts another provider in the same checkout while a turn is pe
1668 }),
1669 );
1670
1671 +effectIt.effect("fails a starting run when its recovery state cannot be read", () =>
1672 + Effect.gen(function* () {
1673 + const harness = makeLocalCommandHarness({
1674 + text: "Continue",
1675 + recoveryReadFailure: "stored turn item no longer decodes",
1676 + });
1677 +
1678 + yield* harness.start.pipe(Effect.ignore);
1679 +
1680 + expect(harness.open).not.toHaveBeenCalled();
1681 + expect(harness.startRootRun).not.toHaveBeenCalled();
1682 + const projection = harness.projection();
1683 + expect(projection.runs.at(-1)).toMatchObject({ status: "failed", startedAt: null });
1684 + expect(projection.attempts[0]).toMatchObject({ status: "failed", startedAt: null });
1685 + expect(projection.nodes[0]).toMatchObject({ status: "failed", startedAt: null });
1686 + expect(projection.turnItems).toMatchObject([{ type: "error", status: "failed" }]);
1687 + }),
1688 +);
1689 +
1690 effectIt.effect("terminalizes a starting run when its provider session cannot open", () =>
1691 Effect.gen(function* () {
1692 const harness = makeLocalCommandHarness({
apps/server/src/orchestration-v2/ProviderTurnStartService.ts
+13 -3
@@ -702,9 +702,19 @@ export const layer: Layer.Layer<
702 runs: current.runs,
703 turnItems: current.turnItems,
704 });
705 - const inheritedBackgroundTurnItems = yield* projectionStore
706 - .getRuntimeRecoveryProjection(projection.thread.id)
707 - .pipe(Effect.map(selectInheritedBackgroundItems));
705 + const recoveryResult = yield* Effect.result(
706 + projectionStore.getRuntimeRecoveryProjection(projection.thread.id),
707 + );
708 + if (recoveryResult._tag === "Failure") {
709 + if (input.willRetry === true) return yield* recoveryResult.failure;
710 + yield* settleStartFailure({
711 + signal: "runtime-recovery-read-failure",
712 + title: "Couldn't read thread state",
713 + error: recoveryResult.failure,
714 + });
715 + return;
716 + }
717 + const inheritedBackgroundTurnItems = selectInheritedBackgroundItems(recoveryResult.success);
718 const providerSessionId = providerThread.providerSessionId;
719 const runControls = makeRunControls({
720 threadId: projection.thread.id,