reconcile provider session state and settle stuck turns#2666
reconcile provider session state and settle stuck turns#2666justsomelegs wants to merge 13 commits into
Conversation
|
React Review found Copy prompt for agentReviewed by react-review for commit d2742fc. Configure here. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What Changed
Fixes several provider session / turn lifecycle cases where T3 Code could leave a thread in the wrong state after provider runtime events, interrupts, stop failures, or server restart.
Main changes:
Treat active
turn.completedevents as lifecycle-ending events:readyerroractiveTurnIdis clearedTreat active
turn.abortedevents as lifecycle-ending events:readyactiveTurnIdis clearedIgnore completion/abort events for non-active turns so auxiliary provider work, like OpenCode title generation, does not incorrectly stop the main running turn.
Reconcile projected running sessions on server startup:
Make
thread.session.stopnon-destructive on provider stop failure:lastErrorPreserve failed turn state in server and web projections:
errorsettle the latest running turn aserrorinterruptedFix OpenCode adapter interrupt handling:
readyturn.abortedeventWhy
A few different provider lifecycle paths were being treated too loosely.
The main symptom was that a thread could stay stuck as “working” even after the provider had already finished, aborted, or lost the active session. This was especially visible with OpenCode, but the underlying fixes are in shared provider orchestration and projection code, so they apply more broadly than just OpenCode.
This approach keeps the existing event model, but makes the lifecycle rules stricter:
Fixes #2644
Fixes #2633
Fixes #2573
UI Changes
No UI changes.
Testing
bun run test src/orchestration/Layers/ProviderRuntimeIngestion.test.ts src/orchestration/Layers/ProjectionPipeline.test.ts src/orchestration/Layers/ProviderCommandReactor.test.ts src/provider/Layers/OpenCodeAdapter.test.tsbun run test src/store.test.tsbun fmtbun lintbun typecheckbun lintpasses with existing unrelated warnings.Checklist
Note
Handle stale provider runtime state by settling running turns on session stop or error
reconcileStaleRunningSessionscompares projected running sessions against live provider sessions; sessions with no live counterpart are stopped and given a descriptivelastError, while live ready sessions are mirrored and their latest turn settled.processSessionStopRequestednow treats 'session not found' as a benign stop; other stop failures record aprovider.session.stop.failedactivity and preserve running state withlastError.turn.abortedevents inProviderRuntimeIngestionnow mark the thread session as ready and clear the active turn, matching the behavior ofturn.completed.interruptTurninOpenCodeAdapterimmediately clearsactiveTurnIdand session state before emittingturn.aborted; prompt-start failures no longer emitturn.aborted.latestTurntointerruptedorerrorwithcompletedAtwhen a session transitions to a non-running status or a stop is requested optimistically.Macroscope summarized d2742fc.