fix(tui_gateway): let completed Desktop sessions run refine - #83520
fangliquanflq wants to merge 2 commits into
Conversation
|
Note for reviewers / @thatssoheil: the complementary messaging-gateway cold-cache case you called out is tracked separately in #83871 and fixed in #83872, so this PR stays focused on the Desktop/TUI |
fix(tui_gateway): let completed Desktop sessions run refine
|
|
Thanks for the review. I checked each point against the current PR head and the compute-host lifecycle:
Focused verification on
No code changes were made. |
Review: PR #83520Summary: Fixes #83455 correctly on the reported surface (Desktop/TUI via Tests: 3 new regression tests pass locally ( Standards axis: No hard violations. One undocumented but real Duplicated Code smell — the refine-start chain is now the third near-verbatim copy ( Spec axis: Implements the issue's preferred option 1 (persisted transcript fallback). Two minor corner-case divergences from sibling paths:
All three AI-review points rebutted correctly — especially the ping-pong recursion concern (#1), which cannot happen because Verdict: Merge-worthy. Suggested follow-up: extract the review-start logic into a shared utility used by CLI, messaging gateway, and TUI gateway. |
|
Thanks for the detailed review. I rechecked the current head (
No code changes were made. The focused persisted-history and compute-host routing tests are present on this head, and GitHub currently reports the PR mergeable with all required checks passing. |
|
Independent confirmation on Desktop / Linux (v0.20.5, upstream Reproduced today with a session holding 169 persisted messages ( One addition to the RCA that may help review: on the Desktop surface the failing command demonstrably runs in a separate slash-worker subprocess, not the backend process that owns the warm agents. From The process that served Impact scoping: automatic post-turn background reviews keep working (they fire inside the process that owns the agent), so this breaks only the manual |
|
Thank you for the independent Desktop/Linux confirmation. This is informational and requires no additional code change: the separate slash-worker process with no resident Revalidated on
No code changes were needed. |
|
Cross-link from another install: we hit the same bug on Linux (Desktop app + TUI gateway, session reattached from disk after a restart) and opened #109934 — a fresh implementation of this same fix on top of current Two reasons for a separate branch rather than a rebase of this one:
Credit for the approach is yours in the #109934 description. Two details we found we needed on top of it, in case they're useful here too:
If you'd rather land it here, take anything you need — no hard feelings about closing #109934 in favour of a rebase of this PR. |
What does this PR do?
Desktop and TUI sessions can now run
/refineagainst a completed conversation even when the isolated slash-command worker has no cached agent. The command stays with the session owner, reads the canonical persisted transcript, and preserves the review focus instead of incorrectly reporting that there is nothing to refine.Symptom
A Desktop session with completed, persisted turns can return
Nothing to refine yet - send a message first.when the user invokes/refineafter the agent is idle.Impact
Affected Desktop and TUI users cannot refine an existing conversation even though its transcript remains visible and durable. The command ignores usable session history and the requested background review never starts.
Bug Cause
Trigger:
tui_gateway/methods_tools.py/slash.execdispatch for/refineCausal chain:
/refinethrough the TUI gateway'sslash.execpath.refinewas not a live-session command, dispatch selected an isolatedHermesCLIslash worker that did not own the active session agent or its persisted transcript.Why it is wrong: Session ownership and durable conversation state live in the gateway process or its compute host, not in the isolated slash worker. Cache absence in that worker does not mean the conversation is empty.
Working sibling / contrast: Other live session commands already execute against the gateway-owned session. The messaging gateway's
/refinepath has its own valid agent cache and is not routed through this isolated Desktop/TUI seam.Ruled out: An actually empty conversation was ruled out because the regression test supplies persisted user and assistant turns and verifies that they are selected over stale in-memory history.
Fix
Route
/refineas an idle-gated live-session command. The gateway now snapshots the persisted transcript including ancestor messages, falls back to locked live history when needed, and starts the review on the owning agent. Turn-isolated sessions forward the command to the compute host so the process that owns the live agent performs the same operation.Related Issue
Closes #83455
Type of Change
Changes Made
tui_gateway/server.py- handle/refineon the live session, load durable history, and forward compute-host-owned sessions.tui_gateway/compute_host.py- execute forwarded refine requests on the host-owned agent.tui_gateway/host_supervisor.py- register refine as an idle-gated mutator route.tests/test_tui_gateway_server.py- cover persisted-history recovery and compute-host forwarding without isolated worker creation.tests/tui_gateway/test_compute_host_phase1.py- cover host-owned review startup and route classification.How to Test
Automated tests already run locally on Windows:
Results: 534 gateway server tests passed, 3 refine focus tests passed, and 8 compute-host tests passed. One unrelated pre-existing Windows
O_APPENDtest in the compute-host file still fails; the focused refine and route tests passed.Checklist