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)

LA
2d ago
+69-6

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_ended moves 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: a Failed link, an ended reader, or a detaching owner.
  • PtyTerminalRuntime::reader_gave_up notifies the stream and ends the port's wait. It is called at the three reader points: WakeInputOnReaderEnd, the give-up in wait_or_fail, and a failed reconnect completion.
  • The four owner_detaching stores in shutdown.rs end 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)).

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/src is the same at the head 32f0563d491 as at 1e84ed39d8d (the cascade after #35082 changed no file there). A --filter hosted run 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 finding cmux-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
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.