Skip to content

fix(TAP-1877): kill '(00 scope, N system)' double-zero leak in Execution stats WARN#21

Merged
wtthornton merged 1 commit into
mainfrom
tap-1877-exec-helpers-grep-c-pitfall
May 16, 2026
Merged

fix(TAP-1877): kill '(00 scope, N system)' double-zero leak in Execution stats WARN#21
wtthornton merged 1 commit into
mainfrom
tap-1877-exec-helpers-grep-c-pitfall

Conversation

@wtthornton
Copy link
Copy Markdown
Owner

Summary

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

  • Replaced the inline grep/echo/tr-d-space idiom in exec_run_live with the documented tr -cd '0-9' || true + ${var:-0} pattern. Keeps only digits whether grep matched or not; default keeps arithmetic safe.
  • Extracted 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.

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
  • Full unit suite — 1731/1731 pass
  • Full integration suite — 203/203 pass

🤖 Generated with Claude Code

…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 wtthornton merged commit 74a9410 into main May 16, 2026
3 checks passed
@wtthornton wtthornton deleted the tap-1877-exec-helpers-grep-c-pitfall branch May 16, 2026 21:06
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>
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.

1 participant