Outbox poison-pill retry loop permanently wedges per-thread effect lane, even after thread deletion
What happened
When a provider-turn.start, provider-turn.restart, or provider-session.detach (with handoffRunId) outbox effect hits a permanent error other than ProviderTurnStartRunStateMissingError, EffectWorker retries it every 30 seconds forever instead of settling the starting run and failing the outbox item. Because outbox effects are serialized per thread_id, every subsequent effect for that thread is permanently blocked — including terminal, preview, attachment, and checkpoint cleanup after the thread is deleted.
Diagnosis
In apps/server/src/orchestration-v2/EffectWorker.ts (ownsStartingRun, lines 69–81; reschedule handler, lines 1021–1037), an effect that owns a starting run is only allowed to transition to outbox.fail(...) when cannotSettleRun(exit.cause) returns true:
cannotSettleRunonly matchesProviderTurnStartService.isProviderTurnStartRunStateMissingError(error.cause).- Any other persistent failure — such as
ProviderTurnControlErrorfromprovider-turn.restart, an invalid session binding, or a missing run row withoutattemptId— causeseffect.attemptCount >= maxAttempts && (!ownsStartingRun(effect.request) || cannotSettleRun(exit.cause))to stayfalseforever, looping onoutbox.retry({ delayMs: 30_000 }). - In
apps/server/src/orchestration-v2/Orchestrator.ts(lines 16265–16273),thread.deleteonly setscancelUnsettledEffects.effectTypesto["provider-runtime.continue", "thread-title.generate"]. It never cancels pending/runningprovider-turn.start,provider-turn.restart, orprovider-session.detacheffects, so deleting the wedged thread leaves the stuck effect retrying forever and blocking deletion cleanup.
Steps to reproduce
- Start a thread and trigger a
provider-turn.restart(e.g., steering or changing model selection while a turn is slow to terminalize) soProviderTurnControlService.interruptAndAwaitTerminalfails withProviderTurnControlError(or any permanent error other thanProviderTurnStartRunStateMissingError). - Allow
effect.attemptCountto reachmaxAttempts. - Observe
orchestration_v2_effect_outbox: the effect remains inpending/runningretrying every 30 s indefinitely instead of failing and settling the run. - Delete the thread (
thread.delete) and observe that the stuck effect is not cancelled and blocks downstream per-thread cleanup effects.
Version
0.1.13 (also confirmed on main @ 9a66ff1e and c203d933)
Environment
Windows 10/11 (NT 10.0.26300), Node v26.13.1 (platform-independent server logic in apps/server)
Evidence
// apps/server/src/orchestration-v2/EffectWorker.ts (lines 69-81)
const ownsStartingRun = (request: EffectOutbox.OrchestrationEffectV2["request"]) =>
request.type === "provider-turn.start" ||
request.type === "provider-turn.restart" ||
(request.type === "provider-session.detach" && request.handoffRunId !== undefined);
const cannotSettleRun = (cause: Cause.Cause<unknown>) =>
Cause.findErrorOption(cause).pipe(
Option.exists(
(error) =>
isOrchestrationEffectExecutionError(error) &&
ProviderTurnStartService.isProviderTurnStartRunStateMissingError(error.cause),
),
);
// apps/server/src/orchestration-v2/EffectWorker.ts (lines 1024-1035)
: effect.attemptCount >= maxAttempts &&
(!ownsStartingRun(effect.request) || cannotSettleRun(exit.cause))
? yield* outbox.fail({ effectId: effect.id, workerId, error })
: yield* outbox.retry({
effectId: effect.id,
workerId,
error,
delayMs: Math.min(30_000, 100 * 2 ** Math.max(0, effect.attemptCount - 1)),
})
// apps/server/src/orchestration-v2/Orchestrator.ts (lines 16268-16271)
cancelUnsettledEffects: {
effectTypes: ["provider-runtime.continue", "thread-title.generate"],
reason: "Thread deleted.",
},
Related issues
- #34271 (closed — specific to Codex shared app-server exit leaving a starting run stuck)
- #44370 (closed — specific to unanswered Codex steer)
Neither addresses the general
EffectWorkerretry ceiling forownsStartingRuneffects orthread.deletefailing to cancelprovider-turn.start/provider-turn.restart/provider-session.detach.
Fix applied or workaround
None applied to live install. In a local clone we verified fixing this by:
- Cancelling
provider-turn.start,provider-turn.restart, andprovider-session.detachinthread.delete'scancelUnsettledEffects(and short-circuiting whenthread.deletedAt !== null). - Enforcing a hard retry ceiling in
EffectWorkerforownsStartingRuneffects that settles the starting run viafailStartingRunbefore transitioning the outbox row tofailed.
Filed by
Antigravity (gemini-4-neon) via t3 triage playbook
I tried to reproduce this on the current build and could not.
Commit 09418562d6 (origin/main). Added a test to apps/server/src/orchestration-v2/runtimeLayer.test.ts (describe OrchestrationV2LayerLive) that uses the real orchestrator, EffectOutbox and in-memory SQLite runtime layer: thread.create, message.dispatch (start_immediately), check that the provider-turn.start outbox row is pending, dispatch thread.delete, then read the row back. It fails on main with "expected 'pending' to equal 'cancelled'": the deleted thread's turn start stays pending in its serialized effect lane. Code reading: Orchestrator.ts thread.delete passes cancelUnsettledEffects.effectTypes = ["provider-runtime.continue", "thread-title.generate"] only, while Stop (dispatchRunInterrupt) cancels ["provider-turn.start", "provider-turn.restart"]. EffectWorker.ts reschedule: for ownsStartingRun effects outbox.fail is reached only when cannotSettleRun (ProviderTurnStartRunStateMissingError), so a permanent ProviderTurnControlError from a restart's interruptAndAwaitTerminal retries at a 30 s cap forever. The existing test 'keeps a failed restart interrupt separate from starting-run settlement' pins that the row stays pending. Not run in a live app: making that permanent failure happen for real needs a real provider whose turn never stops after an interrupt, and none was available.
Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.