Repository navigation
fix(native): keep redirected output when an authored command writes nothing to a stream (HACK-2744) - #1283
Conversation
…HACK-2739) An authored project's `hack exec` sent its request straight to the owner, whose only lease wait was 15 s inside a fixed 30 s budget on its only loop. During another project's 30 s stop it expired and the CLI reported the command as unconfirmed, although nothing ran. The requesting process (`graph native exec`) now waits up to COMMAND_REQUEST_LEASE_WAIT (35 s) for a free lease before it sends anything, through the shared lease-wait loop, so it prints the same single progress line and, on expiry, the raw provider_busy naming the holder. The wait is a bare lock attempt, released at once, so the uncontended path adds one flock. The owner keeps its 15 s wait; if another holder took the lease in between, it answers graph_authored_exec_lease_busy before any effect. The CLI reports both as "nothing ran" with the holder and a retry step, releases a background command's admission slot, and keeps "unconfirmed" for every other failure. The frontend bound is 85 s. ExecStopWait.tla gains an owner-side bound and a no-wait control for the authored path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…2739) Review round 1 on #1278: - The owner's pre-effect refusal now reports its wire code in the CLI detail: native_graph_foreground caused by graph_authored_exec_lease_busy, not a synthesized provider_busy. - await_free_command_lease's comment says what the code does: it does not read the pool record, so while a runtime down or cold start holds the lock it waits up to 35 s and may refuse provider_busy (honest and bounded) instead of reaching the owner's runtime_not_running. - ExecStopWait.tla and COVERAGE.md say that PeerTake is enabled only between the two waits, so a second holder during the requester's own wait is not modelled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…exec-waits-out-stop
…run (HACK-2744) An authored exec or one-off run wrote its captured streams with Bun.write(Bun.stdout, bytes) and Bun.write(Bun.stderr, bytes). Bun.write with an empty payload truncates a regular-file destination to zero bytes, even one opened for append. So a command with no stderr erased a `>> log 2>&1` file (its earlier content and the command's stdout), and an empty stream erased its own redirect file (`>> out`, `2>> err`). The Compose exec writes with process.stdout.write and was not affected. An empty stream now writes nothing. A regression test points a worker's real stdout and stderr at files, with append, truncate and shared redirects, through the stream writer and through the authored exec dispatch; without the fix six of its cases fail with an emptied file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
… (HACK-2744) The time-bounded stale-env test expected the authored exec to write its empty stderr, which is the write that truncated a redirected file. With the fix it writes only the command's stdout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Resolved to the tree tested in batch run m3:z495 (lead train sync). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes HACK-2744.
Problem
In an authored project (
hack.project.json), redirectinghack execorhack runoutput to a regular file could empty that file. Earlier content was lost, and so was the command's own output:hack exec worker -- echo hello >> out.txt 2>&1, run on a file with an existing line, exits 0 and leaves the file empty.hack exec worker -- true >> out.txtempties the file.hack exec worker -- echo hello 2>> err.txt > /dev/nullemptieserr.txt.Through a pipe or a pty, the output came through as expected. Compose projects were not affected.
Root cause
src/lib/native-authored-command.ts(runAuthoredCommand) writes the command's captured streams withBun.write(Bun.stdout, bytes)and thenBun.write(Bun.stderr, bytes). In Bun (1.4.4, the pinned version),Bun.writewith an empty payload truncates a regular-file destination to 0 bytes, even when the file was opened for append. A two-line script reproduces it outside Hack. So any stream with no output erased the file it was redirected to:>> log 2>&1file: its earlier lines, and the stdout written just before.>> out.txt.2>> err.txt.Compose exec writes with
process.stdout.write, which is why it was not affected. Authored one-offhack rungoes through the same function, so it had the same bug. The cause is Bun's behaviour; HACK-2747 tracks it separately.Behaviour
writeNativeCommandStreamwrites nothing when a stream is empty. A non-empty stream is written as before, at the file's current position, so>,>>and2>&1behave as they do for any other command.hack execand authoredhack run.docs/guides/native-candidate.mdgains one sentence: redirected output is written like any other command's output, and a stream with no output leaves its file untouched.Evidence
Local (macOS arm64, Bun 1.4.4):
tests/native-authored-exec-output-file.test.ts: a worker process's real stdout and stderr point at files, with append, truncate and shared (2>&1) redirects. Each case runs once through the stream writer (on every platform) and once through the authoredhack execdispatch (macOS). With the fix, all 12 cases pass. Without it, 8 fail with an emptied file.native-authored-exec-output-file,native-authored-command,native-authored-project-exec,native-authored-project-oneoff, 203 passed.bun run typecheckandbun run check,docs:prepareanddocs:check,privacy:checkafter staging, gitleaks.nextat cd2e21f: typecheck, check, the same tests, privacy and gitleaks again.Real VM (Apple Silicon), fresh isolated homes, an authored busybox
worker, at10018b5f(this fix before the merge ofnext). The control isnextatcc8db3a9:next(control)exec … -- echo hello > out.txt, stderr on a terminalout.txtholdshello(6 bytes)exec … -- echo hello >> out.txt 2>&1, file has an existing linehelloexec … -- echo hello 2>> err.txt > /dev/null, nothing on stderr, file has an existing lineexec … -- true >> out.txt, file has an existing linehack run worker sh -c 'echo hello' >> out.txt 2>&1, file has an existing lineRow 1 passes on both heads: when stdout is a file and stderr is a terminal, the file receives its output. Every failing row on
nextsends an empty write to a regular file. There is no second cause.Not run: the full suite, Linux (this change is TypeScript only; the stream-writer cases run on every platform in CI).
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.