Repository navigation
feat(bin): add armable daily startup growth check - #6725
kunchenguid merged 14 commits into
Conversation
…lines, drop knobs
…, register artifacts
|
| if ! now=$(check_due); then | ||
| return 0 | ||
| fi | ||
| [ -d "$STATE" ] && [ ! -L "$STATE" ] || fail "state directory is unavailable" | ||
| sweep_orphan_records "$now" | ||
| OLD_RECORD=$RECORD | ||
| record_usable || OLD_RECORD=/dev/null | ||
| reported_previous=$(awk -F '\t' '$1 == "reported" { print substr($0, index($0, "\t") + 1); exit }' "$OLD_RECORD" 2>/dev/null || true) |
There was a problem hiding this comment.
Overlapping checks repeat reports
If an operator runs check while the watcher evaluates the same home, both can pass check_due before either publishes its record. They can report the same growth and read baselines while the other replaces the shared record. Hold a home-local lock from the daily gate through publication.
| if [ -n "$ARM_BACKUP" ]; then | ||
| mv -f -- "$ARM_BACKUP" "$CHECK_SHIM" 2>/dev/null || rm -f -- "$ARM_BACKUP" | ||
| ARM_BACKUP= | ||
| if fm_custom_check_registered "$STATE" "$CHECK_ID"; then | ||
| return 0 | ||
| fi | ||
| fi | ||
| rm -f -- "$CHECK_SHIM" "$CHECK_TRUST" |
There was a problem hiding this comment.
Interrupted re-arm disables monitoring
arm_rollback restores only the old shim, not its trust binding. When re-arming changes the shim, a signal after registration publishes the new trust but before the trap is cleared restores the old shim against the new trust. The match fails, so rollback deletes both files and disables the previously working check. Save and restore the trust binding together with the shim.
| rm -f -- "$CHECK_SHIM" "$CHECK_TRUST" "$RECORD" | ||
| printf 'disarmed: state/%s.check.sh\n' "$CHECK_ID" |
There was a problem hiding this comment.
disarm prints success and returns zero even when rm fails. If the state directory becomes unwritable, the shim and trust can remain active while the operator is told monitoring has stopped. Check the removal result and return an error before printing success.
| rm -f -- "$CHECK_SHIM" "$CHECK_TRUST" "$RECORD" | |
| printf 'disarmed: state/%s.check.sh\n' "$CHECK_ID" | |
| rm -f -- "$CHECK_SHIM" "$CHECK_TRUST" "$RECORD" || fail "could not disarm the check" | |
| printf 'disarmed: state/%s.check.sh\n' "$CHECK_ID" |
|
|
||
| if [ -n "$FINDINGS" ]; then | ||
| if [ "$FINDINGS" != "$reported_previous" ]; then | ||
| fm_cap_line "startup-growth: $FINDINGS" "$MAX_LINE" |
There was a problem hiding this comment.
Failed reports become suppressed
The result of fm_cap_line is ignored. If stdout cannot accept the report, such as when the watcher's capture file runs out of disk space, the check still publishes reported and rebases the growth baselines. Later checks suppress a finding that was never delivered. Stop before publishing the record when fm_cap_line fails.
| fm_cap_line "startup-growth: $FINDINGS" "$MAX_LINE" | |
| fm_cap_line "startup-growth: $FINDINGS" "$MAX_LINE" || fail "could not deliver report" |
…iled on tests/fm-contributions.test.sh in test_arm_plumbs_a_configured_budget_into_the_check_shim (inherited mode) with "generated check did not attempt a read" and a missing forge/calls file. Root cause: bin/fm-contributions.sh:379-382 computes DEADLINE=$(date +%s)+BUDGET and then gates each read on DEADLINE-$(date +%s) >= OBSERVATION_RESERVE (= min(BUDGET,15)). At the one-second budget this test uses, that gate demands zero elapsed whole seconds, so a wall-clock second boundary crossing between the two date calls makes the poll loop break before any forge read. The test calls wrap_forge (which installs a fake date reading $FORGE/clock only when that file exists) but never seeded forge/clock, so it ran against the real clock. The repo already documents this exact hazard at tests/fm-contributions.test.sh:675-677 and freezes the clock in every other budget-constrained test: test_budget_exhaustion_keeps_prior_record (both modes), test_genuine_failure_near_deadline_is_unavailable, test_reservation_defers_later_url_when_fifteen_seconds_do_not_remain, test_slow_read_deadline_kill_is_budget_refusal, test_budget_is_cut_down_to_the_watcher_check_bound. test_arm_plumbs was the only omission; its single loop body covers both the configured and inherited modes. The remaining wrap_forge users run the default 20-second budget (5 seconds of slack above the reserve) and are not reachable by this race. Fix (smallest, matching the sibling idiom): added the clock freeze `/bin/date +%s > "$home/forge/clock"` plus a two-line comment inside that test's loop, before the poll. Three added lines in tests/fm-contributions.test.sh; no production code and no other file touched. Verification: reproduced the exact CI failure message by running a scratch copy whose fake date advances one second per read (worst case of the unfrozen clock) - missing forge/calls, "not ok - generated check did not attempt a read". With the fix, the single test passes 10/10 standalone and the full tests/fm-contributions.test.sh passes all 46 assertions with exit 0. tests/fm-startup-growth-check.test.sh still exits 0. bash -n and shellcheck -S warning are clean on the edited file; scratch repro files were removed, leaving only the intended three-line change. Note for the author: this flake is not caused by this branch - tests/fm-contributions.test.sh is untouched by the PR and the race is pre-existing, surfacing only on a loaded runner (the shard's neighbouring assertions show 80+ second gaps). It was fixed because it is genuine nondeterminism with an established in-repo remedy and the check cannot otherwise go green. No work was done on the unselected greptile findings (ci-2..ci-5) or the cancelled "Behavior portable serial 2" check (ci-6)
…log section (fetched with gh api) shows the shard failed on tests/fm-calm-pi-extension.test.sh in test_hidden_block_geometry_e2e with "Pi Calm hidden-block geometry E2E did not complete the /reload viewport transition" (exit=1, duration_ms=23437; the family line pure-contract-unit count=3 duration_ms=51193 failed=1 matches devin-harness 3203 + calm-pi 23437 + task-delivery 24553). Root cause: tests/fm-calm-pi-extension.test.sh:2831 wait_for_geometry_transition detected the /reload by SAMPLING a single intermediate frame - it polled tmux capture-pane for Pi's transient "Reloading keybindings, extensions, skills, prompts, themes, and context files..." box and only accepted the rebuilt transcript afterwards (elif gated on saw_transient). Pi shows that box only while the reload runs and replaces it via dismissReloadBox when done, so on a loaded runner the box can live entirely between two polls; saw_transient then stays 0 forever and the 600-attempt wait times out although the reload fully succeeded. Reproduced locally under CPU oversubscription with CI's Pi 1.0.4: 1 failure in 8 runs, diagnostics proving the mechanism ("DIAG: transition timeout saw_transient=0 attempt=600") while the captured viewport already showed the completed reload status row and the intact collapsed transcript. Not a Pi-version regression: 1.0.4's handleReloadCommand and both banner strings are identical to the installed 0.85.1, and shard 6 of the previous pipeline run (job 112490351105) passed this same script on Pi 1.0.4. Invariant violated: a TUI E2E assertion must key off a durable state the UI retains, never off one intermediate frame polling may miss. Sibling enumeration: the helper was defined once and called once; grep for transient/saw_/two-stage waits across tests/, bin/ and .pi/ found no other one-shot-frame wait - every other wait in the file keys off durable text presence/absence or off continuously repeating animation frames (the working-ship motion checks) where sampling eventually connects; no doc or other test referenced the helper. Fix (smallest, one helper): renamed it wait_for_geometry_reload and made it wait for the durable status row Pi appends once the reload completed and the chat was rebuilt ("Reloaded keybindings, extensions, skills, prompts, themes, and context files", a persistent chat child via showStatus, present in both 0.85.1 and 1.0.4) together with CALM_GEOMETRY_FINAL. That marker is absent before the reload and never appears if the reload throws, so the check is strictly stronger than before (a failed reload now fails the test instead of passing on transient-then-final). One file changed: tests/fm-calm-pi-extension.test.sh, 2 hunks, no production code. Verification: deterministic before/after - with polls spaced 0.4s apart (the loaded-runner worst case) the pre-fix helper fails with exactly the CI message and the post-fix helper passes; 12/12 consecutive passes of the isolated test under load with Pi 1.0.4; full file 15/15 ok exit 0 under LANG=C.utf8 (matching the runner locale); bash -n, shellcheck -S warning and bin/fm-lint.sh clean; scratch repro files and the temp Pi 1.0.4 install removed, git status shows only the one intended modification. Notes: (1) the flake is not caused by this branch - that test file is untouched by the PR and the race is pre-existing; fixed because it is genuine nondeterminism and the check cannot otherwise go green. (2) Under far harsher load than CI applies a separate unrelated flake appeared in the same test: Pi's "Warning: tmux extended-keys is off..." row occasionally lands between the collapsed [skill] ahoy row and the final response, making assert_geometry_gap see 5 rows instead of 2. Different cause, never seen in CI, and its plausible remedies would change key delivery for the other TUI tests in the file, so it was left alone rather than growing this fix
commented
Oct 6, 2026
|
Speaking as Kun's firstmate: reviewed head What I checked:
Contract-class: opt-in. Nothing runs until VISION.md, rule by rule
Optional follow-ups from Greptile's open P2s, none blocking: make Squash-merging. |
commented
Oct 6, 2026
|
Speaking as Kun's firstmate: this is merged. Thank you @Freudator86 — really appreciate you taking the time on this. |
Intent
cadence checks on growing start up scripts and learning files etc.... they shouldnt be loaded too mcuh and use too much
yes use daily chceks
The accepted daily check should check file sizes and changes first, inspect contents only when needed, flag meaningful growth in startup scripts/instructions/memory, stay silent when unchanged without repeated full rereads, and keep old bulk learning files reference-only rather than automatically loaded or merged.
What Changed
bin/fm-startup-growth-check.shwithcheck,arm, anddisarmsubcommands:armwrites astate/startup-growth.check.shshim bound through the existing authenticated watcher-check registration (no new daemon or scheduler), andcheckgates itself to one evaluation per 86400 seconds, reading only its own small.startup-growth-checkrecord on polls inside that interval.stat(1)byte sizes — overAGENTS.md,CLAUDE.md,bin/fm-session-start.sh,bin/fm-bootstrap.sh,bin/fm-supervision-instructions.sh, the session-printeddata/projects.mdanddata/secondmates.md, and the budget-owneddata/captain.md,data/captain-shared.md, anddata/learnings.md; the budget total and verdict are delegated tobin/fm-startup-memory-budget.sh reportrather than re-derived. Growth is compared against per-file baselines retained in the record (2048 bytes for tracked files, 250 estimated tokens for printed memory), first sightings are baselined silently, findings are deduplicated against the last reported set, reporting rebases the baseline, the single report line goes out through the sharedfm_cap_linedigest cut before the record is published, and a secondmate home is not woken about the primary-owneddata/captain-shared.md. Due evaluations also sweep aged empty temp records left by killed runs.docs/configuration.md("Daily startup growth check", including the watcher-retention implication), listed the script indocs/scripts.md, registered the shim and record in theoperational-home-layoutskill's state inventory, and addedtests/fm-startup-growth-check.test.shwith 23 cases covering the daily gate, cumulative growth, optional-file and baseline-restoration behavior, secondmate suppression, unsafe/unreadable inputs, line capping, foreign-schema records, publish-failure delivery, interrupted evaluations, orphan sweeping, and arm/disarm/re-arm failure paths.Risk Assessment
✅ Low: A self-contained, opt-in, metadata-only daily check that writes nothing but its own private 0600 state record and emits at most one capped wake line per day; its logic, baseline retention, record schema guard, arm rollback, and signal handling all trace correctly, and the watcher already ignores the check's exit status.
Testing
I ran the change's own targeted suite as a baseline, then drove every scenario against the real product: the daily check armed into disposable lab homes and dispatched by the actual bin/fm-watch.sh, never a stub. The watcher baselined silently, stayed silent and re-read nothing inside the day, surfaced 2500 bytes of AGENTS.md growth and 900 bytes of learnings growth as a wake line a day later, reported a budget overrun, suppressed the repeat of an unchanged finding, and stopped dispatching after disarm. Syscall traces back the cheapness claim: a gated poll runs in 18 ms touching only its own state record, and a 5.4 MB historical learnings file is reported as prompt cost while the whole evaluation reads 212 KB and never opens a tracked instruction file. For the commit under test I raced SIGTERM into the mktemp window to produce a genuine leaked scratch record, confirmed it survives inside the one-hour grace and is reclaimed by the next due evaluation, and confirmed the sweep's bounds — byte-bearing scratch, a live sibling's fresh scratch, a non-matching name, and a symlink all survive, and a same-day poll sweeps nothing. 150 mid-flight kills published no partial record and lost no retained baseline. This is a CLI/watcher change with no rendered UI surface, so the evidence is CLI transcripts, persisted state records, and syscall traces rather than screenshots. All lab homes were torn down in the same turn and the worktree is clean.
FM_HOME=<lab> bin/fm-startup-growth-check.sh armthenbin/fm-watch.sh; startup-growth-watcher-transcript.txt — shim (0700) and trust binding written, watcher dispatches it with no "rejected" diagn…startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh.aaaaaaremoved; byte-bearing.bbbbbb, fresh live.cccccc, wrong-pattern.ddddddd, and symlink.ffffffplus its target all kept, while the e….startup-growth-check.2SWcFc(mode 600, 0 bytes) with the previous record untouched; kept while inside the grace, recl…unsafe tracked AGENTS.md, zero openat calls naming the symlink target, and the retained baseline survives in the record+400 estimated_tokensin a primary home and prints nothing in a secondmate home, while both record…bin/fm-startup-growth-check.sh --helpprints through the new sweep paragraph and ends at the disarm sentence with no code body leaking; an unknown verb exits 2Evidence: Real watcher transcript: arm, silent baseline, same-day gating, growth wake, dedupe, overrun, disarm
Source: Real watcher transcript: arm, silent baseline, same-day gating, growth wake, dedupe, overrun, disarm
Evidence: Syscall evidence that the check is metadata-first and never loads a 5.4 MB learnings file
Source: Syscall evidence that the check is metadata-first and never loads a 5.4 MB learnings file
Evidence: Orphan temp-record sweep, including a genuinely raced SIGTERM leak reclaimed after its grace
Source: Orphan temp-record sweep, including a genuinely raced SIGTERM leak reclaimed after its grace
Evidence: 150 SIGTERM-interrupted evaluations: no partial record published, no retained baseline lost
Source: 150 SIGTERM-interrupted evaluations: no partial record published, no retained baseline lost
Evidence: Secondmate is not nagged about the primary-owned shared memory file, while a primary is
Source: Secondmate is not nagged about the primary-owned shared memory file, while a primary is
Evidence: The growth wake an operator actually sees from the watcher
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
🔧 **Test** - 1 issue found → auto-fixed ✅
bin/fm-startup-growth-check.sh:246- A TERM arriving in the narrow window where the daily check'smktempchild is running — after the temp record exists but before the EXIT/HUP/INT/TERM traps at bin/fm-startup-growth-check.sh:247-248 are installed — leaves a 0-byte, mode-600state/.startup-growth-check.XXXXXXbehind, and nothing ever sweeps it. Measured live: 200 TERM-interrupted evaluations of the armed shim leaked 2 such files (~1% of interrupts). The invariant that matters held in every one of the 200 runs — no partial record was ever published and no retained baseline was lost — and the repo's own test pins the no-leftover invariant (tests/fm-startup-growth-check.test.sh,an interrupted evaluation left its temporary record behind) but interrupts only inside the budget call, so it cannot reach this window. Flagging rather than auto-fixing because there is no safe reorder: a trap installed beforemktempstill runs with NEW_RECORD unset, so the real remedy is a leftover-rotation sweep like the one bin/fm-wake-drain.sh already does for its own scratch files, which is a design call. Evidence: interrupt-fuzz.txt.bin/fm-startup-growth-check.sh armthen a 25sbin/fm-watch.shrun in the lab home: no wake, and state/.startup-growth-check holds all ten surfaces plus the budget verd…tracked startup surface growth bin/fm-bootstrap.sh +2500 bytes (total 80324 bytes)+2100 bytesagainst the retained baselinestartup memory budget overrun total_estimated_tokens=10002 budget=7500 owner=bin/fm-startup-memory-budget.sh, identical to `bin/fm-sta…unsafe tracked AGENTS.mdon the next due day, with no missing-file noise for the optional memory files, and the finding clear….fm-secondmate-homepresent the watcher stayed silent yet still recorded the observation and the owner's `primary-owned…check: rejected unauthenticated state checks: .../startup-growth.check.shand t…disarmleft no startup-growth artifact in state/, and a later watcher sweep over a 9000-byte AGENTS.md growth produced neither a finding nor an unauthenticated-check rejectionbash tests/fm-startup-growth-check.test.sh(repo's own suite for the changed script, 21 cases)bin/fm-lab-home.sh create $LABplus a byte copy of the tracked tree as$LAB/root— a disposable install of the real product$LAB/root/bin/fm-startup-growth-check.sh arm/disarmin the lab homeFM_HOME=$LAB FM_POLL=1 FM_CHECK_INTERVAL=0 FM_STARTUP_GROWTH_NOW=<epoch> $LAB/root/bin/fm-watch.sh— 18 real watcher sweeps across simulated days$LAB/root/bin/fm-wake-drain.shand--ack-through <seq> --recovery-generation <gen>— the agent-facing wake view and acknowledgement$LAB/root/bin/fm-startup-memory-budget.sh report— cross-checked the overrun totals the check relays against the owner's own reportstrace -f -e trace=openat,open,read,statx,newfstatat,stat $LAB/state/startup-growth.check.sh— syscall proof that no content bytes of AGENTS.md or data/learnings.md are readsha256sum + mtime snapshot of every watched file across two due evaluations — proof the monitor writes/merges nothing200-iterationkill -TERMfuzz of the armed shim mid-evaluation, asserting schema head, 10/10 surface rows, retained baselines, and no leftovers after each runtamperedstate/startup-growth.check.shbytes, then a watcher sweep, to confirm the trust binding refuses it unexecutedtouch $LAB/.fm-secondmate-homewith data/captain-shared.md alone over budget, then the same state without the marker🔧 Fix applied.
✅ Re-checked - no issues remain.
FM_HOME=<lab> bin/fm-startup-growth-check.sh armthenbin/fm-watch.sh; startup-growth-watcher-transcript.txt — shim (0700) and trust binding written, watcher dispatches it with no "rejected" diagn…startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh.aaaaaaremoved; byte-bearing.bbbbbb, fresh live.cccccc, wrong-pattern.ddddddd, and symlink.ffffffplus its target all kept, while the e….startup-growth-check.2SWcFc(mode 600, 0 bytes) with the previous record untouched; kept while inside the grace, recl…unsafe tracked AGENTS.md, zero openat calls naming the symlink target, and the retained baseline survives in the record+400 estimated_tokensin a primary home and prints nothing in a secondmate home, while both record…bin/fm-startup-growth-check.sh --helpprints through the new sweep paragraph and ends at the disarm sentence with no code body leaking; an unknown verb exits 2bash tests/fm-startup-growth-check.test.sh(the change's own targeted suite, baseline)bin/fm-lab-home.sh create <tmpdir>to mint three+ disposable lab homes, each with a private copy of bin/, AGENTS.md and CLAUDE.md as the product checkoutFM_HOME=<lab> bin/fm-startup-growth-check.sh arm/disarm, plus a secondarmto check re-arm idempotence (shim inode and trust bytes unchanged)FM_HOME=<lab> FM_CHECK_INTERVAL=0 FM_POLL=5 bin/fm-watch.sh— the real watcher dispatching state/startup-growth.check.sh across seven cycles (baseline, same-day poll, next-day report, silent day, budget overrun, dedupe, post-disarm)strace -f -e trace=openat,read,newfstatat,statxaround a gated poll, a due evaluation against a 5.4 MB data/learnings.md, and an AGENTS.md replaced by a symlinkstrace -f -ttt -e trace=execveto locate the 1 ms mktemp window, then a python3 watcher loop racing SIGTERM into it until a real 0-byte mode-600 scratch leakedaged/fresh/byte-bearing/wrong-pattern/symlink scratch fixtures planted in state/ before a due evaluation and before a same-day poll150 due evaluations each killed with SIGTERM after 4–84 ms, asserting record schema, 10 surface rows, unchanged last_eval and unchanged retained baseline on every interruptbin/fm-startup-growth-check.sh --helpand an unknown verb (exit 2)docs/configuration.md:667- Out-of-scope consolidation worth a follow-up: the shared consequences of arming a standing watcher check are now restated per check in docs/configuration.md rather than owned once. "Registering the check is itself a reason to watch" lives at :1399 for the watched-tool check, is absent from the mail section (:1460-1467), and this change needed a third site (:667, added here as a pointer to :1399 instead of a copy). The same shape repeats for "arm writes state/<id>.check.sh and binds its bytes with bin/fm-check-register.sh, so the existing watcher polls it on its normal cadence" (:1397, :1461, :666) and for "disarm removes the shim, its trust binding, and the report record" (:1400, :1467, :668). Each new standing check adds another copy that can drift independently. A single operator-facing "standing watcher checks" subsection owning arm/disarm artifacts, the supervision consequence, and the report-record dedupe pattern, with each check's section reduced to what is unique to it, would end the class. Not done here: it rewrites two sections this change does not otherwise touch, which exceeds this change's documentation scope.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.