fix(TAP-1877): kill '(00 scope, N system)' double-zero leak in Execution stats WARN#21
Merged
Merged
Conversation
…ion stats WARN
`grep -c | ... || echo 0` is the canonical pitfall already documented
in CLAUDE.md: `grep -c` on a no-match exits 1 with stdout "0", so the
`|| echo 0` branch appends another "0" — `tr -d '[:space:]'` then
collapses the pair into the literal "00" that leaked through to the
WARN line on 9 of 50 lines in the 2026-05-15 → 2026-05-16 tapps-brain
ralph.log.
Two-part fix:
1. Replace the inline grep/echo/tr-d-space idiom in exec_run_live with
the documented `tr -cd '0-9' || true` + `${var:-0}` pattern. The
change keeps only digits regardless of whether the inner grep
matched, and the default keeps arithmetic safe if the pipeline
produces "0", "" or any digit run.
2. Extract the stats-line emission into a new `exec_log_execution_stats`
helper at the bottom of lib/exec_helpers.sh so the regression
surface is unit-testable. exec_run_live becomes one line.
The new tests/unit/test_exec_post_run.bats covers the canonical
regression case (errors > 0 + zero scope matches must print
`(0 scope, N system)`, not `(00 scope, …)`) plus the mixed
scope/system split, the negative-system clamp, the missing-output_file
defensive path, and the zero-errors INFO branch. Full unit (1731) and
integration (203) suites green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wtthornton
added a commit
that referenced
this pull request
May 16, 2026
…1876, TAP-1877) Cuts 2.15.1 over the 2026-05-15 → 2026-05-16 tapps-brain log review. All three tickets land as fixes to observable regressions in the coordinator brief flow, the validate-command.sh denial UX, and the post-run Execution stats WARN line. - TAP-1875 (#19) — coordinator brief.json missing on ~88% of cache-miss spawns. Tighter agent contract + harness-side prompt + one-time retry + brain_learn_failure regression signal. - TAP-1876 (#20) — python3 -c friction in validate-command.sh denial flow. Remediation message + Tier-B python-introspection skill + skill_retro auto-install hook. - TAP-1877 (#21) — '(00 scope, N system)' double-zero leak in Execution stats WARN. Replaced `grep -c | echo 0` idiom with documented `tr -cd '0-9' || true` pattern; extracted into testable helper. CLAUDE.md "Coordinator brief" section updated with the TAP-1875 retry + brain_learn invariants. Unit suite 1751/1751 green, integration 203/203 green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
grep -c | ... || echo 0is the canonical pitfall already documented in CLAUDE.md:grep -con a no-match exits 1 with stdout"0", so the|| echo 0branch appended another"0"—tr -d '[:space:]'then collapsed the pair into the literal"00"that leaked through to the WARN line on 9 of 50 lines in the 2026-05-15 → 2026-05-16 tapps-brain ralph.log.grep/echo/tr-d-spaceidiom inexec_run_livewith the documentedtr -cd '0-9' || true+${var:-0}pattern. Keeps only digits whether grep matched or not; default keeps arithmetic safe.exec_log_execution_statshelper at the bottom oflib/exec_helpers.shso the regression surface is unit-testable.Test plan
tests/unit/test_exec_post_run.bats(+5 cases): zero errors → INFO branch, errors with zero scope matches print(0 scope, N system)not(00 scope, …), mixed scope+system split, negative-system clamp, missing output_file defensive path🤖 Generated with Claude Code