Repository navigation
feat(bin): alert the captain when dispatch halts, add a captain-queue constraint - #8145
Open
charlesdr13 wants to merge 3 commits into
Open
charlesdr13 wants to merge 3 commits into
charlesdr13 wants to merge 3 commits into
Conversation
added 2 commits
November 4, 2026 19:26
…queue constraint When lanes are under the cap but a host or captain-queue constraint admits nothing while ready work waits, the watcher raises one check wake after FM_CAPACITY_HALT_ALERT_SECS (default 1800s, 0 off), naming each constraint, its value and a fix, and re-raises at most once per 24h. New optional max-captain-holds key in config/lane-capacity holds new dispatch while open captain holds exceed it; unset keeps today's behaviour.
…p ledger on read failure
[Medium impact] The PR appears safe to merge; all three previous findings are addressed and no new actionable issue was found. Reviews (2) · Last reviewed commit: "fix(capacity): announce a halt alert onl..." · Reviewed by Greptile |
…ip stale facts, write the ledger atomically Addresses review on kunchenguid#8145: CAPACITY_HALT_ALERT is set only after fm_wake_append succeeds; lane facts older than 5 minutes (generated_epoch vs the wall clock) are skipped and keep the debounce record; the ledger is written to a temp file and renamed, like open_decision_reminder_tick.
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.
Intent
Follow-up on upstream PR #8145 (dispatch-halt alert + captain-queue constraint), fixing the three Greptile review findings: (P1) CAPACITY_HALT_ALERT must be set only after fm_wake_append succeeds, so a failed queue write never takes the successful wake path; (P2) lane-capacity facts older than 5 minutes, judged by generated_epoch against the real wall clock rather than file mtime (so the test's fake uname/stat does not matter), are skipped and the debounce ledger is preserved; (P2) the ledger is written to a temp file and renamed over, as open_decision_reminder_tick does. Tests: stale facts raise no alert and keep the ledger (fails before the fix), a read-only wake queue announces nothing and keeps the ledger. Original intent unchanged: loud, debounced, once-a-day alert when ready work is blocked by a non-full constraint; optional max-captain-holds constraint, unset keeps today's behaviour; all dispatch held under captain-queue because the verdict is per home. Push to the fork branch only; never push to or merge upstream main. No AI co-author or Generated-with lines. CI on upstream needs maintainer approval for first-time contributor workflows, so CI waiting on approval is expected.
What Changed
bin/fm-watch.sh: newcapacity_halt_alert_tickruns on every watcher loop. It fires when lanes are under the cap but a constraint (anything except a full cap) blocks dispatch whiletasks-axi readystill lists work. Once that has lastedFM_CAPACITY_HALT_ALERT_SECS(default 1800;0turns it off), it queues one captain-facingcheck: dispatch halted ...wake. The wake names each constraint and a one-line fix, and repeats at most once every 24 h. Lane-capacity facts whosegenerated_epochis more than 5 minutes behind the wall clock are skipped, and the<since> <last-alert>timing file (the ledger) is left as it is. The alert is set only afterfm_wake_appendsucceeds. The ledger is written to a temp file and renamed over the old one, and it is removed when the halt or the ready work clears.bin/fm-capacity.sh: new opt-inmax-captain-holdskey inconfig/lane-capacity. When it is set, the script counts open captain holds throughfm-tasks-axi.sh list --state heldand adds acaptain-queueconstraint when the count goes over the limit. The verdict is per home, so this holds every new dispatch. If the key is unset or the backlog can't be read, nothing changes. Probe constraint reasons now also state their threshold (core count,MEM_FREE_MIN_PCT,DISK_FREE_MIN_MB).docs/configuration.mddocumentsmax-captain-holdsand the dispatch-halt alert.tests/fm-capacity.test.shadds tests for the new paths, including: stale facts raise no alert and keep the ledger, and a read-only wake queue announces nothing and keeps the ledger.Risk Assessment
✅ Low: All three Greptile fixes are in place and covered by behavioural tests. The alert is set only after fm_wake_append succeeds. Facts older than 300 s, judged by generated_epoch against the real clock, return before the ledger is touched. The ledger is written to a temp file and renamed over, the same way open_decision_reminder_tick does it. The captain-queue count parses tasks-axi output correctly, including titles with commas and 30+ rows (checked against the real tasks-axi), and an unset key changes nothing.
Testing
I ran the targeted fm-capacity test file on the fix commit and on the pre-fix watcher. The stale-facts test fails before the fix and passes after it. I then ran the real fm-watch.sh daemon in a throwaway lab home with a real backlog and a real captain-queue config. With one captain hold over the limit and one ready item, it sent one alert naming each constraint with its value, threshold and fix. It sent no second alert after a restart. The ledger cleared once no work was ready. With a read-only wake queue it logged a failed check, sent no alert and kept the ledger. Once the queue was writable again, it sent the alert. All four live scenarios passed. Three scenarios were covered only by the test suite, not live, so they are marked untested: stale facts, the max-captain-holds edge cases, and the full lane cap. The lab is removed and the worktree is clean.
Evidence: Targeted test run on the fix commit
Source: Targeted test run on the fix commit
Evidence: Same tests against the pre-fix watcher: stale-facts test fails
Source: Same tests against the pre-fix watcher: stale-facts test fails
not ok - facts older than 5 minutes must not raise an alert (expected '', got 'check: dispatch halted for 88200s with 1 ready: memory: 5% free, under 10% [fix: free memory]')Evidence: Live watcher: captain-queue halt raises one alert with thresholds and fixes
Source: Live watcher: captain-queue halt raises one alert with thresholds and fixes
check: dispatch halted for 3s with 1 ready: disk: 5117 MB free, under 5120 MB [fix: free disk space]; captain-queue: 1 open captain holds, over max-captain-holds 0 [fix: answer open captain holds, or raise max-captain-holds]Evidence: Live watcher re-armed: no second alert within 24h, ledger kept
Source: Live watcher re-armed: no second alert within 24h, ledger kept
Evidence: Live watcher: no ready work clears the ledger
Source: Live watcher: no ready work clears the ledger
Evidence: Live watcher: read-only wake queue sends no alert and keeps the ledger; alert sent once writable
Source: Live watcher: read-only wake queue sends no alert and keeps the ledger; alert sent once writable
watcher: dispatch-halt alert check failed watcher stdout contains capacity alert? 0 ledger after: 1793793067 0 ... re-arm: check: dispatch halted for 112s with 1 ready: disk: 5084 MB free, under 5120 MB [fix: free disk space] ledger: 1793793067 1793793179Pipeline
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-capacity.test.shon the fix commit (all pass, including test_captain_queue_constraint and test_dispatch_halt_alert)bash tests/fm-capacity.test.shwith bin/fm-watch.sh temporarily swapped to f25e4d75 (pre-fix): fails 'facts older than 5 minutes must not raise an alert'; file restored afterwardsLive: bin/fm-lab-home.sh create lab; config/lane-capacity '4 / max-captain-holds 0'; real backlog with one captain hold and one ready ship item; real bin/fm-watch.sh with FM_CAPACITY_HALT_ALERT_SECS=3, FM_POLL=1Live: re-armed the watcher after its wake to check the once-per-24h rule across a restartLive: moved all ready work to in-flight and re-armed the watcher: ledger removedLive adversarial: made the wake queue read-only with the halt past its window; re-armed the watcher; then made the queue writable again and re-armedTeardown: rm -rf lab home; git status clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.