Skip to content

feat(bin): add armable daily startup growth check - #6725

Merged
kunchenguid merged 14 commits into
kunchenguid:mainfrom
Freudator86:fm/lightweight-startup-memory-growth-checks
Oct 6, 2026
Merged

kunchenguid merged 14 commits into
kunchenguid:mainfrom
Freudator86:fm/lightweight-startup-memory-growth-checks

Conversation

@Freudator86

@Freudator86 Freudator86 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Added bin/fm-startup-growth-check.sh with check, arm, and disarm subcommands: arm writes a state/startup-growth.check.sh shim bound through the existing authenticated watcher-check registration (no new daemon or scheduler), and check gates itself to one evaluation per 86400 seconds, reading only its own small .startup-growth-check record on polls inside that interval.
  • A due evaluation stays metadata-only — regular-file safety checks plus stat(1) byte sizes — over AGENTS.md, CLAUDE.md, bin/fm-session-start.sh, bin/fm-bootstrap.sh, bin/fm-supervision-instructions.sh, the session-printed data/projects.md and data/secondmates.md, and the budget-owned data/captain.md, data/captain-shared.md, and data/learnings.md; the budget total and verdict are delegated to bin/fm-startup-memory-budget.sh report rather 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 shared fm_cap_line digest cut before the record is published, and a secondmate home is not woken about the primary-owned data/captain-shared.md. Due evaluations also sweep aged empty temp records left by killed runs.
  • Documented the check in docs/configuration.md ("Daily startup growth check", including the watcher-retention implication), listed the script in docs/scripts.md, registered the shim and record in the operational-home-layout skill's state inventory, and added tests/fm-startup-growth-check.test.sh with 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.

  • Live validation: ✅ go - 15 of 15 scenarios driven live against the product
Scenario Result Live Evidence
An operator arms the daily check and the real watcher accepts and dispatches it ✅ pass live FM_HOME=<lab> bin/fm-startup-growth-check.sh arm then bin/fm-watch.sh; startup-growth-watcher-transcript.txt — shim (0700) and trust binding written, watcher dispatches it with no "rejected" diagn…
The first watcher cycle baselines every startup and memory surface silently ✅ pass live startup-growth-watcher-transcript.txt §1 — watcher prints nothing and keeps polling; state/.startup-growth-check lists all 10 surfaces plus the budget verdict
A poll inside the same day stays silent and re-reads none of the watched surfaces ✅ pass live startup-growth-watcher-transcript.txt §2 (last_eval untouched after 2500+900 bytes of growth) and startup-growth-metadata-only.txt §B — 18 ms, touches only its own state record and shim
A day later, meaningful growth in a startup instruction file and a memory file surfaces as a watcher wake ✅ pass live startup-growth-watcher-transcript.txt §3 — `check: .../startup-growth.check.sh: startup-growth: tracked startup surface growth AGENTS.md +2500 bytes ...; memory growth data/learnings.md +300 estimated…
A finding that has not changed is not repeated the next day ✅ pass live startup-growth-watcher-transcript.txt §4 and §6 — last_eval advances, the record still says over-budget, and the watcher emits nothing
A startup memory budget overrun from the budget owner is always reported ✅ pass live startup-growth-watcher-transcript.txt §5 — startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh
A 5.4 MB historical learnings file is measured as prompt cost but never loaded ✅ pass live startup-growth-metadata-only.txt §C — reports +133334 estimated_tokens in 0.14 s; only stat/statx on the file, 212 KB read(2) in total across the process tree, no openat of AGENTS.md or CLAUDE.md at a…
A due evaluation reclaims an aged empty orphan temp record and nothing else ✅ pass live startup-growth-orphan-sweep.txt §A–B — aged empty .aaaaaa removed; byte-bearing .bbbbbb, fresh live .cccccc, wrong-pattern .ddddddd, and symlink .ffffff plus its target all kept, while the e…
A record genuinely leaked by SIGTERM in the mktemp window survives its grace and is then reclaimed ✅ pass live startup-growth-orphan-sweep.txt §D — SIGTERM raced into the ~1 ms window leaked .startup-growth-check.2SWcFc (mode 600, 0 bytes) with the previous record untouched; kept while inside the grace, recl…
The sweep never runs outside the daily cadence ✅ pass live startup-growth-orphan-sweep.txt §C — a five-hour-old orphan survives a same-day poll, which prints nothing and leaves last_eval alone
Killing an evaluation mid-flight never publishes a partial record or loses a retained baseline ✅ pass live startup-growth-interrupt-fuzz.txt — 150 SIGTERMs, 62 landed mid-evaluation: 0 partial/incomplete records, 0 baselines moved without a publish, 0 leftovers; a clean run afterwards still reports the acc…
A tracked instruction surface swapped for a symlink is flagged unsafe and never followed ✅ pass live startup-growth-metadata-only.txt §D — reports unsafe tracked AGENTS.md, zero openat calls naming the symlink target, and the retained baseline survives in the record
A secondmate home is not nagged about the primary-owned shared memory file it cannot edit ✅ pass live startup-growth-secondmate-suppression.txt — the same +1200 bytes on data/captain-shared.md reports +400 estimated_tokens in a primary home and prints nothing in a secondmate home, while both record…
disarm retires the check and the watcher stops dispatching it ✅ pass live startup-growth-watcher-transcript.txt §7 — shim, trust binding and report record all gone; a following watcher run emits no startup-growth wake and recreates no state
The operator-facing help text renders the whole check contract ✅ pass live bin/fm-startup-growth-check.sh --help prints through the new sweep paragraph and ends at the disarm sentence with no code body leaking; an unknown verb exits 2
Evidence: 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

\### An operator arms the daily check in their home
$ FM_HOME=/tmp/fm-lab.ZCB7WS bin/fm-startup-growth-check.sh arm
armed: state/startup-growth.check.sh
-rw------- 1 quartermaster quartermaster  84 Oct  6 20:27 /tmp/fm-lab.ZCB7WS/state/startup-growth.check-trust
-rwx------ 1 quartermaster quartermaster 124 Oct  6 20:27 /tmp/fm-lab.ZCB7WS/state/startup-growth.check.sh

\### 1. The first watcher cycle baselines the surfaces silently
$ fm-watch.sh   # first cycle, nothing known yet
  (no further output above => the watcher absorbed the cycle and kept polling)

state/.startup-growth-check published by that cycle:
schema	fm-startup-growth-check-v1
last_eval	1791318426
AGENTS.md	tracked	present	47958	47958
CLAUDE.md	tracked	present	90	90
bin/fm-session-start.sh	tracked	present	55508	55508
bin/fm-bootstrap.sh	tracked	present	77824	77824
bin/fm-supervision-instructions.sh	tracked	present	10437	10437
data/projects.md	printed-memory	present	23	23
data/secondmates.md	printed-memory	absent	0	-
data/captain.md	memory	present	33	33
data/captain-shared.md	memory	absent	0	-
data/learnings.md	memory	present	51	51
memory_budget	7500	28	within-budget	

\### 2. The operator appends 2500 bytes to AGENTS.md and 900 bytes of learnings,
\###    then the watcher polls again the same day
50458 /tmp/fm-lab.ZCB7WS/checkout/AGENTS.md
  951 /tmp/fm-lab.ZCB7WS/data/learnings.md
51409 total
$ fm-watch.sh   # same day as the last evaluation
  (no further output above => the watcher absorbed the cycle and kept polling)

last_eval is untouched, so the day's evaluation was not repeated:
last_eval	1791318426

\### 3. A day later the same growth surfaces as an actionable watcher wake
$ fm-watch.sh   # a day later (clock advanced to 1791404827)
check: /tmp/fm-lab.ZCB7WS/state/startup-growth.check.sh: startup-growth: tracked startup surface growth AGENTS.md +2500 bytes (total 50458 bytes); memory growth data/learnings.md +300 estimated_tokens (+900 bytes, total 951 bytes)
  (no further output above => the watcher absorbed the cycle and kept polling)

record after the report (baselines rebased to the reported sizes):
schema	fm-startup-growth-check-v1
last_eval	1791404827
AGENTS.md	tracked	present	50458	50458
CLAUDE.md	tracked	present	90	90
bin/fm-session-start.sh	tracked	present	55508	55508
bin/fm-bootstrap.sh	tracked	present	77824	77824
bin/fm-supervision-instructions.sh	tracked	present	10437	10437
data/projects.md	printed-memory	present	23	23
data/secondmates.md	printed-memory	absent	0	-
data/captain.md	memory	present	33	33
data/captain-shared.md	memory	absent	0	-
data/learnings.md	memory	present	951	951
memory_budget	7500	328	within-budget	
reported	tracked startup surface growth AGENTS.md +2500 bytes (total 50458 bytes); memory growth data/learnings.md +300 estimated_tokens (+900 bytes, total 951 bytes)

\### 4. The next day, with nothing further changed, the watcher stays silent
$ fm-watch.sh   # next day, no new growth
  (no further output above => the watcher absorbed the cycle and kept polling)

last_eval	1791491228
  (last_eval advanced: the evaluation ran and chose silence)

\### 5. The budget owner reports an overrun, and it is always meaningful
$ fm-watch.sh   # day after the budget was lowered to 100 tokens
check: /tmp/fm-lab.ZCB7WS/state/startup-growth.check.sh: startup-growth: startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh
  (no further output above => the watcher absorbed the cycle and kept polling)


\### 6. The same overrun the next day is not repeated
$ fm-watch.sh   # next day, same unchanged overrun
  (no further output above => the watcher absorbed the cycle and kept polling)

memory_budget	100	328	over-budget	
reported	startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh

\### 7. disarm retires the check, and the watcher stops dispatching it
$ FM_HOME=/tmp/fm-lab.ZCB7WS bin/fm-startup-growth-check.sh disarm
disarmed: state/startup-growth.check.sh
  no shim, trust binding, or report record remains
$ fm-watch.sh   # after disarm
  (no further output above => the watcher absorbed the cycle and kept polling)

  the disarmed check recreated nothing

\### lab home torn down
removed /tmp/fm-lab.ZCB7WS
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

\### A home with a 5 MB historical data/learnings.md, check armed
  data/learnings.md: 5000000 bytes
armed: state/startup-growth.check.sh

## A. first evaluation on the real clock: every surface is baselined silently,
##    but the pre-existing 5 MB learnings file already breaks the token budget
  printed: [startup-growth: startup memory budget overrun total_estimated_tokens=1666673 budget=7500 owner=bin/fm-startup-memory-budget.sh]
  last_eval	1791318628
  data/learnings.md	memory	present	5000000	5000000

## B. the operator then grows AGENTS.md by 9000 bytes and learnings by 400000,
##    and a poll lands inside the same day
  wall clock: 0.018s
  printed: []   <= silent
  last_eval	1791318628   <= unchanged, the day is not re-evaluated
  every path under the home this gated poll touched:
  $FM_HOME
  $FM_HOME/.fm-secondmate-home
  $FM_HOME/checkout
  $FM_HOME/checkout\n
  $FM_HOME/state/.startup-growth-check
  $FM_HOME/state/startup-growth.check.sh
  => only its own small state record and its own shim; no watched surface is
     stat-ed, opened, or reread inside the day
  total bytes read(2): 110257

## C. a day later, the due evaluation: sizes only, contents never loaded
  wall clock: 0.112s
  printed: [startup-growth: tracked startup surface growth AGENTS.md +9000 bytes (total 56958 bytes); memory growth data/learnings.md +133334 estimated_tokens (+400000 bytes, total 5400000 bytes); startup memory budget overrun total_estimated_tokens=1800006 budget=7500 owner=bin/fm-startup-memory-budget.sh]
  syscalls naming the 5 MB data/learnings.md:
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, 0) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, AT_SYMLINK_NOFOLLOW) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, 0) = 0
    statx(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_SIZE, {stx_mask=STA
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, 0) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, AT_SYMLINK_NOFOLLOW) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", {st_mode=S_IFREG|0664, st_size=5400000, ...}, 0) = 0
    openat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/data/learnings.md", O_RDONLY) = 3
    <... read resumed>"file=data/learnings.md bytes=540"..., 4096) = 77
    (one openat from wc -c for the size; GNU wc -c answers from fstat, see the read total)
  syscalls naming the tracked instruction surfaces:
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/AGENTS.md", {st_mode=S_IFREG|0664, st_size=56958, ...}, 0) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/AGENTS.md", {st_mode=S_IFREG|0664, st_size=56958, ...}, AT_SYMLINK_NOFOLLOW) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/AGENTS.md", {st_mode=S_IFREG|0664, st_size=56958, ...}, 0) = 0
    statx(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/AGENTS.md", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_SIZE, {stx_mask=ST
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/CLAUDE.md", {st_mode=S_IFREG|0664, st_size=90, ...}, 0) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/CLAUDE.md", {st_mode=S_IFREG|0664, st_size=90, ...}, AT_SYMLINK_NOFOLLOW) = 0
    newfstatat(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/CLAUDE.md", {st_mode=S_IFREG|0664, st_size=90, ...}, 0) = 0
    statx(AT_FDCWD, "/tmp/fm-lab.nUDUZC/checkout/CLAUDE.md", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_SIZE, {stx_mask=ST
    (no openat at all: byte sizes come from stat)
  total bytes read(2) by the whole evaluation: 210311
  largest single read(2): 58021 bytes
  => a 5.4 MB learnings file is reported as prompt cost without being loaded

## D. an instruction surface swapped for a symlink is flagged, never followed
  startup-growth: unsafe tracked AGENTS.md; startup memory budget overrun total_estimated_tokens=1800006 budget=7500 owner=bin/fm-startup-memory-budget.sh
  openat() calls naming the symlink target: 0
  record row (the retained baseline survives the unsafe state):
    AGENTS.md	tracked	unsafe	0	56958

\### lab home removed: /tmp/fm-lab.nUDUZC
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

\### yesterday's evaluation, so today's poll is due
  last_eval	1791228662

## A. scratch files in state/ before the due evaluation
    17:31:02 .aged-empty-target    
    17:31:02 .startup-growth-check.aaaaaa    
    17:31:02 .startup-growth-check.bbbbbb    
    20:31:02 .startup-growth-check.cccccc    
    17:31:02 .startup-growth-check.ddddddd    
    20:31:02 .startup-growth-check.ffffff -> /tmp/fm-lab.nfW5ZJ/state/.aged-empty-target  

## B. the due evaluation runs
  startup-growth: tracked startup surface growth AGENTS.md +3000 bytes (total 50958 bytes)
  state/ afterwards:
    17:31:02 .aged-empty-target    
    17:31:02 .startup-growth-check.bbbbbb    
    20:31:02 .startup-growth-check.cccccc    
    17:31:02 .startup-growth-check.ddddddd    
    20:31:02 .startup-growth-check.ffffff -> /tmp/fm-lab.nfW5ZJ/state/.aged-empty-target  
  -> .aaaaaa (aged + empty + its own mint pattern) reclaimed
  -> .bbbbbb kept: a scratch holding record bytes is never a candidate
  -> .cccccc kept: minutes old, far inside the one-hour grace (a live sibling)
  -> .ddddddd kept: not the mint pattern
  -> .ffffff and its target kept: a symlink is never followed or removed
  and the evaluation still published its own complete record:
    schema	fm-startup-growth-check-v1
    last_eval	1791318662
    surface rows: 10

## C. a poll inside the same day does no sweeping at all
  printed: []
    17:31:02 .aged-empty-target    
    17:31:02 .startup-growth-check.bbbbbb    
    20:31:02 .startup-growth-check.cccccc    
    17:31:02 .startup-growth-check.ddddddd    
    15:31:02 .startup-growth-check.eeeeee    
    20:31:02 .startup-growth-check.ffffff -> /tmp/fm-lab.nfW5ZJ/state/.aged-empty-target  
  -> the aged orphan survives: the sweep lives inside the daily cadence

## D. a genuinely leaked record, produced by racing SIGTERM into the mktemp window
  SIGTERM landed in the mktemp window on attempt 1
  leaked: .startup-growth-check.2SWcFc mode=600 bytes=0
  the record the interrupted evaluation left untouched:
    schema	fm-startup-growth-check-v1
    last_eval	1791318662
  an evaluation whose clock puts the leak inside the grace keeps it:
    kept .startup-growth-check.2SWcFc
  the next due evaluation, with the leak two hours old, reclaims it:
    reclaimed .startup-growth-check.2SWcFc
    remaining scratch files: 0
    record still complete: 10 surface rows, first line schema fm-startup-growth-check-v1

\### lab home removed: /tmp/fm-lab.nfW5ZJ
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

\### 150 due evaluations, each killed with SIGTERM after 4-84 ms
    (an evaluation takes ~110 ms, so many die mid-flight)

  interrupts that landed mid-evaluation : 62
  evaluations that finished before SIGTERM: 88
  partial or incomplete records published: 0
  retained baselines lost without a publish: 0
  leftover temporary records: 0

\### a clean evaluation after all of that still reports the accumulated growth
  startup-growth: tracked startup surface growth AGENTS.md +2200 bytes (total 52658 bytes)

\### lab home removed: /tmp/fm-lab.ncggtF
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

## a primary home, which owns that file
  a day later, after the primary added 1200 bytes to data/captain-shared.md:
    printed: [startup-growth: memory growth data/captain-shared.md +400 estimated_tokens (+1200 bytes, total 1235 bytes)]
    recorded anyway:
      data/captain-shared.md	memory	present	1235	1235

## a secondmate home, which cannot edit that file
  a day later, after the primary added 1200 bytes to data/captain-shared.md:
    printed: []
    recorded anyway:
      data/captain-shared.md	memory	present	1235	1235

\### both lab homes removed
Evidence: The growth wake an operator actually sees from the watcher
check: /tmp/fm-lab.ZCB7WS/state/startup-growth.check.sh: startup-growth: tracked startup surface growth AGENTS.md +2500 bytes (total 50458 bytes); memory growth data/learnings.md +300 estimated_tokens (+900 bytes, total 951 bytes)

check: /tmp/fm-lab.ZCB7WS/state/startup-growth.check.sh: startup-growth: startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (37m20s)

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's mktemp child 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-600 state/.startup-growth-check.XXXXXX behind, 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 before mktemp still 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.
  • Live validation: ✅ go - 14 of 14 scenarios driven live against the product
Scenario Result Live Evidence
Arming a home makes the real watcher take the first daily evaluation silently and publish a baseline record ✅ pass live armed-baseline-silence.txt - bin/fm-startup-growth-check.sh arm then a 25s bin/fm-watch.sh run in the lab home: no wake, and state/.startup-growth-check holds all ten surfaces plus the budget verd…
A grown instruction file and a grown memory file are surfaced to the supervising agent as one actionable wake ✅ pass live watcher-growth-wake.txt, wake-queue-record.txt, wake-drain-agent-view.txt - the watcher exited with `check: .../startup-growth.check.sh: startup-growth: tracked startup surface growth AGENTS.md +2500…
A growing startup script, not just an instruction file, is flagged with its byte delta ✅ pass live tampered-shim-refused.txt second half - after 2500 bytes were appended to bin/fm-bootstrap.sh the watcher woke with tracked startup surface growth bin/fm-bootstrap.sh +2500 bytes (total 80324 bytes)
Polls inside the same day stay silent and never re-read the watched surfaces ✅ pass live same-day-silence.txt - AGENTS.md replaced by a dangling symlink and learnings.md grown 5000 bytes, then three consecutive watcher sweeps produced no wake at all and the record still carried the stale…
A standing finding is reported once and then deduplicated on later days ✅ pass live next-day-report-and-dedupe.txt - the unsafe-AGENTS.md finding was emitted, re-emitted exactly once when the accompanying growth finding cleared and changed the set, then two further due days stayed si…
Adversarial: growth kept under the daily threshold is still caught once it adds up ✅ pass live cumulative-subthreshold-growth.txt - 700 bytes appended to AGENTS.md on three successive due days: days one and two silent, day three woke with +2100 bytes against the retained baseline
A bulk learnings file that pushes startup memory over the token budget wakes the home with the owner's numbers ✅ pass live budget-overrun.txt - learnings.md grown to 29939 bytes produced startup memory budget overrun total_estimated_tokens=10002 budget=7500 owner=bin/fm-startup-memory-budget.sh, identical to `bin/fm-sta…
Adversarial: a due evaluation reads file sizes only and never loads the contents of the watched files ✅ pass live metadata-only-no-content-reads.txt, metadata-only-strace.txt - strace of the armed shim over a 32939-byte learnings.md and a 50058-byte AGENTS.md shows only newfstatat/statx on those paths and zero re…
Old bulk learning files stay reference-only: the monitor never rewrites or merges them ✅ pass live reference-only-no-merge.txt - sha256 + mtime of every watched file before and after two due evaluations (one silent, one reporting growth) differ only by the append the test itself made
Adversarial: an unsafe symlinked surface is reported while an absent optional memory file is not ✅ pass live next-day-report-and-dedupe.txt - the dangling-symlink AGENTS.md produced unsafe tracked AGENTS.md on the next due day, with no missing-file noise for the optional memory files, and the finding clear…
Adversarial: a secondmate home is not woken about the primary-owned shared file, while a primary home is ✅ pass live secondmate-suppression.txt - with data/captain-shared.md alone over budget and .fm-secondmate-home present the watcher stayed silent yet still recorded the observation and the owner's `primary-owned…
Adversarial: a tampered check shim is refused by the watcher instead of executed ✅ pass live tampered-shim-refused.txt - after the armed shim was replaced with an attacker-controlled script the watcher woke with check: rejected unauthenticated state checks: .../startup-growth.check.sh and t…
Adversarial: an evaluation interrupted by a signal abandons its work instead of publishing a partial record or losing baselines ✅ pass live interrupt-fuzz.txt - 200 runs of the armed shim TERMed at random points inside its 42ms evaluation: 187 interrupted, 0 partial records published, 0 retained baselines lost, and a clean run afterwards…
Disarming removes the shim, its trust binding and its record, and the watcher stops monitoring ✅ pass live disarm.txt - disarm left 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 rejection
  • bash tests/fm-startup-growth-check.test.sh (repo's own suite for the changed script, 21 cases)
  • bin/fm-lab-home.sh create $LAB plus 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 / disarm in the lab home
  • FM_HOME=$LAB FM_POLL=1 FM_CHECK_INTERVAL=0 FM_STARTUP_GROWTH_NOW=&lt;epoch&gt; $LAB/root/bin/fm-watch.sh — 18 real watcher sweeps across simulated days
  • $LAB/root/bin/fm-wake-drain.sh and --ack-through &lt;seq&gt; --recovery-generation &lt;gen&gt; — 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 report
  • strace -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 read
  • sha256sum + mtime snapshot of every watched file across two due evaluations — proof the monitor writes/merges nothing
  • 200-iteration kill -TERM fuzz of the armed shim mid-evaluation, asserting schema head, 10/10 surface rows, retained baselines, and no leftovers after each run
  • tampered state/startup-growth.check.sh bytes, then a watcher sweep, to confirm the trust binding refuses it unexecuted
  • touch $LAB/.fm-secondmate-home with data/captain-shared.md alone over budget, then the same state without the marker

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 15 of 15 scenarios driven live against the product
Scenario Result Live Evidence
An operator arms the daily check and the real watcher accepts and dispatches it ✅ pass live FM_HOME=&lt;lab&gt; bin/fm-startup-growth-check.sh arm then bin/fm-watch.sh; startup-growth-watcher-transcript.txt — shim (0700) and trust binding written, watcher dispatches it with no "rejected" diagn…
The first watcher cycle baselines every startup and memory surface silently ✅ pass live startup-growth-watcher-transcript.txt §1 — watcher prints nothing and keeps polling; state/.startup-growth-check lists all 10 surfaces plus the budget verdict
A poll inside the same day stays silent and re-reads none of the watched surfaces ✅ pass live startup-growth-watcher-transcript.txt §2 (last_eval untouched after 2500+900 bytes of growth) and startup-growth-metadata-only.txt §B — 18 ms, touches only its own state record and shim
A day later, meaningful growth in a startup instruction file and a memory file surfaces as a watcher wake ✅ pass live startup-growth-watcher-transcript.txt §3 — `check: .../startup-growth.check.sh: startup-growth: tracked startup surface growth AGENTS.md +2500 bytes ...; memory growth data/learnings.md +300 estimated…
A finding that has not changed is not repeated the next day ✅ pass live startup-growth-watcher-transcript.txt §4 and §6 — last_eval advances, the record still says over-budget, and the watcher emits nothing
A startup memory budget overrun from the budget owner is always reported ✅ pass live startup-growth-watcher-transcript.txt §5 — startup memory budget overrun total_estimated_tokens=328 budget=100 owner=bin/fm-startup-memory-budget.sh
A 5.4 MB historical learnings file is measured as prompt cost but never loaded ✅ pass live startup-growth-metadata-only.txt §C — reports +133334 estimated_tokens in 0.14 s; only stat/statx on the file, 212 KB read(2) in total across the process tree, no openat of AGENTS.md or CLAUDE.md at a…
A due evaluation reclaims an aged empty orphan temp record and nothing else ✅ pass live startup-growth-orphan-sweep.txt §A–B — aged empty .aaaaaa removed; byte-bearing .bbbbbb, fresh live .cccccc, wrong-pattern .ddddddd, and symlink .ffffff plus its target all kept, while the e…
A record genuinely leaked by SIGTERM in the mktemp window survives its grace and is then reclaimed ✅ pass live startup-growth-orphan-sweep.txt §D — SIGTERM raced into the ~1 ms window leaked .startup-growth-check.2SWcFc (mode 600, 0 bytes) with the previous record untouched; kept while inside the grace, recl…
The sweep never runs outside the daily cadence ✅ pass live startup-growth-orphan-sweep.txt §C — a five-hour-old orphan survives a same-day poll, which prints nothing and leaves last_eval alone
Killing an evaluation mid-flight never publishes a partial record or loses a retained baseline ✅ pass live startup-growth-interrupt-fuzz.txt — 150 SIGTERMs, 62 landed mid-evaluation: 0 partial/incomplete records, 0 baselines moved without a publish, 0 leftovers; a clean run afterwards still reports the acc…
A tracked instruction surface swapped for a symlink is flagged unsafe and never followed ✅ pass live startup-growth-metadata-only.txt §D — reports unsafe tracked AGENTS.md, zero openat calls naming the symlink target, and the retained baseline survives in the record
A secondmate home is not nagged about the primary-owned shared memory file it cannot edit ✅ pass live startup-growth-secondmate-suppression.txt — the same +1200 bytes on data/captain-shared.md reports +400 estimated_tokens in a primary home and prints nothing in a secondmate home, while both record…
disarm retires the check and the watcher stops dispatching it ✅ pass live startup-growth-watcher-transcript.txt §7 — shim, trust binding and report record all gone; a following watcher run emits no startup-growth wake and recreates no state
The operator-facing help text renders the whole check contract ✅ pass live bin/fm-startup-growth-check.sh --help prints through the new sweep paragraph and ends at the disarm sentence with no code body leaking; an unknown verb exits 2
  • bash tests/fm-startup-growth-check.test.sh (the change's own targeted suite, baseline)
  • bin/fm-lab-home.sh create &lt;tmpdir&gt; to mint three+ disposable lab homes, each with a private copy of bin/, AGENTS.md and CLAUDE.md as the product checkout
  • FM_HOME=&lt;lab&gt; bin/fm-startup-growth-check.sh arm / disarm, plus a second arm to check re-arm idempotence (shim inode and trust bytes unchanged)
  • FM_HOME=&lt;lab&gt; 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,statx around a gated poll, a due evaluation against a 5.4 MB data/learnings.md, and an AGENTS.md replaced by a symlink
  • strace -f -ttt -e trace=execve to locate the 1 ms mktemp window, then a python3 watcher loop racing SIGTERM into it until a real 0-byte mode-600 scratch leaked
  • aged/fresh/byte-bearing/wrong-pattern/symlink scratch fixtures planted in state/ before a due evaluation and before a same-day poll
  • 150 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 interrupt
  • bin/fm-startup-growth-check.sh --help and an unknown verb (exit 2)
⚠️ **Document** - 1 info
  • ℹ️ 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.

@greptile-apps

ghost commented Oct 6, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds a daily startup growth monitoring script.

The PR appears safe to merge with four previously reported, non-blocking issues still open.

Reviews (3) · Last reviewed commit: "no-mistakes(ci): Diagnosed "Behavior por..."

Comment on lines +274 to +281
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)

ghost Oct 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Comment on lines +351 to +358
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"

ghost Oct 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Comment on lines +393 to +394
rm -f -- "$CHECK_SHIM" "$CHECK_TRUST" "$RECORD"
printf 'disarmed: state/%s.check.sh\n' "$CHECK_ID"

ghost Oct 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed disarm reports success

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.

Suggested change
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"

ghost Oct 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
fm_cap_line "startup-growth: $FINDINGS" "$MAX_LINE"
fm_cap_line "startup-growth: $FINDINGS" "$MAX_LINE" || fail "could not deliver report"

Quartermaster added 2 commits October 6, 2026 21:24
…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
@kunchenguid

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: reviewed head d53c2d1a against main e06a46fe, and this is ready to land.

What I checked:

  • bin/fm-startup-growth-check.sh does nothing until an operator runs arm. arm writes a state/startup-growth.check.sh shim and registers it through the existing fm-check-register.sh trust binding, so it adds no new daemon or scheduler. disarm removes it.
  • check runs once per 86400 s, using stat sizes only. It delegates the budget verdict to bin/fm-startup-memory-budget.sh report, baselines silently the first time, deduplicates findings, and emits at most one capped line.
  • The other test edits are flake fixes: the Pi /reload wait now keys on the durable "Reloaded" row, and a frozen clock was added in fm-contributions.test.sh.
  • No workflow files change and there are no network calls.
  • Head d53c2d1a matches the no-mistakes attestation. CI, including the timing aggregate, Require no-mistakes, and Greptile are all green, and it merges cleanly.

Contract-class: opt-in. Nothing runs until arm. Homes that don't arm it behave exactly as on main.

VISION.md, rule by rule

  • One captain, one interface: aligns. It wakes once a day at most, stays silent when nothing changed, and only wakes the first mate.
  • Authority is explicit and never inferred: aligns. It's opt-in through arm, and it reports growth without changing anything.
  • Scripts own the mechanics, agents own the judgment: aligns. Size deltas and the daily gate are exact script work, and the first mate decides what to do about growth.
  • A restart is a non-event: aligns. The baselines and the last-reported set live in a durable record that is published atomically.
  • Delegation with a spine: aligns. It reuses the watcher-check primitive.
  • The fleet outlives any vendor: aligns. Nothing vendor-specific.
  • Scope: aligns. It guards the token cost of the always-loaded contract.

Optional follow-ups from Greptile's open P2s, none blocking: make disarm fail loudly when rm fails, and don't publish reported when fm_cap_line fails.

Squash-merging.

@kunchenguid
kunchenguid merged commit 99da16d into kunchenguid:main Oct 6, 2026
@kunchenguid

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @Freudator86 — really appreciate you taking the time on this.

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.

3 participants