fix(cmux-tui-core): the reader's end, give-up and the owner's detach end the input port's reconnect wait (R-DAEMON-STATE S1.6c)
Summary
R-DAEMON-STATE stage S1 step 6c, part 1 (handoff/rewrites/R-DAEMON-STATE/DESIGN.md, section 3). It was stacked on #35082 (S1.6b), which landed as 65d098cc113; the branch now merges that squash and feat ca738232f32, with its own diff unchanged (patch id 66e943183f3e against the feat tip). Behind the per-mux switch CMUX_TUI_RDS_INPUT (default off). Review 2 of #35082 asked for this fix before S1.7 turns the switch on.
The defect. Since #35082 review 1, the input port's writer waits for a reconnect on its own route epoch, so a route publication ends the wait at once. But the reader's other wakes (it ended, it gave the host up, a reconnect completion failed) and the owner's detach still only notified stream_progress, which the writer no longer waits on. So a Written write (a script's cmux send, a resource input effect) behind a host that will not come back failed only at its own reconnect deadline, 5 s later. The old path, and S1.6b before review 1, failed it at once.
The fix.
InputPort::reconnect_endedmoves the port's route epoch with no new route. The writer then checks the route and the terminal's state again and fails its frame: aFailedlink, an ended reader, or a detaching owner.PtyTerminalRuntime::reader_gave_upnotifies the stream and ends the port's wait. It is called at the three reader points:WakeInputOnReaderEnd, the give-up inwait_or_fail, and a failed reconnect completion.- The four
owner_detachingstores inshutdown.rsend the port's wait. That takes the port lock under the runtime lock, which is safe because the port lock is a leaf: no holder of it waits for another lock. The stream notify is not added there.
The person's keys (InputReply::Accepted) do not wait for any write, so this changes only when other writers learn of the failure.
Testing
Focused command: ./scripts/verify-cmux-tui-hosted.sh --filter a_write_waiting_for_a_reconnect_fails_when_the_reader_gives_up (Linux test (linux)).
- Red at b6b0b37f3b0, run https://github.com/manaflow-ai/cmux/actions/runs/41814676634: FAILED ("a write to a host the reader gave up on waited 5.000142216s, its reconnect deadline, not the give-up").
- Green at 860edd9053e, run https://github.com/manaflow-ai/cmux/actions/runs/41814947127: passed.
--filter hostedat 860edd9053e, run https://github.com/manaflow-ai/cmux/actions/runs/41814956814: 69 passed, 0 failed.- Then 1e84ed39d8d merged feat d1decc7c447, which has #35222 (the
cmux-cloud-environmentclippy fix), solint (linux)can check this crate again. Run https://github.com/manaflow-ai/cmux/actions/runs/41817024458 at 1e84ed39d8d:test (linux)69 passed, 0 failed. Itslint (linux)checked cmux-tui-core with no error; it is red only in thecmux-tuicrate, which this PR does not change:cmux-tui/src/cloud_environment.rs:22(needless borrow, from #35133) and the panic ratchetcmux-tuiindexing_slicing 841 > 831 (frontend_journal.rs, frame_geometry.rs, agent_browser_provider.rs, ...). Own-diff patch-id unchanged (66e943183f3e).
Compile: fleet job 5ba29eeee3ae225fb683cfb0 at the head 32f0563d491: CmuxNext, app and cmux-tui passed. Before that, job 2106afc90bf8ca0497254bad at 1e84ed39d8d passed. (Job bf827818dd60d90f91e018a2 at 860edd9053e failed only on the relaunch.rs base red from #35133, which that commit predates; #35172 fixed it on feat.)
Observed / Not run
- Observed: the hosted runs above.
cmux-tui-core/srcis the same at the head 32f0563d491 as at 1e84ed39d8d (the cascade after #35082 changed no file there). A--filter hostedrun at the head: https://github.com/manaflow-ai/cmux/actions/runs/41825140915. - The call-site tests that #35280 review 1 asked for (the reader's real backoff give-up and the daemon's shutdown detach) are in S1.6c part 2, not here. Red on this fix's parent at 19e10238b8c, run https://github.com/manaflow-ai/cmux/actions/runs/41820912843: all three FAILED, each write waited its 5 s reconnect deadline.
- At 860edd9053e,
lint (linux)was red on the base findingcmux-cloud-environment/src/lib.rs:262(collapsible_if from #35133). cmux-tui-core depends on that crate through cmux-tui-cloud-conversations, so clippy never reached this PR's code there; the run at 1e84ed39d8d checks it. - Not run: macOS execution of the focused tests; a typing A/B (the change is on the failure path of other writers only).
Changelog
none
Proof
No capture: daemon-only change behind a default-off switch, no UI.
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes the input port's reconnect wait so a Written write fails at once when the reader ends, gives the host up, or the owner detaches, instead of waiting out its full 5 s reconnect deadline.
Since #35082 review 1 the writer waits on its own route epoch, and those wakes still only notified stream_progress. Now InputPort::reconnect_ended moves the route epoch with no new route; the writer checks the route and terminal state again and fails its frame (a Failed link, an ended reader, or a detaching owner). PtyTerminalRuntime::reader_gave_up covers the three reader wakes, and the four owner_detaching stores in shutdown.rs also end the port's wait, taking only the port lock.
Behind the per-mux switch CMUX_TUI_RDS_INPUT (default off). Covered by a_write_waiting_for_a_reconnect_fails_when_the_reader_gives_up in surface/tests/hosted.rs.