Repository navigation
fix(fm-watch): guard staleness auto-close reap with live pane focus - #114
Conversation
A ship pane the captain is reading/typing at (a done: pane in live review) shows the same zero content-churn as a finished crew, so the idle>2h staleness auto-close reclaim would tear it down mid-discussion. Add a human-conversation guard: on a herdr backend the watcher stamps state/.focus-<key> every idle poll it sees the pane focused, and staleness_focus_guard_blocks_reap blocks the reclaim while the pane is focused now or was focused within FM_STALENESS_FOCUS_GRACE_SECS (default 300s/5min). herdr exposes no queryable focus history, only the current boolean, so recency is reconstructed from the poll already run for each idle candidate - no new loop. An unreadable focus query also blocks (errs toward not reaping); a non-herdr backend is a no-op that leaves the reclaim unchanged; the focus skip never consumes the reclaim retry budget. Manual/--force/--staleness-file-dead teardown paths are untouched - the guard gates only the automatic --staleness-autoclose reap. New read-only backend seam fm_backend_pane_focus_state -> fm_backend_herdr_pane_focus_state reads .result.pane.focused via the socket API using parse_target (never starts a server). Reads the raw boolean, not '.focused // empty', because jq's // treats a literal false as empty and would misclassify an unfocused pane as unknown. Tests: focused->blocked, recently-focused->blocked, stale-unfocused-> reaped, non-herdr->reaped(na), unreadable-focus->blocked, stamp-only-on- real-focus, and a herdr boolean-classification parse test. Docs: AGENTS.md reclaim-exceptions sentence + watcher-internals inventory (.focus-*); docs/architecture.md auto-close backstop paragraph.
…ss focus-guard tunable
…d from unreadable focus so reap never wedges
… so dead panes never wedge
…e recency reap rule
|
Warning Review limit reached
Next review available in: 11 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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe watcher now queries Herdr pane focus and protects focused or recently viewed panes from staleness auto-close. It tracks unreadable focus results with bounded retries, adds configurable grace-period behavior, updates documentation, and adds comprehensive tests. ChangesFocus-aware staleness reclamation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@AGENTS.md`:
- Line 386: Update the watcher sentence in AGENTS.md so all three exclusion
conditions have grammatically compatible subjects: retain the crew conditions
for working and being parked at a captain-relevant gate, and restate the final
condition as the pane being actively or recently viewed by the captain.
In `@bin/fm-watch.sh`:
- Around line 170-179: Validate FM_STALENESS_FOCUS_GRACE_SECS before it is used
by the staleness focus guard, accepting only a numeric value and reverting
malformed or empty overrides to the shipped default of 300 seconds. Ensure
staleness_focus_guard_blocks_reap receives the sanitized value so its integer
comparison continues protecting recently focused panes.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: daef6f3f-b2f5-4930-842c-e70d78da3229
📒 Files selected for processing (7)
AGENTS.mdbin/backends/herdr.shbin/fm-backend.shbin/fm-watch.shdocs/architecture.mddocs/configuration.mdtests/fm-watch-triage.test.sh
…c grammar Address CodeRabbit review on PR #114: - Validate the FM_STALENESS_FOCUS_GRACE_SECS override at load time so a non-numeric or empty value reverts to the shipped 300s default instead of breaking the focus guard's integer age comparison and silently dropping the reclaim protection - reusing the file's existing ''|*[!0-9]* sanitize idiom. - Reword the AGENTS.md staleness-reap sentence so all three exclusion conditions have grammatically compatible subjects (wording only, behavior unchanged). - Add a test: a malformed grace override reverts to 300 and the guard still protects a within-grace pane.
Intent
Guard the firstmate watcher's idle>2h staleness auto-close reap with live pane-focus so a pane a human is actively or recently viewing in its herdr pane is not reclaimed mid-review; plus follow-up review fixes: validate the FM_STALENESS_FOCUS_GRACE_SECS override at load time (non-numeric/empty reverts to the 300s default) and fix the AGENTS.md reap-doc sentence grammar.
What Changed
staleness_focus_stamptouchesstate/.focus-<key>on every idle poll the pane is observed focused, andstaleness_focus_guard_blocks_reapblocks the reclaim while the pane is focused now or was focused withinFM_STALENESS_FOCUS_GRACE_SECS(default 300s); an unreadable focus errs toward not reaping, bounded byFM_STALENESS_AUTOCLOSE_MAX_RETRIESconsecutive unknown polls, whilena/unsupportedbackends skip the guard so a focus-less backend can never wedge the reap. Blocked skips are logged and never consume the retry budget; the focus markers are cleared on hash change and successful reclaim.fm_backend_herdr_pane_focus_state(reading.result.pane.focusedvia the herdr socket API, distinguishingfocused/unfocused/unsupported/unknown) and itsfm_backend_pane_focus_statedispatch wrapper as read-only focus queries.FM_STALENESS_FOCUS_GRACE_SECSoverride at load time (non-numeric or empty reverts to the 300s default), documented the new tunable indocs/configuration.md/docs/architecture.mdand the.focus-*state files inAGENTS.md(also fixing the reap-doc sentence grammar), and addedtests/fm-watch-triage.test.shcoverage for the focus guard.Risk Assessment
✅ Low: The change is a well-bounded, backend-gated guard with a load-time input sanitize and a doc/grammar fix, all three intent requirements are satisfied, control flow and marker lifecycle are correct, and it is covered by behavior-based tests.
Testing
Exercised the focus-guard behavior directly against the real watcher/backend functions rather than source text: 14 new behavioral tests pass and the full fm-watch-triage suite passes 70/0 with the pre-existing non-herdr no-op reap tests intact (no regression). An end-to-end captain-review lifecycle demonstrates a focused or recently-focused herdr pane blocks the idle>2h reclaim (with captain-visible triage-log lines) while a truly-idle pane past the grace window reaps as before, and a 10-input sweep confirms non-numeric/empty FM_STALENESS_FOCUS_GRACE_SECS reverts to 300 at load time while valid digits pass through. The AGENTS.md grammar fix is prose-only and was verified by inspection. This is a CLI/watcher-internal change with no rendered UI surface, so evidence is CLI transcripts rather than screenshots.Evidence: End-to-end captain-review lifecycle (focused->blocked, glance-away within grace->blocked, grace elapsed->reap allowed) with watcher triage-log output
=== Scenario: an idle>2h working: ship pane the captain is actively reviewing in its herdr pane === poll -> live focus reads: focused ; recency marker present: yes RESULT: reclaim BLOCKED (captain keeps the pane mid-review) === Scenario: captain glances away; pane now unfocused but was focused <5min ago === poll -> live focus reads: unfocused ; recency marker still fresh (age 0s < 300s) RESULT: reclaim BLOCKED (grace window forgives the glance-away) === Scenario: grace window elapses (last focus older than 300s), pane truly idle === poll -> live focus reads: unfocused ; recency marker age 3600s >= 300s RESULT: reclaim ALLOWED (nobody watching -> auto-close proceeds as before) === Captain-visible triage log the watcher wrote during the above === [..] staleness auto-close skipped for sess:shipwin:p7 (task task-ship-42): pane is focused by a human [..] staleness auto-close skipped for sess:shipwin:p7 (task task-ship-42): pane focused within 300sEvidence: FM_STALENESS_FOCUS_GRACE_SECS load-time validation across 10 override inputs
OVERRIDE -> EFFECTIVE (unset) -> 300 '' -> 300 '900' -> 900 'not-a-number' -> 300 '300abc' -> 300 '12x3' -> 300 '-5' -> 300 '0' -> 0 ' ' -> 300 '600' -> 600Evidence: Focus-guard targeted subset (14 behavioral tests, all ok)
ok - herdr focus read classifies the four outcomes: focused/unfocused, unsupported on absent key, unknown on failures ok - a currently-focused pane blocks the idle>2h auto-close and records its focus recency ok - a pane focused within STALENESS_FOCUS_GRACE_SECS still blocks the auto-close reclaim ok - an unfocused pane whose last focus is older than the grace window is allowed to reclaim ok - a malformed grace override reverts to 300 and the guard still protects a within-grace pane ok - a focus-unaware backend is a no-op that allows the reclaim exactly as before ok - capability gate: focus-capable herdr blocks the reap; a focus-less herdr build no-ops and allows it ok - an unreadable/timed-out focus query blocks the reclaim, never erroneously reaping ok - consecutive unreadable-focus polls are bounded; a dead pane falls through to reap after the bound ok - a readable focused poll resets the unknown-focus bound so a transient blip stays protective ok - a readable not-focused poll resets the unknown-focus bound and the reap proceeds ok - the unknown fall-through keeps blocking at the bound while the within-grace focus marker is fresh ok - the unknown fall-through reaps at the bound once the focus marker has aged past the grace window ok - the focus stamp records recency only on a real observed focusEvidence: Full fm-watch-triage suite log (70 ok, 0 failures)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-watch-triage.test.sh— full suite: 70 ok, 0 failures, exit 0 (includes pre-existing non-herdr no-op reap integration tests, confirming no regression)Focus-guard targeted subset (14 tests) via a temp copy of the test file:test_herdr_pane_focus_state_classifies_boolean,test_focus_guard_blocks_focused_pane,test_focus_guard_blocks_recently_focused_pane,test_focus_guard_allows_stale_unfocused_pane,test_focus_guard_malformed_grace_falls_back_to_default,test_focus_guard_allows_non_herdr_backend,test_focus_guard_capability_gated_pair,test_focus_guard_blocks_on_unreadable_focus,test_focus_guard_bounds_persistent_unknown,test_focus_guard_unknown_reset_by_focused,test_focus_guard_unknown_reset_by_unfocused,test_focus_guard_unknown_within_grace_stays_blocked,test_focus_guard_unknown_aged_marker_reaps_at_bound,test_focus_stamp_only_records_real_focus— all ok, exit 0End-to-end captain-review lifecycle driven through the real sourced fm-watch.sh functions (herdr backend + controllable focus signal): focused->BLOCKED, unfocused-but-within-grace->BLOCKED, marker aged 3600s->ALLOWED; captured the watcher's triage-log outputFM_STALENESS_FOCUS_GRACE_SECS load-time sanitization across 10 override inputs (unset/''/900/not-a-number/300abc/12x3/-5/0/' '/600) by sourcing bin/fm-watch.sh and reading the effective STALENESS_FOCUS_GRACE_SECSVerified AGENTS.md reap-doc grammar fix by inspecting the diff (prose change; no behavioral test applicable)Confirmed[: : integer expectedstderr originates in unchanged fleet auto-discovery code present on base commit f2fbaca (git show f2fbaca:bin/fm-watch.sh), unrelated to this change✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.