Skip to content

fix(zmx): run a fresh live command as a create-only payload - #533

Merged
umputun merged 4 commits into
masterfrom
zmx-command-truncation
Sep 2, 2026
Merged

umputun merged 4 commits into
masterfrom
zmx-command-truncation

Conversation

@umputun

@umputun umputun commented Sep 2, 2026

Copy link
Copy Markdown
Owner

a session new --command longer than 1024 bytes is silently truncated and never submitted in 0.26.0, so every scheduled auto-review sits at a shell prompt holding a half-typed prompt.

what happens

a freshly created live pane took its command through libghostty initial_input. The zmx attach client forwards that into its outer pty before it switches the pty to raw mode, and macOS keeps only MAX_CANON (1024) bytes in the canonical line buffer. The tail is dropped along with the trailing newline, so the command arrives incomplete and unsubmitted. Reproduced with forkpty: a 2049-byte write returns 2049, exactly 1024 survive, no newline.

the route came in with a0af4086, which added || backedByZmx to the initial_input guard. Before that a --command was exec'd as the surface process with no length limit.

the fix

pass a fresh pane's command through zmx's create-only argv path, the route a restored pane already used, and drop the backedByZmx exception. A surviving daemon ignores the payload and a new one runs it, so it still runs exactly once. This bypasses the 1024-byte pty cap, though ARG_MAX still bounds it.

a fresh split pane now gets its command this way too. It previously got neither initialInput (primary only) nor creationCommand (restored only), so in live mode it ran nothing at all.

verified

isolated instance in live mode, a 2092-byte command, marker written once. 2947 host-free tests, strict SwiftLint, and the live UI test with a 2048-byte payload asserting exactly-once.

also here

ZmxLiveUITests teardown killed daemons by running zmx from the XCUITest runner, which cannot signal what the app spawned, so zmx returned PermissionDenied and every run leaked its daemons. It now reaps through the app's own zmx.kill, refusing to act unless the inventory is complete and the endpoint is the test's own namespace, and never the default one. Unreapable rows are reported rather than filtered out of both passes.

a fresh live pane took its --command through libghostty initial_input, which the zmx attach client forwards into its outer pty before it switches that pty to raw mode. macOS keeps 1024 bytes in the canonical line buffer and drops the rest, so a command over that size arrived truncated and without its trailing newline, and sat unsubmitted at the shell prompt. Pass the durable command through zmx's create-only argv path instead, the route a restored pane already took. A fresh split pane now gets its command the same way, where before it got none at all.
ZmxLiveUITests killed its daemons by running zmx from the test runner, which cannot signal processes the app spawned, and zmx reports that kill(2) EPERM as PermissionDenied, so teardown threw and every run leaked its daemons. Reap through the app's own zmx.kill before terminating it, and refuse to act unless the inventory is complete, the endpoint is this test's own namespace, and every running row is a claimed pane. The namespace guard also rejects the default state directory, so a wrong stateDir cannot reach real sessions.

session.close is not a substitute: paneFinalizer discards the kill result, so it can drop the model while the daemon survives.
the teardown kept only rows observed running, so an unresponsive daemon reporting unreadable was neither killed nor counted afterwards and the cleanup passed while it survived. The post-kill poll also demanded a claim, which applyKilledPaneExit removes synchronously, so it threw on the first call and the grace period it exists for was unreachable.

Parse the guarded inventory into typed rows and project it twice. Before the kill, act only on running and claimed rows with complete addressing, since killRefusal rejects an unreadable row outright, and collect each refusal rather than stopping at the first. After the kill, count every running or unreadable row whatever its claim, and name what is left when the deadline passes.

The kill-ordering comment claimed a relationship between the two daemons that does not exist. The order is needed because closePrimaryPane assigns paneIdentity from splitPaneIdentity, so a right entry captured before that stops resolving.

Also correct commands.html and the skill reference, which described --command as argv-style with no shell without saying live mode now runs it through a login shell.
Copilot AI lite review requested due to automatic review settings September 2, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Documentation updates introduce an internal inconsistency around PATH semantics in Live mode, and the UI test daemon-inventory parsing should fail closed rather than silently defaulting required fields.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes Live-mode session new --command execution for zmx-backed panes by routing the command through zmx’s create-only payload path (avoiding the 1,024-byte PTY canonical-input truncation) and removing the prior initial_input exception behavior. This aligns fresh and restored live panes to the same “payload-on-create, ignored-on-reattach” mechanism and adds coverage for split panes plus improved daemon cleanup in UI tests.

Changes:

  • Switch zmx-wrapped pane bootstrapping from libghostty initial_input to zmx create-only payloads (primary + split).
  • Update UI + unit tests to assert long command payloads run exactly once and improve live-daemon cleanup behavior.
  • Refresh user/docs + installed skill reference text to describe the new Live-mode behavior.
File summaries
File Description
agterm/Ghostty/ZmxLaunch.swift Routes fresh-pane commands via creationCommand (create-only payload) and stops emitting initialInput for zmx-backed panes.
agterm/Ghostty/GhosttySurfaceView.swift Removes the backedByZmx exception so initial_input is only set when there is no command.
agterm/Ghostty/LaunchSeed.swift Updates LaunchSeed documentation to reflect strict command/initialInput exclusivity.
agtermTests/SurfaceFactorySeedTests.swift Updates/extends unit coverage to assert create-only payload usage for primary and split wrapped panes.
agtermUITests/ZmxLiveUITests.swift Adds long-payload e2e assertion and reworks teardown cleanup to reap via the app’s zmx.kill.
site/docs.html Documents Live-mode session new --command as a create-only zmx payload, bypassing the PTY input cap.
site/commands.html Documents Live-mode --command semantics (shell evaluation via zmx payload).
plugins/agterm/skills/agterm/SKILL.md Updates installed skill docs to match the new Live-mode create-only payload behavior.
plugins/agterm/skills/agterm/reference.md Updates command reference text to match the new Live-mode create-only payload behavior.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread agtermUITests/ZmxLiveUITests.swift Outdated
Comment on lines +136 to +142
return (zmx["entries"] as? [[String: Any]] ?? []).map { entry in
DaemonRow(daemon: entry["daemon"] as? String ?? "?",
observation: entry["observation"] as? String ?? "",
state: entry["state"] as? String ?? "",
sessionID: entry["sessionID"] as? String,
pane: entry["pane"] as? String)
}
Comment on lines 353 to 356
exits). It runs argv-style (tokenized, quotes respected, but NO shell), so shell operators (`;`,
`&&`, `$VAR`, redirects, globs) are not interpreted, and it inherits the app's GUI `PATH` (the launchd
`&&`, `$VAR`, redirects, globs) are not interpreted. In Live sessions mode it is a create-only zmx
payload run through a login shell instead, so shell operators do work there. It inherits the app's GUI `PATH` (the launchd
default — no `/opt/homebrew/bin`), so a bare Homebrew or other non-default binary fails with exit 127.
Comment thread site/commands.html Outdated
Comment on lines 909 to 913
In <em>Live sessions</em> mode the command is a create-only zmx payload run through a login shell instead, so
shell operators do work there.
It also inherits the app's GUI
<span style="font-family: &quot;JetBrains Mono&quot;, monospace">PATH</span> (the launchd default — no
<span style="font-family: &quot;JetBrains Mono&quot;, monospace">/opt/homebrew/bin</span>), so a bare Homebrew binary
the teardown built each row with defaults, so a missing observation key read as not alive and dropped the daemon from both the kill pass and the remaining count, and a changed entries shape made the whole inventory read as empty while cleanup reported success. Parse observation and state through enums mirroring the model instead, so a renamed value fails the reap rather than passing it, require entries and the three string fields, and throw at once on a claimed row carrying no sessionID or pane rather than waiting out the grace period.

The live-mode note in commands.html and the skill reference contradicted the sentences around it, which still said the command replaces the login shell, closes the session on exit, inherits the launchd PATH, and wants wrapping. State those as Fresh shells and Re-run commands, then give the live exception once.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Deploying agterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 668cdbc
Status: ✅  Deploy successful!
Preview URL: https://3e664451.agterm.pages.dev
Branch Preview URL: https://zmx-command-truncation.agterm.pages.dev

View logs

@umputun
umputun merged commit 0e8067d into master Sep 2, 2026
8 checks passed
@umputun
umputun deleted the zmx-command-truncation branch September 2, 2026 18:29
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.

2 participants