Skip to content

fix(herdr): filter firstmate-owned agents from the spur completion channel - #59

Merged
trillium merged 2 commits into
mainfrom
robots-d45j/spur-ownership
Aug 5, 2026
Merged

trillium merged 2 commits into
mainfrom
robots-d45j/spur-ownership

Conversation

@trillium

@trillium trillium commented Aug 5, 2026

Copy link
Copy Markdown
Owner

What Changed

  • Added window_owner_task to fm-classify-lib.sh — a strict ownership lookup that returns non-zero (printing nothing) when no task's metadata records the target, unlike window_to_task's always-something fallback; window_to_task is refactored to delegate to it.
  • Updated fm-herdr-spur.sh to call fm_herdr_spur_spur_or_skip (replacing direct fm_herdr_spur_enqueue calls) at both the poll-reconcile and event-stream finish-edge sites; the new function resolves the bare pane id against current state metadata — trying both bare and session-qualified shapes — and drops the edge when a firstmate task owns the pane.
  • Added tests/fm-herdr-spur.test.sh covering strict ownership semantics, the backend-qualified vs. bare pane-id mismatch that was the root defect, and mixed-fleet passes where the owned agent is absent from the wake queue while the external agent still fires.

Risk Assessment

✅ Low: The change is well-bounded — it fixes a concrete defect (owned-agent spurious double-waking), the refactored window_to_task preserves all existing call site semantics, the two-shape ownership probe is correct, and behavioral tests cover the stated scenarios.

Testing

Ran the new targeted test suite (7 assertions) plus the backend and transition-lib suites that exercise the refactored window_to_task — all pass. The tests exercise both the strict window_owner_task ownership API and the bridge's end-to-end filtering behavior across external-only, owned-only, and mixed-fleet scenarios.

Evidence: fm-herdr-spur.test.sh output

ok - window_owner_task resolves a recorded window target to its owning task ok - window_owner_task returns non-zero and prints nothing when no task owns the target ok - window_to_task keeps its fallback while window_owner_task stays strict ok - a pane no firstmate task records still spurs on working->idle ok - a bare pane id matching a backend-qualified window= is recognized as owned and never spurs ok - an unqualified recorded window= is recognized as owned too ok - a mixed pass spurs only the external agent # fm-herdr-spur.test.sh: all assertions passed

ok - window_owner_task resolves a recorded window target to its owning task
ok - window_owner_task returns non-zero and prints nothing when no task owns the target
ok - window_to_task keeps its fallback while window_owner_task stays strict
ok - a pane no firstmate task records still spurs on working->idle
ok - a bare pane id matching a backend-qualified window= is recognized as owned and never spurs
ok - an unqualified recorded window= is recognized as owned too
ok - a mixed pass spurs only the external agent
# fm-herdr-spur.test.sh: all assertions passed

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ tests/fm-herdr-spur.test.sh:64 - The spur_run test helper embeds the $agents variable inside single quotes in the generated herdr stub script (printf '%s\n' '$agents'). If agents JSON ever contains a literal single quote, the stub would have broken shell syntax. Current test data is safe, but the pattern is fragile if test coverage expands.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-herdr-spur.test.sh
  • bash tests/fm-backend.test.sh
  • bash tests/fm-transition-lib.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Trillium Smith and others added 2 commits August 5, 2026 10:41
`herdr agent list` reports every agent in the session, including the panes
firstmate itself spawned, and the spur bridge treated all of them as external.
A firstmate-owned agent therefore woke firstmate TWICE per turn-end - once
legitimately through its state/<id>.status append and turn-end hook, once
spuriously through a `check: herdr-spur:<pane>` wake claiming it had "no
firstmate status file". The noise scaled with fleet size and destroyed the one
property the channel exists for: that a spur means an agent firstmate cannot
otherwise see.

The mapping was always available - herdr records `window=<session>:<pane-id>`
in state/<id>.meta - but the bridge never did the reverse lookup, and
window_to_task could not answer it anyway: it always returns something, so
"nobody owns this pane" was not expressible.

- fm-classify-lib.sh: split the strict metadata scan out as window_owner_task,
  which prints the owning task or returns 1 printing nothing. window_to_task now
  calls it and keeps its own always-something fallback, so every existing caller
  is unchanged.
- fm-herdr-spur.sh: resolve each finish edge's pane back to a firstmate task
  before enqueuing, and drop the edge when one owns it. Both the bare pane id
  and the session-qualified "<session>:<pane-id>" shape are tried, since the
  event stream and `herdr agent list` report the bare form while meta records
  the qualified one - that mismatch is why a lookup would have failed even if
  the bridge had attempted it. Checked at the edge, not at subscribe time, so a
  task spawned or torn down mid-stream is classified against current metadata.

tests/fm-herdr-spur.test.sh covers the strict lookup and drives the bridge
--once against a stubbed herdr: an external pane still spurs, an owned pane
(qualified or bare window=) never does, and a mixed pass emits exactly one wake.
Without the bridge change the owned case reproduces the reported line verbatim.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@trillium, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c6fc2ff4-41e6-4214-acd6-cc6b8895bee1

📥 Commits

Reviewing files that changed from the base of the PR and between ba51491 and 206ae1a.

📒 Files selected for processing (4)
  • bin/fm-classify-lib.sh
  • bin/fm-herdr-spur.sh
  • docs/herdr-backend.md
  • tests/fm-herdr-spur.test.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@trillium
trillium merged commit 3a57582 into main Aug 5, 2026
10 checks 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.

1 participant