Repository navigation
Conversation
report-profile.sh claimed the pidfile with its own pid, started the watcher and exited. The watcher wrote its own pid only after asking clauth for its interval. A hook run that landed in that window read a dead pid and started a second watcher, which then polled for as long as the pane lived. herdr starts each event hook on its own thread without waiting for it, so the hooks for events close together (an agent starting) can overlap that window. - report-profile.sh writes the watcher's pid ($!) before it exits; a failed write does not fail the hook. - watch-profile.sh claims the pidfile before anything else. It releases the pidfile only while it still names itself, and it ends on its next tick when the pidfile names another watcher. Two hook runs that both find a stale pidfile can still each start one, and this bounds the duplicate to a tick. - watch-profile.sh traps HUP and TERM (and INT, when run by hand), installed before the pidfile write, so a signalled watcher runs its EXIT trap and no longer leaves its pidfile behind. Three tests drive the real scripts. All three fail on the previous scripts. Co-Authored-By: Claude Opus 5.5 <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
This PR keeps the herdr plugin's pane-tag watcher at one per pane.
report-profile.shclaimswatch-<pane>.pidwith its own pid, startswatch-profile.shin the background, and exits. The watcher writes its own pid only afterclauth herdr config get tag_watch_secsreturns. A hook run that lands in that window reads a dead pid, sokill -0fails and it starts a second watcher. That watcher then polls for as long as the pane lives. herdr starts each event hook on its own thread without waiting for it (src/app/api/plugins/runtime.rs), so the hooks for events that arrive close together, as when an agent starts, can overlap that window. I saw 38 live watchers against at most 29 panes. Whichever duplicate exits first also deletes the pidfile its sibling owns, which invites another spawn.A second gap:
trap 'rm -f "$pidfile"' EXITdoes not run when the shell is killed by SIGTERM or SIGHUP, so the pidfile outlives the watcher. Its pid can later belong to an unrelated process, and thenkill -0suppresses the pane's watcher.Changes:
report-profile.shwrites the watcher's pid ($!) before it exits. A failed write does not fail the hook.watch-profile.shclaims the pidfile before anything else.sleepreturns, so stopping a watcher now takes up to one interval.Tests (in
tests/inline/herdr.rs, on the existing chain harness):a_hook_while_the_watcher_starts_spawns_no_second_watcherslows thetag_watch_secsanswer to hold the window open, then runs two reports back to back.a_watcher_the_pidfile_does_not_name_ends_and_leaves_the_pidfilea_watcher_ended_by_sigterm_releases_its_pidfileAll three fail on the previous scripts and pass with this change. The
herdr::tests passed three runs in a row with--test-threads=16.Not covered: a pidfile can still be read empty mid-write, or recreated naming a dead pid if
report-profile.shis delayed past a watcher that exits on its first tick. Both heal on the next hook;rex-plugin/start-watch.sh's mkdir lock would close them, and I kept this change smaller instead. Also unchanged: outside herdr the state dir falls back to${TMPDIR:-/tmp}/clauth, where the pidfile writes (the watcher's, as before, and now this one) would follow a link another local user planted. Under herdrHERDR_PLUGIN_STATE_DIRis a private directory; the fallback is worth its own change.Checklist
sk-ant-*, no~/.claude/~/.clauthcontents)cargo fmt --all -- --checkpasses locally, andcargo test --locked --all-featurespasses in full (13,570 tests).cargo clippy --locked --all-targets --all-features -- -D warningson rustc 1.98.0 reports onedrop_non_dropattests/inline/runtime.rs:25835, which this PR does not touch and whichmommy's CI does not hit. With that lint allowed, clippy is clean.AI
🤖 Generated with Claude Code