Skip to content

Keep project switches from killing live runs#1748

Open
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-switch-kill
Open

Keep project switches from killing live runs#1748
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-switch-kill

Conversation

@iyernaveenr

Copy link
Copy Markdown

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

  • Skip the stale-cache eviction while any of the outgoing Project's runs still holds a live stream. The stale flag stays set, so the eviction (and fresh reload) simply happens on a later transition when nothing is running.
  • Make history replay refuse to tear down a live stream in any case: if a replay targets a task id that still has an active stream, skip the replay -- the ongoing run is the fresher state.

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.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants