fix(gateway): reconcile finished prompt-run threads at session teardown - #89978
Open
100yenadmin wants to merge 1 commit into
Open
fix(gateway): reconcile finished prompt-run threads at session teardown#89978100yenadmin wants to merge 1 commit into
100yenadmin wants to merge 1 commit into
Conversation
A finished or dead prompt-run worker thread could leave session state wedged: `running` and `inflight_turn` stayed pinned forever after the worker had already exited (e.g. a dropped transport). Reconnect callers read the live payload as their authority, so a stale busy projection stranded the client on a spinner. Reconcile that impossible state in `_live_session_payload` before it is returned: if the session is marked running but its `_run_thread` has exited, clear `running` and the inflight turn. A missing thread is left untouched (other paths briefly set `running` before registering a worker). This is a standalone fix, independent of the WebSocket heartbeat wire contract (NousResearch#89958); part of the NousResearch#83166 recovery work. Receipts: scripts/run_tests.sh tests/test_tui_gateway_server.py \ -k activate_clears_stale_busy fail-before (reconcile call removed): 1 failed pass-after: 1 passed, 0 failed
This was referenced Aug 19, 2026
Contributor
Right reconciliation point and correct polarity: reconciling inside
No blocking issues found. — reviewer-b (automated review) |
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.
What does this PR do?
When a prompt-run worker thread finishes (or dies) but its session still has
running: Trueand a stale_run_threadreference, the next activation of that session can see it as busy and refuse to dispatch. This reconciles that state at session activation: if the recorded run thread is no longer alive, the inflight-turn state is cleared so the session is usable again.This is a standalone, self-contained piece of the WebSocket-recovery work in #83166 — it has no dependency on the heartbeat wire contract (#89958) or the transport-ownership machinery, so it's filed on its own.
Related Issue
Part of the recovery work in #83166.
Type of Change
Changes Made
tui_gateway/server.py—_reconcile_finished_run_thread(session)helper (clears inflight state when_run_threadis no longer alive), called from_live_session_payload.tests/test_tui_gateway_server.py— one test that activating a session with a dead run thread clears the stale busy state.How to Test
Fail-before (reconcile call removed): 1 failed (session still reports
running). Pass-after: 1 passed.Checklist
Code
Documentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/ASalvage-friendly: single commit on current main (
13ce0c5c67), no dependencies — cherry-pick welcome, authorship preservation appreciated but optional.