Skip to content

Rebuild the eval-coverage emit scanner on a real shell parser instead of hand-rolled awk #4222

Closed

Description

@kyle-sexton

Follow-up promised in #4205, which fixed ~20 shapes in scripts/check-detector-eval-coverage.sh's emit scanner but did not change its foundation.

The problem is the approach, not the remaining bugs

The scanner hand-parses shell in awk to find emit <severity> <ID> call sites. Its failure mode of record is a silent loss: a literal call site that yields neither an ID nor an UNRESOLVED line, with CANDIDATES not counting it, so the count-vs-resolved accounting has nothing to disagree about and the gate exits 0 on a detector with uncovered check ids.

#4205 is the evidence that patching shapes does not converge. Six rounds of adversarial review, and four of them found defects introduced by the previous round's fix:

round found of which introduced by the prior fix
1 4 regressions 4
2 7 silent losses 3
3 6 silent losses, plus refuted the structural claim 0
Codex 1 (P1) 0
4 2 silent losses 2
5 (V1) 3 silent losses 2
6 (different model family) 6 silent losses, none previously found 0

Each fix was validated before shipping. The defects were found by the next round, not by the tests written alongside the fix.

The shapes still open, all verified executing under real bash

Round 6 ran on the merged b229834ae and is the sharpest evidence, because it came from a different model family and found the simplest shape of all — one that five same-model rounds never tried:

x="$(emit error P1)"        # bash: EMIT:error P1   scanner: CANDIDATES 0

A command substitution inside double quotes collapses to a single opaque token, so its call sites never reach the tokenizer. A detector that captures its emitter's output is wholly invisible to the gate.

The rest of the open set:

  • the closing line of a multi-line quoted string, when it carries a call after the quote (' ... )" || emit error P2) — per-line quote resolution inverts the state there;
  • $'...' with an escaped apostrophe, whose tail arms a delimiter that a later genuine heredoc then closes;
  • a )# comment carrying a <<WORD, which swallows to the next WORD line;
  • command positions the walk does not model: coproc, time -p, a leading redirection, a += or escaped-space assignment prefix, a quoted command name ("emit" error P8), trap '...' EXIT, eval;
  • $[ 1 << N ] deprecated arithmetic arming N;
  • two heredocs on one line (cat <<A <<B), where only A arms.

Every one needs parser state a line-based scanner does not have. #4223 records them in the header and corrects three header claims that asserted some of them were already safe; it does not fix them.

Proposal

Replace the extraction with shfmt -tojson, which emits a real AST.

  • Already a dependency. shfmt runs in this repo's lint lanes today, so this adds no new tool to CI.
  • Replaces the class. Call sites, quoting, heredoc spans and command substitutions come from a parser that agrees with bash by construction, so none of the shapes above — and none of the next ones — are the scanner's problem.
  • Fits the contract. shfmt absent, or a file it cannot parse, is an environment answer: exit 2, which the check-script contract already requires of an input the gate cannot read.

What to carry over

The 104-check self-test is the valuable artifact and should be the acceptance criterion for any replacement — it encodes every shape the rounds found, in both directions. Three disciplines in it are worth preserving explicitly, because #4205 shipped eight checks that reported clean while observing nothing:

  • Arm-and-close. An arming case must assert that a call site after the terminator is still seen. "The body's own emit is hidden" is also satisfied by a swallow-to-EOF, so it passes exactly when the scanner is most broken.
  • Measured discrimination. Every guard should be run against the revision carrying the bug it names, and fail there. In fix: read heredoc openings off the quote-resolved line in the eval-coverage gate #4205 five guards never executed at all (a helper defined 24 lines later; command not found on stderr while the suite reported green), two were byte-identical duplicates, and two exercised the wrong line.
  • Cross-model verification. Round 6 found six shapes that five same-model rounds missed, including the simplest one. Same-model review appears to share blind spots with the author.

A mutation audit keeps the first two honest: #4205's found three uncovered invariants that 104 passing checks did not.

Scope note

The gate governs one registered pair today (claude-config:audit-permission-grants), which resolves identically at every revision and contains none of the open shapes — independently re-confirmed in round 6. So nothing here is urgent. It is the difference between a gate that is correct today and a gate that stays correct as detectors are added.

🤖 Generated with Claude Code

https://claude.ai/code/session_013G9e6TtA2P5wVWRaaGT2ER

Activity

  1. added
    needs-triage
    on Sep 19, 2026
  2. added
    needs-human
    and removed
    needs-triage
    on Sep 23, 2026
  3. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Human-gated. Open decision: whether to invest in the shfmt -tojson rewrite now (issue's own scope note says "nothing here is urgent" — gate currently governs one registered pair that resolves identically today)

  4. added theissue type on Sep 23, 2026
  5. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during the 2026-09-29 audit of the Cursor run.

    Reopened, not for the shfmt decision (that ratify stands and is unchanged), but because the follow-up evidence this issue's "What to carry over" asked for is incomplete. PR #5339 (draft, Refs #4222) carries the code and test work.

    Done

    • Flipped assertions. git diff 02c87fb82~1 02c87fb82 -- scripts/check-detector-eval-coverage.test.sh removes the undecidable_case group (exit 2 became exit 1 naming P4, six shapes: the id now resolves and is reported as lacking an eval case) and unclosed_case (exit 2 became exit 1). Those are the only flipped assertions. Each was checked against real bash: all seven fixtures parse (bash -n), real bash executes both emit calls, the new scanner reports both IDs, and the pre-fix(scripts): read emit call sites with shfmt --to-json (#4222) #5065 scanner answered exit 2.
    • Header. "RE2" corrected to Oniguruma (jq's engine), with the rule that a row pattern must stay within what awk ERE and Oniguruma read identically. The "known, not exhaustive" caveat is restored.
    • Newly loud shapes. A wrapper (command, builtin, exec, nohup, eval, env, xargs) with an emit name in a later word, and a forwarder with a word after it (emit error "$@" P1), are now counted and reported UNRESOLVED (exit 2, site named) instead of vanishing. The suite is 166 pass, 0 fail.
    • Mutation audit of the jq walk and the shell comparison, run against the final script: 177 rows, 161 killed, 16 survived. One survivor is the unmutated control, which must survive.
    • Cross-model review. Codex (0.158.0, read-only, codex exec exit 0) returned 14 findings. Re-probing the final script: quoted command words and quoted arguments, emit-finding, bundled -pv lookups and later-argument false positives are fixed; concatenated, escaped and computed command words (e"mit", \emit, $(printf emit)) are stated in the header as invisible by design. Findings 9 (quoted array-subscript evaluation) and 14 (trailing newline in an ID) were not re-verified in this pass.

    Still missing

    The 15 surviving mutants have no recorded disposition. The audit plan required each to be shown equivalent or killed by a new test. Survivors, by id: st-qlit, pp-paramexp, st-arrguard, st-objguard, pp-objtype, pp-noindex, if-quoted-any, mn-id-caret, mn-restnull, mn-select-args-drop, mn-select-args, hw-opts-i2, sh-cmp-gt, sh-cand-head, sh-res-noanchor. Several are plausibly equivalent guards, but if-quoted-any, mn-id-caret, mn-select-args-drop, mn-select-args and hw-opts-i2 change behavior a test should pin.

    Next steps (owner or a follow-up run)

    1. For each survivor, decide equivalent or add a test case (additions only) to scripts/check-detector-eval-coverage.test.sh.
    2. Confirm Codex findings 9 and 14 by hand, then fix or list as rejected with reasons.
    3. Run the suite (bash scripts/check-detector-eval-coverage.test.sh), then close.

    Nothing here reverses the shfmt ratify.

  6. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during the 2026-09-29 audit of the Cursor run.

    Disposition of the 15 surviving mutants and Codex findings 9 and 14, recorded in PR #5339 (draft, Refs: #4222). The issue stays open until that PR merges.

    Survivors

    The unmutated control still passes the suite (171 pass, 0 fail). Each equivalence below was checked structurally and by running the original and mutated jq programs over 1,117 inputs (every tracked shell script plus edge shapes) with no output difference.

    Mutant Disposition Reason
    st-qlit equivalent The other one-part contents of a double-quoted word (ParamExp, CmdSubst, ArithmExp) carry no .Value, so dropping the Lit check still yields null.
    st-objguard equivalent static only sees a Word or null; for null, .Parts is null and length is 0, so the array guard returns null anyway.
    st-arrguard equivalent The object guard already rejects null, and Word .Parts is always an array.
    pp-objtype equivalent The input sits behind a length == 1 guard, so it is always an object.
    pp-paramexp equivalent Only ParamExp carries .Param; other nodes give null and fail the @/* test.
    pp-noindex equivalent shfmt refuses ${@[0]} and ${*[1]} ("cannot index a special parameter name"), so no such node reaches the walk.
    if-quoted-any equivalent A single-quoted word is a SglQuoted node with .Value and no .Parts; the .Parts[0].Parts length test fails for it either way, and the suite pins '$@' as not a forwarder.
    mn-id-caret equivalent Under jq's default regex syntax ^ is \A ("\nP1" | test("^(P1)\\z") is false; only (?m) changes that). The leading-newline case is added as a pin.
    mn-restnull equivalent Argument elements are Word objects; there are no nulls to drop.
    mn-select-args-drop equivalent A CallExpr with no Args (assignment-only) reaches hidden_wrapped_emit and the emit test with a null command word and changes nothing.
    mn-select-args equivalent A CallExpr with one Arg never yields a candidate: an emit name alone has an empty $rest, any other word has an empty .Args[1:].
    hw-opts-i2 equivalent The extra element is the emit word, which starts with emit and cannot match ^-[pvV]*[vV][pvV]*$.
    sh-cmp-gt killed New case: an id holding a second ID line makes resolved exceed candidates; the gate must exit 2.
    sh-cand-head killed New case: an id holding a CANDIDATES 7 line must not replace the last CANDIDATES line.
    sh-res-noanchor killed New case: an id line that only contains ID is not an ID line.

    The three killed mutants are reachable only through a row pattern that accepts whitespace, which the header's row-pattern contract excludes. The cases pin the counts rather than report a live defect.

    Codex findings

    • 9 (commands run during quoted array-subscript evaluation, [[ -v 'a[$(emit error P1)]' ]]): rejected as by design. It is text until bash evaluates it, the same class as eval '...', and the header's "any other string bash evaluates later" covers it. A not-a-site case now pins it.
    • 14 (trailing newline in an id): already fixed. The id match is \A(...)\z, the existing trailing-newline case asserts it is UNRESOLVED, and a leading-newline case is added beside it.

    Left open

    The issue's decision (the shfmt -tojson rewrite, human-gated) is unchanged. Nothing remains for the mutation audit or the Codex review once #5339 merges.

  7. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during the 2026-09-29 audit of the Cursor run.

    Owner decision needed: confirm the shfmt rewrite (priority low)

    What happened. PR #5029 parked the eval-coverage shell-parser rewrite as unpaid work. It was closed without merging at 2026-09-28 05:26 UTC. PR #5065 merged the rewrite (shfmt --to-json) at 07:23 UTC the same day. Neither PR says why the park was reversed. The issue was triaged needs-human, so no owner decision covers the rewrite. Where the earlier audit comment says "that ratify stands", it means the audit recommended ratifying. The owner has not decided.

    What it costs.

    • A new CI and cloud dependency. scripts/check-detector-eval-coverage.sh needs shfmt v3.13.0 or later and exits 2 without it.
    • The v3.14.1 pin and its SHA-256 are kept in three places: .claude/cloud-bootstrap.sh:73, the ci.yml lint-2 install step (:774), and the test-linux install step (:1707). A pin bump has to touch all three. No check keeps them in parity.

    Options

    Recommended: A (judgment). The rewrite is merged, tested (171 cases), and fixes shapes the old scanner dropped silently. The pin duplication is a maintenance cost; a small pin-parity check can cover it if the owner wants one.

    Reply A or B here. Choosing A closes this item. Choosing B unblocks a revert PR.

  8. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-29): accepted the recommendation: "A. Ratify the rewrite as merged. Nothing changes. The mutation dispositions in PR #5339 stand."

    The owner accepted every standing recommendation on 2026-09-29.

    Evidence, checked against origin/main: PR #5065 merged 2026-09-28T07:23:27Z, and scripts/check-detector-eval-coverage.sh on origin/main uses shfmt (16 references). No revert is needed.

    Next: closing as completed. The survivor and Codex dispositions stay recorded in PR #5339 (Refs #4222, still open), which merges on its own review. The optional pin-parity check for the three shfmt pin sites is not part of this decision; file it separately if wanted.

  9. removed
    needs-human
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions