Skip to content

fix(web): refuse oversized reviews instead of printing a dead link - #1351

Merged
benvinegar merged 2 commits into
mainfrom
fix/web-oversized-review-link
Nov 22, 2026
Merged

benvinegar merged 2 commits into
mainfrom
fix/web-oversized-review-link

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Problem

A hunk diff --web review 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. waitForDaemonRegistration waited for waitForFirstRegistration(), 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:

bound refusal client saw
5,000 registration files / 15,000 catalog resources (≈3,000 changed text files: canonical, patch, source, 2× bytes) 1008 "Incompatible session registration." "Session daemon rejected this review" on stderr, but the URL was already printed
4 MiB retained bytes per session (maxRetainedSessionBytes) 1013 "Session broker capacity exceeded." nothing: it resent the payload every 3 s
8 MiB websocket frame 1009 from the runtime nothing: it resent a 10 MB payload every 3 s

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

for d in $(seq 1 60); do mkdir -p packages/module-$d/src/components; for i in $(seq 1 100); do echo a > packages/module-$d/src/components/component-file-$i.tsx; done; done
git add -A; git commit -m i; for f in $(git ls-files); do echo b > $f; done
hunk diff --web --no-open --no-watch

Approach

  • Admission check before any wait (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 from session-broker-core as measureRetainedSessionBytes and used by brokerState itself. When the review is over a bound, --web exits 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 -- .
  • The URL waits until the daemon serves the review. After the hello, the runner requests its own publication route with the link's capability, as the page's first request does. It stops when it gets an answer, when the broker client reports a refusal, or when the existing 6 s bound runs out. This also covers refusals that the admission check cannot predict, such as the daemon-wide session and byte budgets.
  • Terminal behaviour: the TUI already kept working on a refusal. The broker client now treats a post-hello 1009/1013 close as a registration rejection, but only when the session's own registration is over a per-session bound. That avoids treating daemon-wide capacity, which can free up, as permanent. The TUI now shows the sticky "Session daemon rejected this review. Try a smaller review." notice and waits like any other payload refusal, instead of silently resending megabytes every 3 s. I checked this in a PTY with 2,600 and 6,000 files: the TUI renders and shows the notice.
  • Page message: the daemon answers an unknown session and a wrong key the same way (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

  • Raising the ceiling. I did not change the per-file publication overhead. The descriptors are redundant: generation, fileKey, contentType and the id repeat per resource, at about 240 bytes each, and fileKeysByRuntimeId repeats 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. Offering bytes resources 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.
  • No wire change: the session-wire fixture is unchanged and no daemon restart is needed.
  • A --watch reload that later grows a running --web review 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:

bun run typecheck && bun run lint && bun run format:check && bun run deps:check
bun test packages/hunk/src/session packages/hunk/src/app/session test/session/headless.test.ts test/cli/web-entry-points.test.ts   # 659 pass
bun test scripts/quality packages/session-broker packages/session-broker-core   # 368 pass
bun run test:session-broker-node   # 4 pass
bun run build:web && npx playwright test --config test/web/playwright.config.ts --trace off test/web/review-shell.e2e.ts   # 16 pass

Manual checks, run with an isolated HUNK_MCP_PORT and XDG dirs:

  • The repro (6,000 files) and 3,100 short files now exit 1 with the message.
  • Narrowing with -- packages/module-1 serves the review.
  • At the boundary I compared main and this branch on the same repo. At 2,540 files both serve the review. At 2,550, 2,560 and 2,600, main printed a URL but hunk session list was empty, and this branch exits with the message. The admission check matched the daemon at every size tried.

Platforms: Linux only.

Known limitations

  • The "about N files" figure is an estimate: the file count scaled by the bound it overshoots most, rounded down to two significant digits.
  • Reloads that grow past the bounds: see above.

Generated by Claude Code

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
@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect local browser-review startup and terminal session connections.

Fix the unfinished probe request and snapshot recovery before merging.

Findings

  1. P1 Timeout does not end command ▶
  2. P1 Smaller snapshots stay disconnected ▶
Fix 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.

Summary

The PR refuses oversized browser reviews before printing a URL and waits for the daemon to serve the publication.

  • Browser reviews get a link only after the daemon can serve them.
  • Terminal reviews recognize when the daemon refuses an oversized payload.
  • Unavailable browser reviews explain why the daemon is not serving them.

Acknowledged by benvinegar: keeping the existing size ceilings is intentional. Reloads that grow a running browser review beyond those ceilings are explicitly deferred.

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]
Loading

Reviews (1) · Last reviewed commit: "fix(web): refuse oversized reviews inste..." · Reviewed by Greptile

Comment on lines +114 to +117
const response = await fetch(
`${httpOrigin}${reviewHttpPath({ kind: "publication", sessionId })}`,
{ headers: { [HUNK_REVIEW_CAPABILITY_HEADER]: reviewProcessCapability().token } },
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Comment on lines +550 to +552
isOversizedRegistrationRejection(event, () =>
assessSessionRegistration(this.registration, this.snapshot),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
@benvinegar
benvinegar merged commit 6eea614 into main Nov 22, 2026
15 checks passed
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