fix(cmux NEXT agent pane): a failed screencapture is an error, not an Esc (carries part of #20827)
Carries the AgentPaneCapture half of #20827 (Austin's error-handling audit for #20776). Those commits credit Austin with Co-authored-by, and the string and its 21 translations are his. #20827 stays open for its owner to close.
The rest of #20827 is superseded: base moved the Changes view's git runs onto AsyncProcess (92598cb8d2c, fcafb743e0e: SIGTERM at the deadline, SIGKILL after the grace, awaited without a thread), which covers its AgentPaneGitProcess deadline rewrite. Its SSHRunner change was reformatting only.
What it fixes
composer.capture (the composer's + > Attach Screenshot… / Attach Window…) counted every screencapture run that started as a pick. One that ended with an error (no Screen Recording grant, a crash) answered the page {cancelled: true}, the same as an Esc, and any partial file it wrote stayed in the temp folder.
AgentPaneCapture.capturereturns.takenor.failed(reason), and takes anexecutableseam so tests can use a stub.- With a file written, the exit status decides: 0 is the image, anything else is
.failedand the partial file is removed. (A partial file at status 0 can't be told apart from a capture.) - With no file, an end that prints nothing is an Esc (
.taken, no image), whether this macOS version exits 0 or non-zero on Esc. An end that prints why is.failed, even at status 0. - A signal is always
.failed. On.failedthe system's message is logged (agent-pane.capture) and the page getscapture.failedwith "The screen capture failed." - File operations go through
FileManager.checked(the guardrail's seam).
Test
AgentPaneCaptureTests (CmuxNextAppTests), with stub screencapture scripts:
aFailedScreencaptureIsAFailureNotACancel: prints a reason and exits 1. Expects.failed. Red at6c1f6a398d6.anErrorSaidWithStatusZeroAndNoImageIsAFailure: prints a reason, exits 0, writes no file. Expects.failed. Added after review.aFailedPickLeavesNoFile: writes a partial file and exits 1. Expects no file left. Red at6c1f6a398d6.anEscapedPickIsTakenWithNoImageandaQuietNonzeroExitWithNoImageIsACancel: an Esc under either exit convention stays a cancel. Green on both commits.
Observed / Not run
- Observed:
scripts/cmux-next/prepush-gate.py: no new violations. - Not run here: the Swift suites. This host builds no Swift, so the red at
6c1f6a398d6and the green at the head come from this PR's CI. I have not checked a realscreencaptureEsc status on macOS; the quiet-exit rule is there so either convention stays a cancel.
Risk: normal. One reply path in the agent pane; the page already treats a failed call as no attachment (App.tsx .catch(() => null)).
No capture: no visible change on success or Esc; a failed capture answers an error instead of a cancel.
Changelog
Fixed: A screenshot attach that fails no longer reads as a cancel and leaves no temporary file behind.
Agent session: agent session
🤖 Generated with Claude Code