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
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed