Skip to content

feat(bin): alert the captain when dispatch halts, add a captain-queue constraint - #8145

Open
charlesdr13 wants to merge 3 commits into
kunchenguid:mainfrom
charlesdr13:feat/capacity-halt-alert
Open

charlesdr13 wants to merge 3 commits into
kunchenguid:mainfrom
charlesdr13:feat/capacity-halt-alert

Conversation

@charlesdr13

@charlesdr13 charlesdr13 commented Nov 4, 2026 •

Copy link
Copy Markdown

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: new capacity_halt_alert_tick runs on every watcher loop. It fires when lanes are under the cap but a constraint (anything except a full cap) blocks dispatch while tasks-axi ready still lists work. Once that has lasted FM_CAPACITY_HALT_ALERT_SECS (default 1800; 0 turns it off), it queues one captain-facing check: dispatch halted ... wake. The wake names each constraint and a one-line fix, and repeats at most once every 24 h. Lane-capacity facts whose generated_epoch is 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 after fm_wake_append succeeds. 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-in max-captain-holds key in config/lane-capacity. When it is set, the script counts open captain holds through fm-tasks-axi.sh list --state held and adds a captain-queue constraint 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.md documents max-captain-holds and the dispatch-halt alert. tests/fm-capacity.test.sh adds 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.

  • Live validation: ✅ go - 4 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Captain holds over max-captain-holds with ready work: the real watcher sends one 'dispatch halted' check wake naming each constraint, its value vs threshold, and a fix ✅ pass live live-watcher-captain-queue-halt.txt
Watcher re-armed while the halt persists: no second alert within 24h, and the debounce ledger survives the restart ✅ pass live live-watcher-rearm-and-clear.txt
No ready work left (count: 0): the ledger is removed so a later halt starts a fresh 30-minute wait ✅ pass live live-watcher-ready-cleared.txt
Adversarial P1: wake queue is read-only when the alert is due: no alert sent, tick reports a failure, ledger keeps last-alert=0; once the queue is writable the alert is sent ✅ pass live live-watcher-readonly-queue.txt; tests/fm-capacity.test.sh test_dispatch_halt_alert
Adversarial P2: lane facts whose generated_epoch is older than 5 minutes raise no alert and keep the ledger (fails before the fix) ⏸️ untested no The prior payload did not establish a live result. The live watcher republishes facts every 30 s, so this was covered only by the targeted test (fm-capacity-test-after.txt vs fm-capacity-test-before-f…
max-captain-holds unset changes nothing; at the threshold it does not constrain; other hold kinds do not count; a malformed value is refused ⏸️ untested no The prior payload did not establish a live result. Covered only by tests/fm-capacity.test.sh test_captain_queue_constraint; the live run covered just the 'over the limit' case
A full lane cap with ready work never raises the alert ⏸️ untested no The prior payload did not establish a live result. Covered only by tests/fm-capacity.test.sh test_dispatch_halt_alert; not repeated in the lab
Evidence: Targeted test run on the fix commit

Source: Targeted test run on the fix commit

ok - absent config/lane-capacity reports counts and no target
ok - the Constrained line is printed only when config/lane-capacity exists
ok - a target yields open lanes, full, and never a negative count
ok - cpu, memory, and disk pressure close every lane and are named
ok - unavailable probes print unknown and do not constrain
ok - a malformed target is reported, not guessed
ok - keyed config lines parse, and unknown, repeated, or malformed lines are refused
ok - a fresh beat replaces probes, and its warn level closes lanes with its reason
ok - late beats count, and stale, missing, malformed, or foreign beats fall back to probes
ok - several pressure files: worst level wins, first supplies memory, every disk counts
ok - a beat with missing fields keeps its fields aligned and limits fall back to probes
ok - the lane footprint memory rule applies only with min-avail-gb
ok - limits close lanes with named reasons, and --admit exits 0, 75, or 1
ok - publish is opt-in, private, throttled, records boots, and publishes an invalid config as invalid
ok - captain presence and quota runway publish derived words only, unknown when unreadable
ok - the watcher publishes lane facts only for an opted-in home
ok - captain-queue constrains only when max-captain-holds is set and exceeded
~/.no-mistakes/worktrees/680eb455bb43/01M6K64E7BSSDRVGXBZPM024ZV/bin/fm-wake-lib.sh: line 2696: /tmp/fm-capacity.tj4bPc/halt/state/.wake-queue: Permission denied
ok - the dispatch-halt alert debounces, re-raises once a day, clears, and ignores a full cap
ok - real host probes produce a well-formed report
# all fm-capacity tests passed
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]')

ok - absent config/lane-capacity reports counts and no target
ok - the Constrained line is printed only when config/lane-capacity exists
ok - a target yields open lanes, full, and never a negative count
ok - cpu, memory, and disk pressure close every lane and are named
ok - unavailable probes print unknown and do not constrain
ok - a malformed target is reported, not guessed
ok - keyed config lines parse, and unknown, repeated, or malformed lines are refused
ok - a fresh beat replaces probes, and its warn level closes lanes with its reason
ok - late beats count, and stale, missing, malformed, or foreign beats fall back to probes
ok - several pressure files: worst level wins, first supplies memory, every disk counts
ok - a beat with missing fields keeps its fields aligned and limits fall back to probes
ok - the lane footprint memory rule applies only with min-avail-gb
ok - limits close lanes with named reasons, and --admit exits 0, 75, or 1
ok - publish is opt-in, private, throttled, records boots, and publishes an invalid config as invalid
ok - captain presence and quota runway publish derived words only, unknown when unreadable
ok - the watcher publishes lane facts only for an opted-in home
ok - captain-queue constrains only when max-captain-holds is set and exceeded
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]

## lab home: /tmp/fm-lab.xNru0t
## config/lane-capacity:
4
max-captain-holds 0
## tasks-axi ready:
count: 1
ready[1]{id,state,kind,repo,title}:
  r1,queued,ship,"-",ready ship work
ready_public_followups: 0 delivery-ready obligations
help[1]:
  - Run `tasks-axi start <id>` to dispatch one of these
## fm-capacity.sh --admit:
deferred: lane capacity of this home (/tmp/fm-lab.xNru0t/config/lane-capacity) does not admit another lane: disk: 5117 MB free, under 5120 MB; captain-queue: 1 open captain holds, over max-captain-holds 0
exit=75
## start real watcher (FM_CAPACITY_HALT_ALERT_SECS=3, FM_POLL=1)
## after 6s, wake queue entries for capacity-halt:
1793792981	1	check	capacity-halt	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]
## ledger:
1793792978 1793792981
## after 6 more seconds, alert count (debounce: must stay 1):
1
## answer the captain hold
## after 60s: ledger present? yes; verdict:
{"admit":false,"free_lanes":0,"reasons":["disk: 5117 MB free, under 5120 MB","captain-queue: 1 open captain holds, over max-captain-holds 0"]}
## alert count still: 1
## watcher stderr (halt-related):
(none)
Evidence: Live watcher re-armed: no second alert within 24h, ledger kept

Source: Live watcher re-armed: no second alert within 24h, ledger kept

## run 2: re-arm the real watcher (the watcher exits after delivering a wake); captain hold already answered, disk constraint still real
## ledger before: 1793792978 1793792981
## after 12s: republished verdict: ["disk: 5113 MB free, under 5120 MB"]
## capacity-halt wakes queued: 1 (must stay 1: at most once per 24h)
## ledger: 1793792978 1793792981
## complete the only ready item
count: 1
## after 30s: ledger present? yes (must be no: ready work cleared)
## watcher stdout (should be empty, no new alert): [check: rearm-resurface]
Evidence: Live watcher: no ready work clears the ledger

Source: Live watcher: no ready work clears the ledger

## run 3: the unheld q1 itself became ready work, so start it too; ready list now:
count: 0
## ledger before: 1793792978 1793792981; verdict still constrained: ["disk: 5113 MB free, under 5120 MB"]
## after 2s: ledger present? no (must be no: ready work cleared, halt debounces afresh)
## capacity-halt wakes queued: 1
## watcher stdout: [check: rearm-resurface]
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 1793793179

## run 4 (adversarial): new ready work, prior ledger seeded as an old halt already past the window, wake queue read-only
count: 1
## ledger seeded: 1793793067 0
## watcher stderr (halt lines):
      1 ~/.no-mistakes/worktrees/680eb455bb43/01M6K64E7BSSDRVGXBZPM024ZV/bin/fm-wake-lib.sh: line 2696: /tmp/fm-lab.xNru0t/state/.wake-queue: Permission denied
      1 watcher: dispatch-halt alert check failed
## watcher stdout contains capacity alert? 0
## ledger after (must still be '<since> 0', no alert recorded): 1793793067 0
## run 5: queue writable again, re-arm: the alert must now be delivered
## watcher stdout: check: dispatch halted for 112s with 1 ready: disk: 5084 MB free, under 5120 MB [fix: free disk space]
## ledger: 1793793067 1793793179

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.

  • Live validation: ✅ go - 4 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Captain holds over max-captain-holds with ready work: the real watcher sends one 'dispatch halted' check wake naming each constraint, its value vs threshold, and a fix ✅ pass live live-watcher-captain-queue-halt.txt
Watcher re-armed while the halt persists: no second alert within 24h, and the debounce ledger survives the restart ✅ pass live live-watcher-rearm-and-clear.txt
No ready work left (count: 0): the ledger is removed so a later halt starts a fresh 30-minute wait ✅ pass live live-watcher-ready-cleared.txt
Adversarial P1: wake queue is read-only when the alert is due: no alert sent, tick reports a failure, ledger keeps last-alert=0; once the queue is writable the alert is sent ✅ pass live live-watcher-readonly-queue.txt; tests/fm-capacity.test.sh test_dispatch_halt_alert
Adversarial P2: lane facts whose generated_epoch is older than 5 minutes raise no alert and keep the ledger (fails before the fix) ⏸️ untested no The prior payload did not establish a live result. The live watcher republishes facts every 30 s, so this was covered only by the targeted test (fm-capacity-test-after.txt vs fm-capacity-test-before-f…
max-captain-holds unset changes nothing; at the threshold it does not constrain; other hold kinds do not count; a malformed value is refused ⏸️ untested no The prior payload did not establish a live result. Covered only by tests/fm-capacity.test.sh test_captain_queue_constraint; the live run covered just the 'over the limit' case
A full lane cap with ready work never raises the alert ⏸️ untested no The prior payload did not establish a live result. Covered only by tests/fm-capacity.test.sh test_dispatch_halt_alert; not repeated in the lab
  • bash tests/fm-capacity.test.sh on the fix commit (all pass, including test_captain_queue_constraint and test_dispatch_halt_alert)
  • bash tests/fm-capacity.test.sh with bin/fm-watch.sh temporarily swapped to f25e4d75 (pre-fix): fails 'facts older than 5 minutes must not raise an alert'; file restored afterwards
  • Live: 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=1
  • Live: re-armed the watcher after its wake to check the once-per-24h rule across a restart
  • Live: moved all ready work to in-flight and re-armed the watcher: ledger removed
  • Live 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-armed
  • Teardown: rm -rf lab home; git status clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

charlesdr13 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.
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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

Comment thread bin/fm-watch.sh Resolved
Comment thread bin/fm-watch.sh Resolved
Comment thread bin/fm-watch.sh Resolved
…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.
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