close-report reviewer gate fails CLOSED on a >128KB diff (prompt exceeds MAX_ARG_STRLEN, claude never runs) #2162

Closed
opened 2026-11-04 15:22:09 +00:00 by matou-build-agent · 1 comment

Symptom

close-report.sh's independent-reviewer gate (#197) fails every close CLOSED whenever the claimed commits' combined diff is larger than ~128 KB, even in a sandbox where the reviewer cannot authenticate (which #228/#2155 decided must SKIP, not fail).

Observed on #2154 (an i18n seam ticket, ~1553-line / ~146 KB diff): the close-report gate refused with

reviewer output was empty or unparseable — failing the close CLOSED (#197)

and posted an independent reviewer … verdict malformed, despite all deterministic gates passing and the reviewer being structurally unauthenticated in the worker sandbox.

Root cause

cr_review_invoke (.sandcastle/close-report.sh ~L300) passes the whole reviewer prompt as a single argv string:

( cd "$root" && timeout … claude -p --model "$SWARM_REVIEW_MODEL" \
    --allowedTools "$tools" --output-format json "$(cat "$prompt_file")" ) \
  > "$result" 2>"$log" || true

cr_review_build_prompt embeds git show … | head -c 200000 — up to 200 KB of diff. On Linux a single argument string is capped at MAX_ARG_STRLEN = 131072 bytes (128 KB), independent of the 2 MB total ARG_MAX. A prompt over that cap makes execve fail with E2BIG:

/usr/bin/timeout: Argument list too long   (rc 126)

so claude never runs, : > "$result" leaves the result file empty, and || true swallows the failure. cr_review_parse on an empty file → _cr_review_fail → _cr_review_is_auth_error returns 1 (an empty file fails its [ -s "$rf" ] guard) → verdict malformed → fail CLOSED.

This defeats the #228/#2155 intent: an un-runnable reviewer should be treated as ABSENT and SKIPPED, never fail the close. The arg-size failure is indistinguishable from "reviewer ran and returned garbage" only because the un-run signal (E2BIG → empty file) is classified as malformed.

Reproduced deterministically in the #2154 worker sandbox:

  • exact single-arg invocation with the real 146 KB prompt → Argument list too long, rc 126, 0-byte result file;
  • the same invocation with a short prompt → a well-formed {… "result":"Not logged in · Please run /login", usage.input_tokens:0 …} that _cr_review_is_auth_error correctly classifies as unauthenticated → SKIP.

So the bug bites any ticket with a >~128 KB diff, and on an authenticated host would brick those closes regardless of auth.

Proposed fix (one of)

  1. Feed the prompt on stdin, not argv (preferred — no size cap): claude -p --model … --output-format json < "$prompt_file" (claude -p reads the prompt from stdin when no prompt argument is given). Removes the MAX_ARG_STRLEN ceiling entirely.
  2. Failing that, in cr_review_invoke detect the empty-result / non-zero-rc case and classify an un-run reviewer (claude present, invocation failed to execute, zero bytes out) as absent → SKIP, preserving fail-CLOSED only for a reviewer that produced non-empty non-usage output. (Keep the #197 posture for a reviewer that genuinely ran.)
  3. As a floor, also cap the embedded diff well under 128 KB and note the truncation in the prompt.

TDD: a cr_review_parse / cr_review_invoke case over a >128 KB prompt file asserting the close is not refused CLOSED when the reviewer could not execute.

Found while working

#2154 (i18n Go seam: member dashboard + join-rejection surfaces). The ticket's own work is complete, verified green on every deterministic gate, and pushed to its worker branch; this gate is the sole blocker. Filed per CLAUDE.md Rule 9 (protected-path machinery bug → separate issue, ready-for-session, ADR 0174) — .sandcastle/close-report.sh is a protected path.

## Symptom `close-report.sh`'s independent-reviewer gate (#197) **fails every close CLOSED whenever the claimed commits' combined diff is larger than ~128 KB**, even in a sandbox where the reviewer cannot authenticate (which #228/#2155 decided must SKIP, not fail). Observed on **#2154** (an i18n seam ticket, ~1553-line / ~146 KB diff): the close-report gate refused with ``` reviewer output was empty or unparseable — failing the close CLOSED (#197) ``` and posted an `independent reviewer … verdict malformed`, despite **all deterministic gates passing** and the reviewer being structurally unauthenticated in the worker sandbox. ## Root cause `cr_review_invoke` (`.sandcastle/close-report.sh` ~L300) passes the whole reviewer prompt as a **single `argv` string**: ```sh ( cd "$root" && timeout … claude -p --model "$SWARM_REVIEW_MODEL" \ --allowedTools "$tools" --output-format json "$(cat "$prompt_file")" ) \ > "$result" 2>"$log" || true ``` `cr_review_build_prompt` embeds `git show … | head -c 200000` — up to 200 KB of diff. On Linux a **single** argument string is capped at `MAX_ARG_STRLEN` = 131072 bytes (128 KB), independent of the 2 MB total `ARG_MAX`. A prompt over that cap makes `execve` fail with `E2BIG`: ``` /usr/bin/timeout: Argument list too long (rc 126) ``` so `claude` never runs, `: > "$result"` leaves the result file **empty**, and `|| true` swallows the failure. `cr_review_parse` on an empty file → `_cr_review_fail` → `_cr_review_is_auth_error` returns 1 (an empty file fails its `[ -s "$rf" ]` guard) → verdict **`malformed`** → **fail CLOSED**. This defeats the #228/#2155 intent: an un-runnable reviewer should be treated as ABSENT and SKIPPED, never fail the close. The arg-size failure is indistinguishable from "reviewer ran and returned garbage" only because the un-run signal (E2BIG → empty file) is classified as malformed. Reproduced deterministically in the #2154 worker sandbox: - exact single-arg invocation with the real 146 KB prompt → `Argument list too long`, rc 126, 0-byte result file; - the same invocation with a short prompt → a well-formed `{… "result":"Not logged in · Please run /login", usage.input_tokens:0 …}` that `_cr_review_is_auth_error` correctly classifies as `unauthenticated` → SKIP. So the bug bites **any ticket with a >~128 KB diff**, and on an authenticated host would brick those closes regardless of auth. ## Proposed fix (one of) 1. **Feed the prompt on stdin, not argv** (preferred — no size cap): `claude -p --model … --output-format json < "$prompt_file"` (claude `-p` reads the prompt from stdin when no prompt argument is given). Removes the `MAX_ARG_STRLEN` ceiling entirely. 2. Failing that, in `cr_review_invoke` detect the empty-result / non-zero-rc case and classify an **un-run** reviewer (claude present, invocation failed to execute, zero bytes out) as absent → SKIP, preserving fail-CLOSED only for a reviewer that produced non-empty non-usage output. (Keep the #197 posture for a reviewer that genuinely ran.) 3. As a floor, also cap the embedded diff well under 128 KB and note the truncation in the prompt. TDD: a `cr_review_parse` / `cr_review_invoke` case over a >128 KB prompt file asserting the close is not refused CLOSED when the reviewer could not execute. ## Found while working #2154 (i18n Go seam: member dashboard + join-rejection surfaces). The ticket's own work is complete, verified green on every deterministic gate, and pushed to its worker branch; this gate is the sole blocker. Filed per CLAUDE.md Rule 9 (protected-path machinery bug → separate issue, `ready-for-session`, ADR 0174) — `.sandcastle/close-report.sh` is a protected path.
Author
Member

Close-report — #2162 already landed under #2161 (concurrent duplicate)

This exact bug — the close-report.sh independent-reviewer gate (#197) failing
CLOSED whenever the reviewer prompt exceeds the Linux single-argument limit
MAX_ARG_STRLEN (~128 KiB) because execve returns E2BIG before claude
starts, leaving an empty result that cr_review_parse classified as malformed
— was fixed on main by a concurrent session as #2161, commit 6df89b67
(landed before this ticket was drained). #2161 is closed; its title and root
cause are identical to this one, and it names the same live close (#2154) that
first surfaced the gate.

Both of this ticket's proposed fixes are already live on origin/main:

  • Preferred fix 1 (stdin, no size cap) — close-report.sh:310 now feeds
    the prompt to claude -p on stdin: --output-format json < "$prompt_file"
    instead of the old single-argv "$(cat "$prompt_file")". Removes the
    MAX_ARG_STRLEN ceiling entirely.
  • Fix 2 (classify an un-run reviewer as absent → SKIP) — close-report-lib.sh:621
    _cr_review_is_auth_error now return 0s on an absent/empty result file, so an
    exec failure (E2BIG → 0-byte result) normalises to unauthenticated → SKIP,
    never malformed. A reviewer that genuinely RAN always writes a non-empty
    --output-format json envelope, so the #197 fail-CLOSED posture is preserved
    for real garbage (RV-C), while a large diff is never worse than an absent
    reviewer (RV-C2).

The TDD this ticket asked for is also already in place and green: close-report-lib
RV7/RV8 (empty/missing result → skip, was malformed) and close-report RV-C2
(empty result → close PROCEEDS over a large diff).

Proof (this session, on origin/main):

  • .sandcastle/tests/close-report-lib-test.sh → 81 checks passed
  • .sandcastle/tests/close-report-test.sh → 142 checks passed
  • .sandcastle/close-report.sh:310 carries < "$prompt_file"; .sandcastle/close-report-lib.sh:621 returns 0 on empty/missing.

No new code change is needed — the fix is already on main (including the
upstream dev-factory vendor and FACTORY_REF bump described in #2161's commit).
Closing as a duplicate of #2161.

Ruled by agent under ADR 0174 — veto anytime. Two-way door: nothing was landed
from this session; the ticket is closed only because the identical fix is already
proven live on main.

## Close-report — #2162 already landed under #2161 (concurrent duplicate) This exact bug — the `close-report.sh` independent-reviewer gate (#197) failing CLOSED whenever the reviewer prompt exceeds the Linux single-argument limit `MAX_ARG_STRLEN` (~128 KiB) because `execve` returns `E2BIG` before `claude` starts, leaving an empty result that `cr_review_parse` classified as `malformed` — was fixed on `main` by a concurrent session as **#2161**, commit `6df89b67` (landed before this ticket was drained). #2161 is closed; its title and root cause are identical to this one, and it names the same live close (#2154) that first surfaced the gate. Both of this ticket's proposed fixes are already live on `origin/main`: - **Preferred fix 1 (stdin, no size cap)** — `close-report.sh:310` now feeds the prompt to `claude -p` on **stdin**: `--output-format json < "$prompt_file"` instead of the old single-argv `"$(cat "$prompt_file")"`. Removes the `MAX_ARG_STRLEN` ceiling entirely. - **Fix 2 (classify an un-run reviewer as absent → SKIP)** — `close-report-lib.sh:621` `_cr_review_is_auth_error` now `return 0`s on an absent/empty result file, so an exec failure (E2BIG → 0-byte result) normalises to `unauthenticated` → SKIP, never `malformed`. A reviewer that genuinely RAN always writes a non-empty `--output-format json` envelope, so the #197 fail-CLOSED posture is preserved for real garbage (RV-C), while a large diff is never worse than an absent reviewer (RV-C2). The TDD this ticket asked for is also already in place and green: `close-report-lib` RV7/RV8 (empty/missing result → skip, was malformed) and `close-report` RV-C2 (empty result → close PROCEEDS over a large diff). **Proof (this session, on `origin/main`):** - `.sandcastle/tests/close-report-lib-test.sh` → **81 checks passed** - `.sandcastle/tests/close-report-test.sh` → **142 checks passed** - `.sandcastle/close-report.sh:310` carries `< "$prompt_file"`; `.sandcastle/close-report-lib.sh:621` returns 0 on empty/missing. No new code change is needed — the fix is already on `main` (including the upstream dev-factory vendor and FACTORY_REF bump described in #2161's commit). Closing as a duplicate of #2161. Ruled by agent under ADR 0174 — veto anytime. Two-way door: nothing was landed from this session; the ticket is closed only because the identical fix is already proven live on `main`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#2162
No description provided.