Repository navigation
fix(session): match the terminal's shutdown signals in headless reviews - #1353
Conversation
[Medium impact] The change affects headless browser reviews and the scripts that read their output. The filename requirement must be satisfied before merging; the script example also needs non-blocking fixes. Findings
Fix with agent prompt### Issue 1
packages/hunk/src/core/process/outputClosed.ts:14
The new `outputClosed.ts` and `outputClosed.test.ts` files violate the repository directive to use dash-case for TypeScript filenames. Rename them to `output-closed.ts` and `output-closed.test.ts`, and update the imports. This repository requirement must be satisfied before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
### Issue 2
website/src/content/docs/docs/workflows/browser-review.md:34
If `TMPDIR` is unset, this redirects to `/hunk-url`. An ordinary Linux user cannot write there, so the review never starts and the following loop waits forever. Concurrent runs also share this filename and can read each other's URL. Create a unique file with `mktemp`, using `${TMPDIR:-/tmp}` if needed, and remove it when done.
### Issue 3
website/src/content/docs/docs/workflows/browser-review.md:36
Even with a writable temporary file, this loop never ends if Hunk fails before printing its URL. A daemon port conflict is one documented example: Hunk exits, but the file stays empty. Check whether `review` has exited while waiting, then use `wait` to return its failure instead of sleeping forever.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR checks for closed output readers every 500 ms and sends headless reviews through the existing shutdown path. It also adds a real-process regression test and replaces the command-substitution advice with a background script example.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Headless review prints URL] --> B[Check stdout and stderr every 500 ms]
B --> C{Pipe or socket reader gone?}
C -->|No| B
C -->|Yes| D[Stop output checks]
D --> E[Stop reloads and input watch]
E --> F[Shut down extensions]
F --> G[Stop broker client and exit]
Reviews (1) · Last reviewed commit: "fix(session): end a headless review when..." · Reviewed by Greptile |
| * `/dev/null` has no reader to lose, so those are never reported gone. Windows has no `poll` | ||
| * for pipe handles, so there a closed reader is still noticed by the next failed write only. | ||
| */ | ||
| import { fstatSync } from "node:fs"; |
There was a problem hiding this comment.
New filenames break repository rules
The new outputClosed.ts and outputClosed.test.ts files violate the repository directive to use dash-case for TypeScript filenames. Rename them to output-closed.ts and output-closed.test.ts, and update the imports. This repository requirement must be satisfied before merging.
Context Used: guidelines.mdc Cursor rule (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/core/process/outputClosed.ts
Line: 14
Comment:
**New filenames break repository rules**
The new `outputClosed.ts` and `outputClosed.test.ts` files violate the repository directive to use dash-case for TypeScript filenames. Rename them to `output-closed.ts` and `output-closed.test.ts`, and update the imports. This repository requirement must be satisfied before merging.
**Context Used:** guidelines.mdc Cursor rule ([source](https://github.com/modem-dev/modem/blob/main/.cursor/rules/guidelines.mdc))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| Start the review in the background, send its output to a file, and read the first line once it appears. Stop the review when the script is done: | ||
|
|
||
| ```bash | ||
| hunk diff --web --no-open > "$TMPDIR/hunk-url" & |
There was a problem hiding this comment.
Script shares an unreliable filename
If TMPDIR is unset, this redirects to /hunk-url. An ordinary Linux user cannot write there, so the review never starts and the following loop waits forever. Concurrent runs also share this filename and can read each other's URL. Create a unique file with mktemp, using ${TMPDIR:-/tmp} if needed, and remove it when done.
Prompt To Fix With AI
This is a comment left during a code review.
Path: website/src/content/docs/docs/workflows/browser-review.md
Line: 34
Comment:
**Script shares an unreliable filename**
If `TMPDIR` is unset, this redirects to `/hunk-url`. An ordinary Linux user cannot write there, so the review never starts and the following loop waits forever. Concurrent runs also share this filename and can read each other's URL. Create a unique file with `mktemp`, using `${TMPDIR:-/tmp}` if needed, and remove it when done.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| ```bash | ||
| hunk diff --web --no-open > "$TMPDIR/hunk-url" & | ||
| review=$! | ||
| until [ -s "$TMPDIR/hunk-url" ]; do sleep 0.1; done |
There was a problem hiding this comment.
Script hangs after startup fails
Even with a writable temporary file, this loop never ends if Hunk fails before printing its URL. A daemon port conflict is one documented example: Hunk exits, but the file stays empty. Check whether review has exited while waiting, then use wait to return its failure instead of sleeping forever.
Prompt To Fix With AI
This is a comment left during a code review.
Path: website/src/content/docs/docs/workflows/browser-review.md
Line: 36
Comment:
**Script hangs after startup fails**
Even with a writable temporary file, this loop never ends if Hunk fails before printing its URL. A daemon port conflict is one documented example: Hunk exits, but the file stays empty. Check whether `review` has exited while waiting, then use `wait` to return its failure instead of sleeping forever.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.A `--web` review now stops on the same signals as the terminal UI, SIGQUIT included, from one shared list. The browser review docs now explain why `URL=$(hunk diff --web)` never returns and show how a script reads the URL instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
2f1043d to
646bd6d
Compare
|
Reworked after review, to mirror the terminal UI. I dropped the Generated by Claude Code |
Problem
hunk diff --web --no-open | head -1keeps the review running afterheadexits.URL=$(hunk diff --web --no-open)never returns, because the review keeps running and never closes stdout.Approach
This mirrors the terminal UI instead of adding new detection. The TUI does not poll for a closed reader. It stops on signals and on EPIPE from a failed write, and the headless runner already handles EPIPE that way.
packages/hunk/src/core/process/shutdownSignals.tsholdsREVIEW_SHUTDOWN_SIGNALS, the TUI's list:runInteractiveApp.tsxandheadlessReviewRunner.tsboth use it, so the two lists cannot drift apart again. The only behavior change is that headless now also stops on SIGQUIT.browser-review.md):$(...)never returns.kill(a background job in a non-interactive shell ignores SIGINT, sokill -INTwould not stop it).hunk session open --repo . --no-openfor a review that is already running.| head -1the review ends on a signal or at its next write to the closed pipe, as with the terminal UI.Non-goals: detecting a closed reader without a write. An earlier version of this PR polled with
bun:ffi; that was dropped to match the TUI.Tests and checks (Linux only)
bun test packages/hunk/src/app/session/headlessReviewRunner.test.ts packages/hunk/src/ui/runInteractiveApp*: 25 passbun test test/cli/web-entry-points.test.ts test/session/headless.test.ts: 14 passbun run typecheck,bun run lint,bun run format:check,bun run deps:check: cleankillended the review with exit code 0.Known limitations
| head -1still leaves the review running until a signal or its next write. That is the documented behavior, matching the TUI.headlessReviewRunner.ts, as fix(web): refuse oversized reviews instead of printing a dead link #1351 does, so it may need a trivial rebase after fix(web): refuse oversized reviews instead of printing a dead link #1351.https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
Generated by Claude Code