Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a turn that fails to start after its session opens now fails the run #14183

Mergedjuliusmarmingemerged 2 commits intot3code/codex-turn-mapping fromrefs/pull/14183/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Addresses #13392 (the server half).

When the last provider-turn.start attempt failed after the provider session opened (for example resumeThread failing, then the fresh ensureThread fallback failing because the Pi process exited), the error escaped ProviderTurnStartService.start. EffectWorker then only marked the outbox row failed. The run stayed starting with a pending attempt forever: the thread showed as working, thread.settle refused it ("has active or blocked work"), and only Delete or an app restart cleared it. Only a failed providerSessions.open settled the run.

What changed

ProviderTurnStartService.start wraps the provider-thread load step (native fork, ensureThread, resumeThread plus its fresh-thread fallback) in Effect.result. On failure:

  • willRetry === true: return the error unchanged, so the run stays starting and the worker retries (same as a session-open failure).
  • Final attempt: settle the run through the existing settleRunBeforeStart, using the same shape as a failed session open: a provider_error item titled "Provider turn failed to start" that carries the adapter's underlying message (e.g. pi process exited with code 1), plus a failed run, attempt and root node. The write goes through writeIfRunCurrent, so a run that was interrupted in the meantime is not overwritten. If the settle write itself fails, that error goes back to the worker.

The failure-item building that the open path already had moved into a small settleStartFailure helper, so both paths share it.

This PR does not include the desktop Stop half of #13392 (offer Stop while a run is preparing/starting). That is a separate web change, and #14088 already covers it, though that PR targets main.

Verification

  • 4 new tests in ProviderTurnStartService.test.ts, using the existing harness with a session that opens and then fails ensureThread with ProviderAdapterEventStreamError:
    • fails a starting run when its last start attempt cannot load the thread: fails on the base branch (run stays starting), passes with the fix.
    • does not overwrite a run interrupted while its thread loads: fails on the base branch, passes with the fix.
    • leaves the run starting when a thread-load failure will be retried: passes before and after.
    • keeps a thread-load failure retryable when terminal persistence fails: passes before and after.
  • vp test run src/orchestration-v2/ProviderTurnStartService.test.ts src/orchestration-v2/EffectWorker.test.ts: 25 passed.
  • vp exec tsc --noEmit -p . in apps/server: no errors. vp lint on both files: clean.
  • Not run: a live Pi launch failure. These tests fake the failure because a real provider can't be made to exit during resume on demand.

Model: Claude Opus 5.5 (Claude Code)

🤖 Generated with Claude Code


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at d3e6416

      Macroscope's review found this PR approvable — This narrowly scoped server bug fix settles runs that fail during provider-thread startup while preserving retries and unrelated persistence errors. The added tests cover terminal, retry, interruption, and typed-error behavior, with no schema, security, deployment, or default-setting changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—4.9 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.7 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.4 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—4.9 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.7 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—20.7 KiB—29.3 KiB✅
      ClaudeLive turn messages—1—8✅

      Baseline: unavailable · PR result: d3e6416 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. juliusmarminge merged thise2a8620

    5. juliusmarminge closed this

Sign in to join this conversation.