Repository navigation
zmx attach client drops a session's last output when the session ends #998
alexandru-savinov
started this conversation in
General
Replies: 1 comment
|
yes, a PR is welcome. It reproduces here with the 0.42.3 zmx: I'd change the shape a bit:
The client code is the same on upstream zmx main, and upstream took the matching daemon-side input fix in neurosnap/zmx@0a18bee, so sending it to neurosnap/zmx as well makes sense. Here it can go in as 0007 meanwhile. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'd like to propose a small fix in the bundled zmx: the attach client should finish writing a session's output before it exits when the session ends.
What happens. In the released macOS app, a session whose command prints and then exits can lose the end of its output. The terminal sees the start of the output, but not the last lines. It happens when the terminal is briefly not reading at the moment the session ends (a busy pane), and sometimes without that.
Build under test. agterm 0.42.3 (
agterm-0.42.3.dmgfrom the v0.42.3 release, sha25633062c5c…ed9d09), its bundledagterm.app/Contents/MacOS/zmx(zmx version: 0.8.1, sha25642f76cec…aa68bf), zmx rev8bab1f0. Hosted GitHub runner, macOS 26.7.2 (25G332), arm64.Repro. The script below runs
zmx attach <name> /bin/sh -c '<command>'under a pty, with a freshZMX_DIR. The command sleeps 0.3 s, printsDRAIN-START-MARK, prints N bytes of filler in 100-column lines, printsDRAIN-FINAL-MARK, and exits. The script reads the pty master to EOF and counts a run as lost when the start mark arrived and the final mark did not. Reader modes:fast: reads as fast as it can.stall: reads fast, but stops reading for 0.5 s once the start mark arrives, then reads fast to EOF.slow: reads 1 KiB at a time with a 2 ms pause, for a terminal that stays far behind.The reader is a pty in a Python script, not the app's terminal view. I have not shown the loss inside the app itself.
Results, 30 runs each, lost runs out of 30. Arm A is the 0.42.3 release binary. Arm B is v0.42.3 source (
0a84471) built with its ownscripts/setup.sh --zmx-onlyand its own patches 0001–0006, plus one added patch (below).The last two rows are the limit of the proposal, on purpose: the patch spends at most 2 s and 1 MiB on the remaining output, so a terminal that stays behind for longer still loses the tail. The patch does not try to fix that case.
Cause. In zmx's attach client loop (
src/loop.zigat 8bab1f0), one pass reads at most one buffer from the daemon socket and does one write to stdout. Then it returns as soon as the socket reports a hangup (L210–213), or when a read returns 0 (L146–149). Output the client has read but not yet written, and output still queued behind the hangup, is dropped.Proposed scope, kept small, as one more file in
scripts/zmx-patches/:finishSessionloop before returning. It reads the socket until EOF and writes the buffered output to stdout, both nonblocking. It is bounded by an absolute 2 s deadline and 1 MiB read from the socket, so a terminal that stopped reading cannot hold the client.We carry this patch in a downstream fork, where it fixed a flaky end-of-output test on Linux. Arm B above is that same patch applied unchanged after your 0001–0006, built by your
setup.sh, and itszig build teststep passed. Before sending a PR I would also runmake build,make test,make test-appandmake lint, and add the repro as a test if you want one.Would a PR like this be welcome? Or would you rather handle it differently, or upstream in zmx?
I'm following the discussion-first process; no upstream PR has been opened.
zmx-drain-repro.py
This investigation and proposal were prepared with AI assistance (Claude); I reviewed them. If you agree, I will open a PR with tests.
All reactions