Keep project switches from killing live runs#1748
Open
iyernaveenr wants to merge 1 commit into
Open
Conversation
Opening a Project that was hydrated from a stale cache marks it for runtime eviction on the next transition away. If a run was still streaming, returning to the Project rebuilt it from history and replayed the ongoing task id, which aborted the live run's stream; the backend treated the disconnect as a cancel and the run died with its session stuck as ongoing forever. Skip the eviction while any of the Project's runs still holds a live stream (the stale flag stays set, so eviction happens on a later, safe transition), and make history replay refuse to tear down a live stream in any case -- the ongoing run is the fresher state. Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Switching to another Project and back while a run is streaming can kill the run: its stream is aborted client-side, the backend treats the disconnect as a cancel and aborts the in-flight work, and the conversation is left stuck as ongoing forever (spinner, no output, zero recorded tokens). To the user it looks like the run "never started".
Root cause
When a Project is hydrated from a cached snapshot and the server has newer activity, the Project is flagged so its runtime state is evicted on the next transition away (forcing a fresh history load next time). That eviction also drops the chat stores of a still-streaming run. Returning to the Project then rebuilds it from history -- which includes the still-ongoing task -- and the history replay for that task id finds the live stream controller and aborts it ("already has an active SSE connection, aborting old one").
Fix
Testing
Reproduced deterministically before the fix (Linux desktop): open a Project whose cache is older than its server state, start a long-running task, switch to another Project and back -- the console logs the abort warning, the backend logs a stream cancellation, and the run dies with its session permanently stuck as ongoing. After the fix, the same sequence leaves the run untouched: no abort, no history reload, and the task completes normally with its output and token count recorded.
tsc, lint, and the store test suites pass.