Skip to content

fix(tui): clear the reconnection failure when a reconnect attaches - #3988

Open
snimu wants to merge 2 commits into
mainfrom
sebastian/tui-reconnect-failed-sticky
Open

snimu wants to merge 2 commits into
mainfrom
sebastian/tui-reconnect-failed-sticky

Conversation

@snimu

@snimu snimu commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

After the session re-attach window expired, a later successful reconnect still left every submit blocked with "Daemon reconnection failed". This PR clears that failure on every successful attach.

Bug

When the direct worker link dies, the session-plane driver retries the attach for a fixed 1-minute window. When the window expires, it sets SessionUi.reconnection_failed, and send_prompt refuses every submit while that is set. Only a later session-plane success cleared it.

These paths attach a healthy connection but never cleared the flag:

  • a full reconnect (lost link, shutdown, or update recovery)
  • /switch and /new
  • a session_binding rebind

So after any of them, every submit was still refused.

Fix

attach_session now clears reconnection_failed next to daemon_closing_notice. Both are per-connection state. Every successful attach goes through attach_session, including the session-plane driver and the recovery reattach. Because of that, the separate clear in the session-plane success arm (run.rs) is deleted. One comment in reconnect.rs named this bug as a reason for the shutdown yield rule; that clause is removed.

Test

New unit test an_attach_clears_the_reconnection_failure in session_ui/lifecycle.rs. It sits on the layer that owns the flag and reuses the module's existing mock_session helper. The test sets reconnection_failed, calls attach_session against the mock daemon, and asserts the flag is None.

Mutation check (Prime sandbox): with the new self.reconnection_failed = None; line removed from attach_session, the test fails:

panicked at crates/pa-tui/src/session_ui/lifecycle.rs:977:13:
  left: Some("the session worker is gone")
 right: None

An earlier revision of this PR had a minute-long headless e2e. It drove the full path: direct link lost, the window expires, full reconnect, then a submit. On main, that e2e showed the submit refused after the reconnect:

 Daemon restarted (v0.10.2) - reconnected
 ⚠ Error: Daemon reconnection failed: the daemon rejected the attach request: the session worker is gone
 >  hello

It was replaced by the unit test above to keep the suite fast.

Validation

All green in a Prime sandbox with toolchain 1.98.1:

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test -p pa-tui --no-fail-fast
  • cargo build -p pa-cli

Overlap

#3893, #3424 and #3650 touch run.rs, session_ui.rs and lifecycle.rs; #3825 touches run.rs. The production change here is one added line in attach_session and one deleted line in run.rs, so conflicts should be trivial.


Note

Low Risk
Small lifecycle/state-reset change on the attach path; no new networking or auth behavior, with a targeted unit test.

Overview
Fixes prompts staying blocked with "Daemon reconnection failed" after the TUI had already reattached to a healthy daemon.

Previously reconnection_failed was only cleared on one session-plane reconnect success path in run.rs, even though other recoveries (attach_session, shutdown/lost reconnect, /switch, rebind) also established a live connection. attach_session now clears reconnection_failed with daemon_closing_notice on every successful attach, and the redundant clear in the reconnect success arm is removed.

Docs/comments in session_ui and reconnect.rs reflect that this flag is per-connection. A focused unit test asserts an attach wipes a preset failure state.

Reviewed by Cursor Bugbot for commit 5fb51fc. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Clear SessionUi.reconnection_failed in attach_session instead of reconnect handling

The TUI could keep showing "Daemon reconnection failed" and block submits even after a later reconnect succeeded, because the failure marker was only cleared in one branch of the reconnect flow.

  • Moves the clearing of reconnection_failed to SessionUi.attach_session in lifecycle.rs, so every successful attach clears it after reconstructed session state is applied.
  • Removes the old clearing from the successful-reconnect branch in run.rs after transcript resynchronization.
  • Adds a regression test (an_attach_clears_the_reconnection_failure) and a release note in .changes/tui-reconnect-failed-sticky.md.

Macroscope summarized 5fb51fc.

snimu added 2 commits November 7, 2026 17:03
An expired session-plane re-attach window set `reconnection_failed`, and only a
later session-plane success cleared it. A full reconnect, /switch, /new or a
session_binding rebind attached a healthy connection but left every submit
refused with "Daemon reconnection failed". The flag is per-connection, so
attach_session now clears it beside `daemon_closing_notice`; the session-plane
arm's own clear is gone.
Replace the minute-long headless e2e and its direct-link mock helpers with an
in-crate test on the layer that owns the flag: attach_session against the
existing mock session must clear reconnection_failed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant