close-report reviewer gate (#197) fails CLOSED in interactive standing sessions: headless claude -p is unauthenticated #228

Closed
opened 2026-10-15 07:37:55 +00:00 by matou-build-agent · 3 comments

Symptom

close-report.sh's independent-reviewer gate (#197) runs a headless claude -p --output-format json call. In an interactive standing session (session-runner.sh, the drainer that works ready-for-session tickets) that subprocess returns terminal_reason: api_error with .result = "Not logged in · Please run /login" — the interactive session is authenticated, but the spawned headless -p child is not. cr_review_parse then sees empty/unparseable output and the gate fails CLOSED, refusing every close with reviewer output was empty or unparseable.

Impact

The standing sessions are exactly the agents that close ready-for-session (protected-path / high-blast-radius) tickets. So the #197 gate is effectively un-runnable on the close path it most needs to cover — a session either dead-ends or (as on #217) must CR_REVIEW_DISABLE=1 and substitute an out-of-band read-only review, which is manual and easy to get wrong.

Repro

In a standing session checkout: claude -p --model "$SWARM_HEAL_MODEL" --output-format json "hi" | jq -r .result → Not logged in · Please run /login.

Proposed options (design, not prescribed)

  1. Treat an auth-error result (terminal_reason=api_error + a "/login" .result) the same as an ABSENT reviewer binary — SKIP the gate (the #197 comment already says absence is skipped, "no worse than pre-#197"), rather than fail CLOSED. This keeps fail-closed for a reviewer that genuinely RAN and returned garbage.
  2. OR have session-runner.sh wire CR_REVIEW_CMD to a reviewer that runs inside the session's authenticated context (e.g. an SDK/subagent call) so the gate runs for real.
  3. Also: .sandcastle/review-prompt.md is not vendored into the factory self-copy yet, and root close-report.sh resolves $here/review-prompt.md (repo root), which does not exist — the skeleton lives at prompts/review-prompt.md. The prompt-file default should resolve the skeleton wherever close-report runs from.

Found while closing #217 (the in-sandbox worker rebase re-test gate); that close used option-0 (disable + out-of-band review) as a documented ADR 0174 two-way-door ruling.

## Symptom `close-report.sh`'s independent-reviewer gate (#197) runs a headless `claude -p --output-format json` call. In an **interactive standing session** (`session-runner.sh`, the drainer that works `ready-for-session` tickets) that subprocess returns `terminal_reason: api_error` with `.result = "Not logged in · Please run /login"` — the interactive session is authenticated, but the spawned headless `-p` child is not. `cr_review_parse` then sees empty/unparseable output and the gate **fails CLOSED**, refusing every close with `reviewer output was empty or unparseable`. ## Impact The standing sessions are exactly the agents that close `ready-for-session` (protected-path / high-blast-radius) tickets. So the #197 gate is effectively un-runnable on the close path it most needs to cover — a session either dead-ends or (as on #217) must `CR_REVIEW_DISABLE=1` and substitute an out-of-band read-only review, which is manual and easy to get wrong. ## Repro In a standing session checkout: `claude -p --model "$SWARM_HEAL_MODEL" --output-format json "hi" | jq -r .result` → `Not logged in · Please run /login`. ## Proposed options (design, not prescribed) 1. Treat an auth-error result (`terminal_reason=api_error` + a "/login" `.result`) the same as an ABSENT reviewer binary — SKIP the gate (the #197 comment already says absence is skipped, "no worse than pre-#197"), rather than fail CLOSED. This keeps fail-closed for a reviewer that genuinely RAN and returned garbage. 2. OR have `session-runner.sh` wire `CR_REVIEW_CMD` to a reviewer that runs inside the session's authenticated context (e.g. an SDK/subagent call) so the gate runs for real. 3. Also: `.sandcastle/review-prompt.md` is not vendored into the factory self-copy yet, and root `close-report.sh` resolves `$here/review-prompt.md` (repo root), which does not exist — the skeleton lives at `prompts/review-prompt.md`. The prompt-file default should resolve the skeleton wherever close-report runs from. Found while closing #217 (the in-sandbox worker rebase re-test gate); that close used option-0 (disable + out-of-band review) as a documented ADR 0174 two-way-door ruling.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime

Ruling: Fix via option 1 — the reviewer gate treats a reviewer that
could not authenticate (a claude -p child returning
terminal_reason=api_error with a /login .result) the same as an absent
reviewer binary
: SKIP the gate, rather than fail CLOSED. Fail-closed is
retained for a reviewer that genuinely RAN and returned empty/garbage output.
Also fix the review-prompt.md skeleton path resolution (option 3) so
close-report.sh finds the skeleton wherever it runs from. Classified
bug / ready-for-agent.

Why this is a two-way door: it is revertible by a later commit (the skip
branch can be removed or narrowed), and it does not touch the one-way-door
list — the independent-reviewer gate is a code-quality / false-green guard,
not a security control, so narrowing when it runs is not a security-posture
widening, and nothing here concerns credentials, a member-facing trust
accept, data destruction, or non-routine spend. The skip is the exact posture
#197 already ships for an absent reviewer binary ("no worse than
pre-#197").

What proves it: the reviewer-gate parse + verdict logic is deliberately
offline-testable over a shimmed claude result file (close-report-lib.sh
header). A shimmed auth-error result ({terminal_reason:"api_error", result:"Not logged in · Please run /login"}) must make the gate skip; a
shimmed genuine-garbage result must still fail CLOSED. Both assertions
live in the existing close-report offline tests.

Option 2 (wire session-runner.sh to run the reviewer inside the
session's authenticated context) is a larger design change and is left out of
scope for this ticket — option 1 unblocks standing-session closes now and is
fully revertible if a real in-session reviewer is later preferred.


Agent Brief

Category: bug
Summary: The independent-reviewer gate (#197) fails CLOSED in interactive
standing sessions because the headless claude -p child it spawns is
unauthenticated; treat an auth-error reviewer result as an absent reviewer
(SKIP), not as garbage (fail-closed), and fix the reviewer-prompt skeleton
path resolution.

Current behavior:
In an interactive standing session (the drainer that works
ready-for-session tickets), the reviewer gate is considered enabled
because a review model is configured and claude is on PATH — but the
spawned headless claude -p --output-format json child is not
authenticated
and returns terminal_reason=api_error with
.result = "Not logged in · Please run /login". The verdict parse normalises
that to malformed, so the gate fails CLOSED and refuses every close with
reviewer output was empty or unparseable. Standing sessions are precisely
the agents that close protected-path / high-blast-radius tickets, so the gate
is un-runnable on the close path it most needs to cover; the current
workaround is to disable it and substitute a manual out-of-band review.

Separately, when close-report runs from the repo root the reviewer-prompt
skeleton default resolves to <script-dir>/review-prompt.md, which does not
exist at the root (the skeleton lives at prompts/review-prompt.md), so the
reviewer silently loses its skeleton.

Desired behavior:

  • When the reviewer subprocess returns an authentication error — an
    api_error terminal reason whose result text indicates the agent is not
    logged in (a /login prompt) — the gate skips (treated as "no reviewer
    available", exactly like an absent claude binary), and the close proceeds
    on the deterministic gates alone. The skip must be visible (a stdout line
    and/or thread note that the reviewer could not authenticate and was
    skipped), never a silent pass.
  • A reviewer that genuinely RAN and returned empty, truncated, or
    non-verdict output still fails CLOSED — the existing fail-closed posture
    for real garbage is unchanged.
  • The reviewer-prompt skeleton default resolves to an existing file whether
    close-report runs from the vendored .sandcastle/ copy (where the skeleton
    is vendored beside the script) or from the repo root (where it lives under
    prompts/), falling back gracefully when neither exists (prompt still
    built best-effort without the skeleton, as today).

Key interfaces:

  • The reviewer-result parse (cr_review_parse, in close-report-lib.sh):
    it currently maps anything non-verdict to {"verdict":"malformed"}.
    Distinguish an auth-error result shape (an api_error /
    not-logged-in .result) from genuine garbage — e.g. normalise it to a
    distinct verdict such as unauthenticated (or expose a dedicated
    predicate), keeping rc 0 and leaving the approve|reject|unsure|malformed
    vocabulary intact for real reviews.
  • The gate decision block in close-report.sh that switches on the
    normalised verdict: the auth-error case must route to skip the gate
    (do not add to violations, do not set gate_rc=1), parallel to the
    cr_review_enabled/absent-binary skip, while malformed keeps failing
    CLOSED.
  • The reviewer-prompt default (CR_REVIEW_PROMPT_FILE /
    cr_review_build_prompt's skel resolution): resolve the skeleton across
    the vendored-vs-root layouts.

Acceptance criteria:

  • A shimmed reviewer result of
    {"terminal_reason":"api_error","result":"Not logged in · Please run /login"}
    causes the gate to skip — the close is NOT refused on reviewer
    grounds and no reviewer output was empty or unparseable violation is
    added.
  • A shimmed reviewer result that is empty / truncated / a non-verdict
    object still fails CLOSED (the existing behaviour is preserved by a
    test).
  • A shimmed reject / unsure / approve reviewer result still
    behaves exactly as before (refuse / park-for-human / proceed).
  • The skip is observable (stdout and/or a thread note), not silent.
  • The reviewer-prompt skeleton is found both when running from the
    vendored .sandcastle/ copy and from the repo root; a missing skeleton
    still degrades to a best-effort prompt rather than erroring.
  • Every changed lib has its offline test updated in the same commit, and
    the full offline suite passes
    (for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done).
  • A docs/journal/YYYY-MM-DD-228.md entry is added and the relevant
    STATUS.md surface/header updated in the same commit (CLAUDE.md
    project-state rule); a docs/gotchas/ entry if a new operational
    hazard is codified.

Out of scope:

  • Option 2 — wiring session-runner.sh to run the reviewer inside the
    session's authenticated context (SDK/subagent). That is a separate,
    larger design change; this ticket only stops the fail-closed on auth
    failure.
  • Changing the fail-closed posture for a reviewer that genuinely ran and
    returned garbage.
  • Editing any prompt skeleton content, the vendored self-copy under
    .sandcastle/, or .forgejo/ (protected paths — a swarm worker must not
    touch them; the skeleton lands in .sandcastle/ only at the next human pin
    bump, GOTCHAS 4).
  • Changing the reviewer's model, tool allowlist, or timeout.
> *This was generated by AI during triage.* ## Ruled by agent under ADR 0174 — veto anytime **Ruling:** Fix via **option 1** — the reviewer gate treats a reviewer that could not *authenticate* (a `claude -p` child returning `terminal_reason=api_error` with a `/login` `.result`) the same as an **absent reviewer binary**: **SKIP** the gate, rather than fail CLOSED. Fail-closed is retained for a reviewer that genuinely RAN and returned empty/garbage output. Also fix the `review-prompt.md` skeleton path resolution (option 3) so `close-report.sh` finds the skeleton wherever it runs from. Classified **bug / ready-for-agent**. **Why this is a two-way door:** it is revertible by a later commit (the skip branch can be removed or narrowed), and it does not touch the one-way-door list — the independent-reviewer gate is a code-quality / false-green guard, not a security control, so narrowing *when* it runs is not a security-posture widening, and nothing here concerns credentials, a member-facing trust accept, data destruction, or non-routine spend. The skip is the exact posture #197 already ships for an absent reviewer binary ("no worse than pre-#197"). **What proves it:** the reviewer-gate parse + verdict logic is deliberately offline-testable over a shimmed `claude` result file (`close-report-lib.sh` header). A shimmed auth-error result (`{terminal_reason:"api_error", result:"Not logged in · Please run /login"}`) must make the gate **skip**; a shimmed genuine-garbage result must still **fail CLOSED**. Both assertions live in the existing `close-report` offline tests. **Option 2** (wire `session-runner.sh` to run the reviewer inside the session's authenticated context) is a larger design change and is left out of scope for this ticket — option 1 unblocks standing-session closes now and is fully revertible if a real in-session reviewer is later preferred. --- ## Agent Brief **Category:** bug **Summary:** The independent-reviewer gate (#197) fails CLOSED in interactive standing sessions because the headless `claude -p` child it spawns is unauthenticated; treat an auth-error reviewer result as an absent reviewer (SKIP), not as garbage (fail-closed), and fix the reviewer-prompt skeleton path resolution. **Current behavior:** In an interactive standing session (the drainer that works `ready-for-session` tickets), the reviewer gate is considered *enabled* because a review model is configured and `claude` is on PATH — but the spawned headless `claude -p --output-format json` child is **not authenticated** and returns `terminal_reason=api_error` with `.result = "Not logged in · Please run /login"`. The verdict parse normalises that to `malformed`, so the gate **fails CLOSED** and refuses every close with `reviewer output was empty or unparseable`. Standing sessions are precisely the agents that close protected-path / high-blast-radius tickets, so the gate is un-runnable on the close path it most needs to cover; the current workaround is to disable it and substitute a manual out-of-band review. Separately, when close-report runs from the repo root the reviewer-prompt skeleton default resolves to `<script-dir>/review-prompt.md`, which does not exist at the root (the skeleton lives at `prompts/review-prompt.md`), so the reviewer silently loses its skeleton. **Desired behavior:** - When the reviewer subprocess returns an **authentication error** — an `api_error` terminal reason whose result text indicates the agent is not logged in (a `/login` prompt) — the gate **skips** (treated as "no reviewer available", exactly like an absent `claude` binary), and the close proceeds on the deterministic gates alone. The skip must be visible (a stdout line and/or thread note that the reviewer could not authenticate and was skipped), never a silent pass. - A reviewer that genuinely RAN and returned empty, truncated, or non-verdict output still **fails CLOSED** — the existing fail-closed posture for real garbage is unchanged. - The reviewer-prompt skeleton default resolves to an existing file whether close-report runs from the vendored `.sandcastle/` copy (where the skeleton is vendored beside the script) or from the repo root (where it lives under `prompts/`), falling back gracefully when neither exists (prompt still built best-effort without the skeleton, as today). **Key interfaces:** - The reviewer-result parse (`cr_review_parse`, in `close-report-lib.sh`): it currently maps anything non-verdict to `{"verdict":"malformed"}`. Distinguish an **auth-error** result shape (an `api_error` / not-logged-in `.result`) from genuine garbage — e.g. normalise it to a distinct verdict such as `unauthenticated` (or expose a dedicated predicate), keeping rc 0 and leaving the `approve|reject|unsure|malformed` vocabulary intact for real reviews. - The gate decision block in `close-report.sh` that switches on the normalised verdict: the auth-error case must route to **skip the gate** (do not add to `violations`, do not set `gate_rc=1`), parallel to the `cr_review_enabled`/absent-binary skip, while `malformed` keeps failing CLOSED. - The reviewer-prompt default (`CR_REVIEW_PROMPT_FILE` / `cr_review_build_prompt`'s `skel` resolution): resolve the skeleton across the vendored-vs-root layouts. **Acceptance criteria:** - [ ] A shimmed reviewer result of `{"terminal_reason":"api_error","result":"Not logged in · Please run /login"}` causes the gate to **skip** — the close is NOT refused on reviewer grounds and no `reviewer output was empty or unparseable` violation is added. - [ ] A shimmed reviewer result that is empty / truncated / a non-verdict object still **fails CLOSED** (the existing behaviour is preserved by a test). - [ ] A shimmed `reject` / `unsure` / `approve` reviewer result still behaves exactly as before (refuse / park-for-human / proceed). - [ ] The skip is observable (stdout and/or a thread note), not silent. - [ ] The reviewer-prompt skeleton is found both when running from the vendored `.sandcastle/` copy and from the repo root; a missing skeleton still degrades to a best-effort prompt rather than erroring. - [ ] Every changed lib has its offline test updated in the same commit, and the full offline suite passes (`for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done`). - [ ] A `docs/journal/YYYY-MM-DD-228.md` entry is added and the relevant `STATUS.md` surface/header updated in the same commit (CLAUDE.md project-state rule); a `docs/gotchas/` entry if a new operational hazard is codified. **Out of scope:** - Option 2 — wiring `session-runner.sh` to run the reviewer inside the session's authenticated context (SDK/subagent). That is a separate, larger design change; this ticket only stops the fail-closed on auth failure. - Changing the fail-closed posture for a reviewer that genuinely ran and returned garbage. - Editing any prompt skeleton content, the vendored self-copy under `.sandcastle/`, or `.forgejo/` (protected paths — a swarm worker must not touch them; the skeleton lands in `.sandcastle/` only at the next human pin bump, GOTCHAS 4). - Changing the reviewer's model, tool allowlist, or timeout.
Author
Member

swarm-claim host=matou-dev-server-01 run=21978
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=21978 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #228 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 228,
  "status": "success",
  "commits": [
    "2061c58c34ed842dc6574872170614ba019683b2"
  ],
  "changed_files": [
    "STATUS.md",
    "close-report-lib.sh",
    "close-report.sh",
    "docs/journal/2026-10-15-228.md",
    "tests/close-report-lib-test.sh",
    "tests/close-report-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/close-report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/close-report-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A shimmed api_error /login reviewer result causes the gate to SKIP (not refused, no 'empty or unparseable' violation)": "close-report-lib.sh cr_review_parse → 'unauthenticated' + close-report.sh unauthenticated SKIP case; tests RV10/RV10b (lib) + RV-F (e2e asserts close proceeds+closes and no 'reviewer output was empty or unparseable')",
    "A shimmed empty/truncated/non-verdict reviewer result still fails CLOSED": "preserved: cr_review_parse → 'malformed' for non-auth garbage; lib RV5/RV6/RV7 + RV11/RV11b (login-prose/no-login-prompt stay malformed), e2e RV-C (malformed/empty refuse)",
    "A shimmed reject/unsure/approve reviewer result still behaves exactly as before": "gate switch unchanged for those verdicts; e2e RV-A (approve closes), RV-B (reject refuses with findings), RV-D (unsure parks ready-for-human)",
    "The skip is observable (stdout and/or a thread note), not silent": "close-report.sh emits 'could not authenticate … SKIPPING' on stdout + cr_post_review posts the unauthenticated verdict on the thread (:fast_forward:); e2e RV-F asserts the stdout line",
    "The reviewer-prompt skeleton is found from both the vendored .sandcastle copy and the repo root; a missing skeleton degrades to best-effort": "close-report.sh _cr_review_prompt_default resolves review-prompt.md beside the script OR prompts/review-prompt.md at root, else best-effort (cr_review_build_prompt skips a non-existent skel); e2e RV-G asserts prompts/review-prompt.md is folded in",
    "Every changed lib has its offline test updated in the same commit, and the full offline suite passes": "same commit updates tests/close-report-lib-test.sh + tests/close-report-test.sh; full suite loop green (tests entry 4, exit 0)",
    "A docs/journal/YYYY-MM-DD-228.md entry is added and the relevant STATUS.md surface/header updated in the same commit; a docs/gotchas entry if a new hazard is codified": "docs/journal/2026-10-15-228.md added + STATUS.md header line updated (same commit); no new operational hazard codified (bug fix within an existing gate), so no docs/gotchas entry needed"
  },
  "summary": "The #197 reviewer gate now SKIPS when its claude -p child is unauthenticated (new 'unauthenticated' verdict) instead of failing CLOSED, and resolves the review-prompt skeleton across the vendored and repo-root layouts.",
  "blockers": []
}
**close-report** for #228 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 228, "status": "success", "commits": [ "2061c58c34ed842dc6574872170614ba019683b2" ], "changed_files": [ "STATUS.md", "close-report-lib.sh", "close-report.sh", "docs/journal/2026-10-15-228.md", "tests/close-report-lib-test.sh", "tests/close-report-test.sh" ], "tests": [ { "command": "bash tests/close-report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/close-report-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "A shimmed api_error /login reviewer result causes the gate to SKIP (not refused, no 'empty or unparseable' violation)": "close-report-lib.sh cr_review_parse → 'unauthenticated' + close-report.sh unauthenticated SKIP case; tests RV10/RV10b (lib) + RV-F (e2e asserts close proceeds+closes and no 'reviewer output was empty or unparseable')", "A shimmed empty/truncated/non-verdict reviewer result still fails CLOSED": "preserved: cr_review_parse → 'malformed' for non-auth garbage; lib RV5/RV6/RV7 + RV11/RV11b (login-prose/no-login-prompt stay malformed), e2e RV-C (malformed/empty refuse)", "A shimmed reject/unsure/approve reviewer result still behaves exactly as before": "gate switch unchanged for those verdicts; e2e RV-A (approve closes), RV-B (reject refuses with findings), RV-D (unsure parks ready-for-human)", "The skip is observable (stdout and/or a thread note), not silent": "close-report.sh emits 'could not authenticate … SKIPPING' on stdout + cr_post_review posts the unauthenticated verdict on the thread (:fast_forward:); e2e RV-F asserts the stdout line", "The reviewer-prompt skeleton is found from both the vendored .sandcastle copy and the repo root; a missing skeleton degrades to best-effort": "close-report.sh _cr_review_prompt_default resolves review-prompt.md beside the script OR prompts/review-prompt.md at root, else best-effort (cr_review_build_prompt skips a non-existent skel); e2e RV-G asserts prompts/review-prompt.md is folded in", "Every changed lib has its offline test updated in the same commit, and the full offline suite passes": "same commit updates tests/close-report-lib-test.sh + tests/close-report-test.sh; full suite loop green (tests entry 4, exit 0)", "A docs/journal/YYYY-MM-DD-228.md entry is added and the relevant STATUS.md surface/header updated in the same commit; a docs/gotchas entry if a new hazard is codified": "docs/journal/2026-10-15-228.md added + STATUS.md header line updated (same commit); no new operational hazard codified (bug fix within an existing gate), so no docs/gotchas entry needed" }, "summary": "The #197 reviewer gate now SKIPS when its claude -p child is unauthenticated (new 'unauthenticated' verdict) instead of failing CLOSED, and resolves the review-prompt skeleton across the vendored and repo-root layouts.", "blockers": [] } ``` </details>
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/dev-factory#228
No description provided.