Repository navigation
fix(web): refuse oversized reviews instead of printing a dead link - #1351
Conversation
The session daemon refuses a registration over its per-session bounds (files, catalog resources, frame size, retained bytes) after the signed hello, by closing the socket. `--web` printed its URL at the hello, so a large review got a link that never loaded and no error. `--web` now measures the registration against the daemon's bounds before waiting and exits 1 with the file count, an estimate of what fits, and a `-- <pathspec>` remedy. Past that, it prints the URL only once the daemon serves the review's publication to the link's capability. The broker client treats post-hello 1009/1013 closes of an oversized session as registration rejections, so a terminal review shows the rejection notice instead of silently resending the payload every few seconds. The page's unauthorized message now also covers a stopped or refused review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
[Medium impact] The changes affect local browser-review startup and terminal session connections. Fix the unfinished probe request and snapshot recovery before merging. FindingsFix with agent prompt### Issue 1
packages/hunk/src/app/session/headlessReviewRunner.ts:114-117
If the daemon stops answering after the signed hello, the registration deadline throws but leaves this `fetch` running. Cleanup only stops future polls, and the CLI error handler only sets `process.exitCode`. The open request can therefore keep the command alive past its six-second bound.
Pass an abort signal to the probe and abort it when the wait ends.
### Issue 2
packages/hunk/src/session/broker/brokerClient.ts:550-552
The new size-rejection branch puts oversized snapshots into the permanent `payload` wait. A terminal review near the byte limit can cross it when notes are added. Removing those notes later sends a smaller snapshot through `updateSnapshot`, but that method never releases the wait. Browser and session access stay broken even after the review fits again.
Recheck admission when a snapshot changes and release a size-based wait once the current pair fits.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR refuses oversized browser reviews before printing a URL and waits for the daemon to serve the publication.
Acknowledged by Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Create review] --> B{Fits per-session limits?}
B -->|No| C[Exit with size and remedy]
B -->|Yes| D[Wait for signed hello]
D --> E[Request publication with review key]
E -->|Served| F[Print URL and keep serving]
E -->|Not ready| E
E -->|Refused or deadline reached| G[Stop review and report error]
Reviews (1) · Last reviewed commit: "fix(web): refuse oversized reviews inste..." · Reviewed by Greptile |
| const response = await fetch( | ||
| `${httpOrigin}${reviewHttpPath({ kind: "publication", sessionId })}`, | ||
| { headers: { [HUNK_REVIEW_CAPABILITY_HEADER]: reviewProcessCapability().token } }, | ||
| ); |
There was a problem hiding this comment.
If the daemon stops answering after the signed hello, the registration deadline throws but leaves this fetch running. Cleanup only stops future polls, and the CLI error handler only sets process.exitCode. The open request can therefore keep the command alive past its six-second bound.
Pass an abort signal to the probe and abort it when the wait ends.
Knowledge Base Used: Session management
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/app/session/headlessReviewRunner.ts
Line: 114-117
Comment:
**Timeout does not end command**
If the daemon stops answering after the signed hello, the registration deadline throws but leaves this `fetch` running. Cleanup only stops future polls, and the CLI error handler only sets `process.exitCode`. The open request can therefore keep the command alive past its six-second bound.
Pass an abort signal to the probe and abort it when the wait ends.
**Knowledge Base Used:** [Session management](https://app.greptile.com/-/switch-tenant?tenant=modem&next=%2Fcustom-context%2Fknowledge-base%2Fmodem-dev%2Fhunk%2F-%2Fdocs%2Fsession-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Fixed in 4935c05: the probe now takes an AbortSignal that waitForDaemonRegistration aborts in its finally, so the request in flight ends with the wait. New test: "ends a hanging review request when the registration bound runs out" (a probe that never answers until aborted; the run exits at the bound with the signal aborted).
Generated by Claude Code
| isOversizedRegistrationRejection(event, () => | ||
| assessSessionRegistration(this.registration, this.snapshot), | ||
| ) |
There was a problem hiding this comment.
Smaller snapshots stay disconnected
The new size-rejection branch puts oversized snapshots into the permanent payload wait. A terminal review near the byte limit can cross it when notes are added. Removing those notes later sends a smaller snapshot through updateSnapshot, but that method never releases the wait. Browser and session access stay broken even after the review fits again.
Recheck admission when a snapshot changes and release a size-based wait once the current pair fits.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/session/broker/brokerClient.ts
Line: 550-552
Comment:
**Smaller snapshots stay disconnected**
The new size-rejection branch puts oversized snapshots into the permanent `payload` wait. A terminal review near the byte limit can cross it when notes are added. Removing those notes later sends a smaller snapshot through `updateSnapshot`, but that method never releases the wait. Browser and session access stay broken even after the review fits again.
Recheck admission when a snapshot changes and release a size-based wait once the current pair fits.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Fixed in 4935c05: a payload wait now records whether it came from a size refusal (1009/1013 with the session over a per-session bound). updateSnapshot re-checks admission and ends a size wait once the current registration and snapshot fit, so the next reconnect registers without a reload. Parser (1008) refusals still wait for a replacement review, as before. Tests: "ends a size refusal once a smaller snapshot brings the session back under the bounds" and "keeps a parser refusal waiting for a replacement review, whatever the snapshot".
Generated by Claude Code
…napshot reconnect The headless runner's publication probe now takes an abort signal that the registration wait aborts when it ends, so a daemon that answers the hello and then nothing cannot hold the command open past its bound. A size refusal (1009/1013 for a session over a per-session bound) is now marked as such, and a snapshot update that brings the registration and snapshot back under the bounds ends the wait, so a terminal review whose notes shrink reconnects without a reload. Parser refusals still wait for a replacement review, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nn5HpgDBQrjicbK5ZoZnMG
Problem
A
hunk diff --webreview that is too large for the session daemon printed a URL and kept running, but the page said "This review link is not valid for that session". In some cases stderr was empty too. Nothing told the user that the review was too big.The cause: the daemon judges a registration only after the signed hello, and it refuses one by closing the socket.
waitForDaemonRegistrationwaited forwaitForFirstRegistration(), which settles at the hello, so the URL was already printed when the refusal arrived. The daemon enforces four per-session bounds, and each fails differently:maxRetainedSessionBytes)In practice the 4 MiB retained bound binds first. Because each file's runtime id carries the absolute repo path, the ceiling is roughly 2,300–2,500 files, depending on path length.
Repro
Approach
session/broker/registrationAdmission.ts): measures the registration and snapshot the broker client sends against the bounds the daemon enforces. It uses the same constants (MAX_REGISTRATION_FILES,MAX_HUNK_REVIEW_CATALOG_RESOURCES,maxWsMessageBytes,maxRetainedSessionBytes). For the retained bound it uses the broker's own measurement, now exported fromsession-broker-coreasmeasureRetainedSessionBytesand used bybrokerStateitself. When the review is over a bound,--webexits 1 before it starts a daemon:hunk: could not serve this review through the session daemon on 127.0.0.1:<port>. This review has 6,000 files, more than the session daemon can hold (about 2,300 files like these). Narrow it to fewer files with--.unauthorized). The message now reads "This review link does not match a review the Hunk daemon is serving." The remedy names a missing key, a stopped review, and a review refused as too large. The docs troubleshooting section is updated to match.Non-goals / decided against
generation,fileKey,contentTypeand the id repeat per resource, at about 240 bytes each, andfileKeysByRuntimeIdrepeats absolute paths. But slimming them changes the catalog's shape on the session wire, which needs a version bump and a fixture change, and on the browser publication body. That still would not reach 6,000 files without also raising the 5,000-file and 15,000-resource caps. Offeringbytesresources only for previewable files would cut 2 of the 5 resources per file, but it would move the preview policy into publication. Neither is cheap and safe, so this PR only makes the failure honest.--watchreload that later grows a running--webreview past the bounds is still dropped by the daemon. stderr now shows the rejection notice and the page shows the new message, but the process keeps running. Refusing such a reload belongs in the reload coordinator, which the terminal shares, so it is left as a follow-up.Tests
registrationAdmission.test.ts: each bound with injected limits, the default file cap, the estimate's rounding, and the wording.headlessReviewRunner.test.ts: an oversized review exits with the message, prints no URL, never waits, and holds no process. The URL is printed only once the daemon serves the review. A refusal reported after the hello exits with that refusal and no URL.brokerClient.test.ts: classification of 1009/1013 closes.test/session/headless.test.ts: a real-process run with 3,100 changed files (over the catalog bound whatever the paths) exits 1, prints nothing on stdout, puts the message on stderr, and launches no daemon.Commands run, all passing:
Manual checks, run with an isolated
HUNK_MCP_PORTand XDG dirs:-- packages/module-1serves the review.mainand this branch on the same repo. At 2,540 files both serve the review. At 2,550, 2,560 and 2,600,mainprinted a URL buthunk session listwas empty, and this branch exits with the message. The admission check matched the daemon at every size tried.Platforms: Linux only.
Known limitations
Generated by Claude Code