t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Outbox poison-pill retry loop permanently wedges per-thread effect lane, even after thread deletion

Open mateodelcon1 opened this issue 4 days ago • 1 comments

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:

  • cannotSettleRun only matches ProviderTurnStartService.isProviderTurnStartRunStateMissingError(error.cause).
  • Any other persistent failure — such as ProviderTurnControlError from provider-turn.restart, an invalid session binding, or a missing run row without attemptId — causes effect.attemptCount >= maxAttempts && (!ownsStartingRun(effect.request) || cannotSettleRun(exit.cause)) to stay false forever, looping on outbox.retry({ delayMs: 30_000 }).
  • In apps/server/src/orchestration-v2/Orchestrator.ts (lines 16265–16273), thread.delete only sets cancelUnsettledEffects.effectTypes to ["provider-runtime.continue", "thread-title.generate"]. It never cancels pending/running provider-turn.start, provider-turn.restart, or provider-session.detach effects, so deleting the wedged thread leaves the stuck effect retrying forever and blocking deletion cleanup.

Steps to reproduce

  1. Start a thread and trigger a provider-turn.restart (e.g., steering or changing model selection while a turn is slow to terminalize) so ProviderTurnControlService.interruptAndAwaitTerminal fails with ProviderTurnControlError (or any permanent error other than ProviderTurnStartRunStateMissingError).
  2. Allow effect.attemptCount to reach maxAttempts.
  3. Observe orchestration_v2_effect_outbox: the effect remains in pending/running retrying every 30 s indefinitely instead of failing and settling the run.
  4. 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 EffectWorker retry ceiling for ownsStartingRun effects or thread.delete failing to cancel provider-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:

  1. Cancelling provider-turn.start, provider-turn.restart, and provider-session.detach in thread.delete's cancelUnsettledEffects (and short-circuiting when thread.deletedAt !== null).
  2. Enforcing a hard retry ceiling in EffectWorker for ownsStartingRun effects that settles the starting run via failStartingRun before transitioning the outbox row to failed.

Filed by

Antigravity (gemini-4-neon) via t3 triage playbook

mateodelcon1 avatar Nov 27 '26 23:11 mateodelcon1

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.

juliusmarminge avatar Nov 27 '26 23:11 juliusmarminge