Skip to content

fix: post-write hook debounce break outside loop#35

Merged
benslockedin merged 1 commit intomainfrom
fix/post-write-hook-break
Apr 9, 2026
Merged

fix: post-write hook debounce break outside loop#35
benslockedin merged 1 commit intomainfrom
fix/post-write-hook-break

Conversation

@benslockedin
Copy link
Copy Markdown
Contributor

Summary

  • The project.py debounce guard in alive-post-write.sh (line 53) used break to early-exit when the walnut was already projected within the last 5 minutes
  • break is only valid inside for/while/until loops — inside a case statement, bash emits "break: only meaningful in a for, while, or until loop" to stderr and returns non-zero, which can surface as a hook failure in Claude Code
  • Changed to exit 0, matching the identical debounce pattern for generate-index.py on line 80

Test plan

  • Trigger a log.md write twice within 5 minutes for the same walnut — second invocation should exit cleanly with no stderr
  • Confirm project.py still runs on the first write (marker file created)
  • Verify no "break: only meaningful" errors in hook output

🤖 Generated with Claude Code

The project.py debounce path (line 53) used `break` to skip
re-running when the walnut was projected within the last 5 minutes.
`break` is only valid inside for/while/until loops — inside a `case`
statement it causes bash to emit "break: only meaningful in a …
loop" to stderr and exit non-zero, which can surface as a hook
failure in Claude Code.

Changed to `exit 0`, matching the identical debounce guard for
generate-index.py on line 80.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@patrickSupernormal
Copy link
Copy Markdown

Merge safety review (advisory) — Patrick Brosnan, non-collaborator on alivecontext/alive. Comment weight only, not an approving review.

Verdict: GREEN — merge as-is, merge first of the batch.

Headline: The bug on main is real and user-visible. alive-post-write.sh:53 has [ "$AGE" -lt 300 ] && break sitting inside a case */log.md) block, inside an if [ -n "$WALNUT_PATH" ], AFTER the while ... done loop on lines 37-43 has already closed. There is no enclosing loop at that nesting level. In bash, break with no loop prints bash: break: only meaningful in a 'for', 'while', or 'until' loop to stderr and returns non-zero for that statement — but bash does NOT exit the script; it continues to the next line.

The debounce on main is therefore doubly broken:

  1. The hook emits stderr on every repeated save (Claude Code can surface as a hook failure)
  2. Execution falls through to touch "$MARKER" and re-invokes project.py anyway, so the 5-minute debounce never actually skips anything

The breakexit 0 fix is correct. exit 0 is the only right answer here — no enclosing loop, no function scope, so break/continue/return are all wrong. The fix also matches the established pattern for the second debounce block at line 80 which already uses [ "$AGE" -lt 300 ] && exit 0. The activity counter for statusline (lines 14-22) runs BEFORE the first case block, so early exit doesn't break activity tracking.

Recommendation: Merge as-is. Merge this first of the batch. No rebase needed, no author response needed, no dependencies.

Inter-PR compatibility: Zero file overlap with any other open PR (#28, #29, #31, #32, #33, #34). No semantic or behavioural interactions with #29's architectural refactor or #33's Hermes subsystem. Smallest, safest, most isolated PR in the queue. Merging first also removes any chance that Ben's rebase of #29 accidentally reintroduces the broken break during conflict resolution.

Full cross-PR synthesis (conflict matrix, recommended merge order for all 7 open PRs, per-PR verdicts, blocker list): see the cover comment on #29#29 (comment)

Generated via flow-next epic fn-8-vly (stackwalnuts walnut). 🐿️

@benslockedin benslockedin merged commit 5910737 into main Apr 9, 2026
1 check passed
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.

2 participants