Skip to content

feat(supervision-host): compact idle sessions while the prompt cache is warm - #7807

Merged
kunchenguid merged 8 commits into
kunchenguid:mainfrom
Azd325:fm/fm-7755-warm-compact
Oct 26, 2026
Merged

kunchenguid merged 8 commits into
kunchenguid:mainfrom
Azd325:fm/fm-7755-warm-compact

Conversation

@Azd325

@Azd325 Azd325 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Add bin/fm-warm-compact-lib.sh, gated by an optional config/warm-compact file (idle-seconds, default 2700, and min-context-tokens, default 80000). It decides when a session is due for compaction. For a Claude primary, it sends /compact through the backend's verified submit primitive, and only when the agent is idle and the composer is empty. For the supervision host's engine conversation, it runs /compact as a bounded headless turn.
  • The supervision host now runs a warm-compact tick while parked (every 60s by default). It compacts the primary and the engine conversation at most once per idle episode. The engine run is abandoned when the arm closes or the park boundary arrives. The Claude stop-autoarm passes the transcript path so the primary's context size can be measured.
  • The engine record gains ended= and compacted= fields. The resumable-record check is factored into engine_record_resumable, shared with choose_conversation. Warm-compact state files are cleared on activation.
  • Document the gate and guards in docs/configuration.md and add a row to docs/supervision-host.md. Add tests: tests/fm-warm-compact.test.sh, additions to tests/fm-supervision-host.test.sh, and a live herdr end-to-end test.

Risk Assessment

⚠️ Medium: The feature is opt-in and its guards hold. Prior-round fixes check out: the persisted engine marker is keyed to ended=, the runner is abortable in the host shell, the resume predicate is shared, and an abandoned compaction stays unmarked, with a test that goes red without the guard. It still adds a background engine turn and an in-loop tick to the supervision host's park loop, which handles signals, so it should not be treated as trivial.

Testing

The library suite passed. The live Herdr e2e passed on the rerun after a fix to the test's transcript lookup. The live run showed an idle Claude primary compacted once through the backend submit path, and the engine conversation compacted once by a resumed /compact, with no wake queued for the captain. The primary then drained and acknowledged a wake queued afterward. The host-suite cases for engine marker persistence, the non-resumable-session skip, and abandon-at-park-boundary passed in a subset run against stub engines (not live). The full host suite aborted on an unrelated, load-sensitive case; that case passed when rerun alone.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
An idle Claude primary in a Herdr lab is compacted once through the backend submit path, and not again in that episode ✅ pass live live-e2e.log: 'warm-compact primary sent'; primary transcript has 1 compaction boundary; no second primary compaction in the host log
The supervision host's engine conversation is compacted once by a resumed /compact after an away wake ✅ pass live live-e2e.log: 'warm-compact engine compacted'; engine context 18229 tokens afterward
Compaction never becomes captain-facing news (no wake queued) ✅ pass live the live e2e asserts the wake queue is empty after both compactions and it passed
A compacted primary still picks up a wake queued on disk afterward ✅ pass live live-e2e.log: 'compacted primary drained and acknowledged the wake queued after compaction'
Engine marker persists across host processes, and an engine session the next turn would not resume is skipped ⏸️ untested no The prior payload ran this only as host-suite tests against stub engines (host-subset.log). It did not drive it against the live product, so it records no live result.
A compaction abandoned at the park boundary is not marked done ⏸️ untested no The prior payload ran this only as a host-suite test against stub engines (host-subset.log). It did not drive it against the live product, so it records no live result.
Evidence: live e2e pass log

Source: live e2e pass log

# 20:06:36 primary idle in Herdr pane w1:p1 (2.1.310 (Claude Code), herdr 0.9.5, model haiku); host pid 96829
# 20:06:58 engine conversation dd29fdfb-83bb-4b15-a189-2d3faf1271ed handled one away wake
# 20:07:38 primary: warm-compact	primary	sent
# 20:08:16 engine: warm-compact	engine	compacted
# 20:08:16 primary transcript compaction boundaries: 1
# 20:08:36 engine context after compaction: 18229 tokens
# 20:08:51 compacted primary drained and acknowledged the wake queued after compaction
ok - warm-cache compaction: primary and engine compacted once each, pending wake picked up from disk
exit=0
Evidence: first live run (test-lookup failure)

Source: first live run (test-lookup failure)

# 19:49:06 primary idle in Herdr pane w1:p1 (2.1.310 (Claude Code), herdr 0.9.5, model haiku); host pid 35616
# 19:49:43 engine conversation f031f6e9-28b3-4379-9789-76cdb28c2d02 handled one away wake
# 19:50:06 primary: warm-compact	primary	sent
# 19:51:03 engine: warm-compact	engine	compacted
# 19:51:03 primary transcript compaction boundaries: 1
# 19:51:23 engine context after compaction: 18889 tokens
not ok - the compacted primary never drained and acknowledged the pending wake
{"id":"cli:pane:list","result":{"panes":[{"agent":"claude","agent_session":{"agent":"claude","kind":"id","source":"herdr:claude","value":"f85e2c99-0683-4575-93f4-d82f6c073ba4"},"agent_status":"idle","cwd":"/private/var/folders/m7/v02n8pqn167dn42b0vdb3l4h0000gn/T/fm-warm-compact-live.OJEsuH/fm","focused":true,"foreground_cwd":"/private/var/folders/m7/v02n8pqn167dn42b0vdb3l4h0000gn/T/fm-warm-compact-live.OJEsuH/fm","pane_id":"w1:p1","revision":2,"scroll":{"max_offset_from_bottom":0,"offset_from_bottom":0,"viewport_rows":40},"tab_id":"w1:t1","terminal_id":"term_65ec2c7bd42d01","terminal_title":"✳ Firstmate wake drain test lab","terminal_title_stripped":"Firstmate wake drain test lab","workspa
--- host log
1793040545	start	gen=host-35616-1793040544	primary=claude
1793040583	handled	turn=host-35616-1793040544.1	posture=away	rc=0	reports=1	error=0 cost=0.038199 conversation_cost=0.038199 input=16 cache_read=141035 cache_write=3086 output=1172 turns=8	signal: /private/var/folders/m7/v02n8pqn167dn42b0vdb3l4h0000gn/T/fm-warm-compact-live.OJEsuH/fm/state/demo.status
1793040606	warm-compact	primary	sent
1793040663	warm-compact	engine	compacted
1793040686	pass-through	attended	main-only	signal: /private/var/folders/m7/v02n8pqn167dn42b0vdb3l4h0000gn/T/fm-warm-compact-live.OJEsuH/fm/state/demo.status
1793040697	start	gen=host-92924-1793040697	primary=claude
1793040697	take-over	arm=81832
1793040762	warm-compact	primary	sent
--- queue

--- screen

✻ Sautéed for 6s · done 7:49 PM

❯ /compact
  ⎿  Compacted (ctrl+o to see full summary)
  ⎿  Referenced file AGENTS.md

⏺ Stop hook feedback

  Thought for 3s, ran 2 shell commands

⏺ ACKED

✻ Churned for 9s · done 7:51 PM

❯ /compact
  ⎿  Compacted (ctrl+o to see full summary)
  ⎿  Referenced file AGENTS.md


───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  Haiku 5.5 | ctx: 0% used
  ⏵⏵ bypass permissions on (shift+tab to cycle) · ← 1 agent
exit=1
Evidence: host suite subset

Source: host suite subset

ok - host: the dialog mirror, its feed, and the wake file are owner-only
ok - host: an idle engine conversation is compacted once across hosts
ok - host: a conversation the next turn would not resume is not compacted
ok - host: a compaction abandoned at the park boundary is not marked done
exit=0
Evidence: full host suite run (aborted on unrelated case)

Source: full host suite run (aborted on unrelated case)

ok - host+hook: a main-only close after a handled turn restores inherited handling and rewakes main
ok - host+hook: a refused inherited handling restore delivers a failure instead of silent success
ok - host+hook: a driver returning to an idle worker is stale-handled while attended
ok - host+hook: a driver returning to an idle worker is stale-handled while away
ok - host+hook: boundary survives a lost continuation, retries, and transfers one watcher after acknowledgement
ok - host+hook: pass-through survives a lost continuation, retries, and transfers one watcher after acknowledgement
ok - host+hook: an acknowledged hand-back at the turn keeps its pass-through row
ok - host+hook: hand-back retry submits only to the idle owning pane without replacing human input
ok - host+hook: a successor closed before exit_to_main does not suppress the branch-outcome rewake
ok - host+hook: a successor that closes during a held engine turn does not suppress the branch-outcome rewake
ok - host+hook: a refused hand-back becomes a delivered failure notice
ok - host+hook: a refused hand-back on an announced handling marker becomes a delivered failure notice
ok - host: parked child-exit sampling uses ordinary half-second sleeps
ok - report surface: only the branch actor's current turn may report, and only on the tasks its wake names
ok - report surface: visible late outcomes queue a relay, while silent outcomes remain stored without a wake or note
ok - dispatch entry: the host reads branch eligibility, the offer rule, and the wake prompt from the Pi branch's own owner
ok - drain: BRANCH OUTCOMES runs on a Claude home by default and on another primary with the file, never with off, and never on Pi
ok - drain: captain outcomes come first, and routine overflow collapses into a count one drain clears
ok - drain: repeated captain outcomes collapse per task, and the byte cap presents only the run its acknowledgement covers
ok - drain: a long away window costs one short drain, captain outcomes collapsed per task and routine overflow counted, and nothing from it is shown again
ok - drain: the BRANCH OUTCOMES budgets count bytes, cutting multibyte summaries by whole characters in any locale
ok - drain: branch outcomes stay unread when a projection of the store fails
ok - drain: branch outcomes stay unread and the drain fails when jq is missing
ok - drain: branch outcomes stay unread when the drain cannot print them
ok - drain: a legacy backlog is presented with each outcome's age and a check-first instruction, never adopted
ok - drain: a keyed decision survives acknowledgement through a newer outcome for its task
ok - drain: an outcome carried across a switch off Pi comes back with its age, never adopted
ok - drain: an outcome nothing has shown is presented until acknowledged, and a repeated acknowledgement changes nothing
ok - drain: an outcome the host drain presented but main never acknowledged stays unprocessed across a switch to Pi
ok - drain: an outcome the host drain presented but main never acknowledged survives an outcome index repair
ok - host: an attended wake the branch may take is handled on the engine, and its routine outcome never wakes main
ok - host: a host stopped right after a handled wake exits and leaves the wake queue usable
ok - host: an engine in another time zone than the host drains, reports, and acknowledges its granted rows
ok - host: an attended captain outcome wakes main once and stays in its drain until main acknowledges it
ok - host: a captain outcome recorded after the captain left waits for the return, then reaches main's drain
ok - host: a quiet record without its daemon is a present captain, so outcomes and decisions reach main
ok - host: an attended decision close stays main's exactly as the plain arm delivers it
ok - host: an off written while the host is parked sends the next attended close to main, naming the opt-out
ok - host: a main-only pass-through leaves the successor watcher running and the close undelivered for main
ok - host: an attended close whose main session cannot be identified reaches main and runs no engine turn
ok - host: a decision close accepted away whose turn starts attended still reaches main unchanged
ok - host: an attended close whose task turns main-only before its turn still reaches main unchanged
ok - host+hook: an attended main-only pass-through rewakes main and keeps its successor watcher
ok - host+hook: an inbox note queued while the host is parked on a handled wake's successor rewakes main
ok - host+hook: a captain outcome beside a quiet record rewakes the present captain with no away note
ok - host+hook: a Claude home without config/supervision-host runs the host at the default engine, and an off file restores the plain arm
ok - host+hook: a close that turns main-only at its turn rewakes main and keeps its successor watcher
ok - host+hook: the successor a close that turns main-only at its turn leaves for main survives the hook's process group teardown
ok - host+hook: failed at-turn downtime write notifies main despite a healthy successor
ok - host+hook: a successor close that lands during main's turn is delivered at the next turn end
ok - host+hook: the successor a pass-through leaves for main survives the hook's process group teardown
ok - host+hook: the next park takes over the cycle a main-only pass-through left, so one arm owns it
ok - host+hook: a park stopped mid take-over leaves the take-over to the next park
ok - host+hook: a successor that cannot be recorded is stopped, and main's next turn end arms a fresh cycle
ok - host: a primary with no verified dialog mirror keeps every attended close on main, and its away posture still runs
ok - host: each wake carries the captain's dialog since the last wake, without operational input
not ok - private: the wake was not handled: 1793043072	start	gen=host-10815-1793043070	primary=claude
exit=1
  • Outcome: ⚠️ 1 info across 1 run (59m19s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed (3) ✅
  • 🚨 bin/fm-supervision-host.sh:569 - The engine's once-per-idle-episode marker (WARM_COMPACT_ENGINE_DONE) lives only in host process memory, but the engine episode spans host processes. choose_conversation (bin/fm-supervision-host.sh:845-855) resumes the recorded engine session across parks, and ended= in .supervision-host-engine changes only when a turn is handled. Failing sequence: (1) the engine handles a wake at T0. (2) The primary keeps working, and each Stop starts a fresh host with WARM_COMPACT_ENGINE_DONE empty. (3) After T0+idle-seconds, every new host's first tick finds idle>=2700 and compacted=0. (4) Each host then resumes the engine with /compact again. The size guard does not stop this. A /compact adds a compact_boundary and a summary user entry but no new assistant usage line, so fm_warm_compact_context_tokens (bin/fm-warm-compact-lib.sh:64-72) still reads the pre-compaction size. Result: one headless Claude run per primary turn end. Once the cache is cold, each run re-writes the context at the cache-write price, which is the cost Claude primary and supervision host are never compacted before cache expiry, so idle wakes re-write ~400k tokens #7755 (warm-compact) sets out to avoid. This breaks the intent's 'at most once per idle episode'. The primary has the same weakness, because WARM_COMPACT_PRIMARY_DONE (line 568) and the stale transcript size reset whenever the autoarm loop restarts the host in the same idle episode (bin/fm-claude-stop-autoarm.sh:446-451). Fix: persist the marker with the record it guards, for example compacted=<ended> in ENGINE_RECORD, written atomically like write_engine_record, and read it in warm_compact_tick. Also add a host-level test: two host runs over one engine record must produce one /compact. tests/fm-warm-compact.test.sh:118 only passes compacted=1 into the library, so it cannot catch this.
  • ⚠️ bin/fm-supervision-host.sh:592 - The engine compaction runs synchronously inside await_close, through a command substitution. That blocks the park loop for up to FM_WARM_COMPACT_ENGINE_TIMEOUT (300s) plus the engine grace. During that time the host does not see the arm close, so a real wake waits up to about 5 minutes. boundary_reached is also not checked. Bash defers the host's TERM/INT/HUP traps until the foreground command substitution returns, so a take-over or stop also waits that long. The compaction also bypasses ENGINE_RUNNING and ENGINE_PID_FILE, so cleanup/stop_engine_turn (lines 426-437, 448-450) cannot stop the engine. A host killed outright leaves the resumed claude process running on the session the successor resumes next. Its .warm-compact-msg/result/err temp files are also left behind, because the startup sweep only removes .supervision-host-* files (line 400). Fix: run the compaction like handle's engine turn (lines 1073-1090): background the subshell and wait on it, set ENGINE_RUNNING/ENGINE_SUBSHELL, pass ENGINE_PID_FILE to fm_supervision_engine_turn, and name the temp files under the swept .supervision-host-* prefix.
  • ⚠️ bin/fm-supervision-host.sh:585 - The engine check matches only engine= against the record. choose_conversation resumes a recorded session only when key, engine, and model all match and turns < ROTATE_TURNS (bin/fm-supervision-host.sh:845-848). The host can therefore compact a conversation that the next turn will never resume: after a model change, a prompt-key change, or a conversation at its 20-turn rotation limit. Each such compaction is a paid headless run of up to 300s with no benefit. Fix: apply the same model, key, and turns<ROTATE_TURNS predicate before calling fm_warm_compact_engine.

🔧 Fix applied.
4 issues (1 error, 3 warnings) still open:

  • 🚨 bin/fm-supervision-host.sh:569 - The engine's once-per-idle-episode marker (WARM_COMPACT_ENGINE_DONE) lives only in host process memory, but the engine episode spans host processes. choose_conversation (bin/fm-supervision-host.sh:845-855) resumes the recorded engine session across parks, and ended= in .supervision-host-engine changes only when a turn is handled. Failing sequence: (1) the engine handles a wake at T0. (2) The primary keeps working, and each Stop starts a fresh host with WARM_COMPACT_ENGINE_DONE empty. (3) After T0+idle-seconds, every new host's first tick finds idle>=2700 and compacted=0. (4) Each host then resumes the engine with /compact again. The size guard does not stop this. A /compact adds a compact_boundary and a summary user entry but no new assistant usage line, so fm_warm_compact_context_tokens (bin/fm-warm-compact-lib.sh:64-72) still reads the pre-compaction size. Result: one headless Claude run per primary turn end. Once the cache is cold, each run re-writes the context at the cache-write price, which is the cost Claude primary and supervision host are never compacted before cache expiry, so idle wakes re-write ~400k tokens #7755 (warm-compact) sets out to avoid. This breaks the intent's 'at most once per idle episode'. The primary has the same weakness, because WARM_COMPACT_PRIMARY_DONE (line 568) and the stale transcript size reset whenever the autoarm loop restarts the host in the same idle episode (bin/fm-claude-stop-autoarm.sh:446-451). Fix: persist the marker with the record it guards, for example compacted=&lt;ended&gt; in ENGINE_RECORD, written atomically like write_engine_record, and read it in warm_compact_tick. Also add a host-level test: two host runs over one engine record must produce one /compact. tests/fm-warm-compact.test.sh:118 only passes compacted=1 into the library, so it cannot catch this.
  • ⚠️ bin/fm-supervision-host.sh:592 - The engine compaction runs synchronously inside await_close, through a command substitution. That blocks the park loop for up to FM_WARM_COMPACT_ENGINE_TIMEOUT (300s) plus the engine grace. During that time the host does not see the arm close, so a real wake waits up to about 5 minutes. boundary_reached is also not checked. Bash defers the host's TERM/INT/HUP traps until the foreground command substitution returns, so a take-over or stop also waits that long. The compaction also bypasses ENGINE_RUNNING and ENGINE_PID_FILE, so cleanup/stop_engine_turn (lines 426-437, 448-450) cannot stop the engine. A host killed outright leaves the resumed claude process running on the session the successor resumes next. Its .warm-compact-msg/result/err temp files are also left behind, because the startup sweep only removes .supervision-host-* files (line 400). Fix: run the compaction like handle's engine turn (lines 1073-1090): background the subshell and wait on it, set ENGINE_RUNNING/ENGINE_SUBSHELL, pass ENGINE_PID_FILE to fm_supervision_engine_turn, and name the temp files under the swept .supervision-host-* prefix.
  • ⚠️ bin/fm-supervision-host.sh:585 - The engine check matches only engine= against the record. choose_conversation resumes a recorded session only when key, engine, and model all match and turns < ROTATE_TURNS (bin/fm-supervision-host.sh:845-848). The host can therefore compact a conversation that the next turn will never resume: after a model change, a prompt-key change, or a conversation at its 20-turn rotation limit. Each such compaction is a paid headless run of up to 300s with no benefit. Fix: apply the same model, key, and turns<ROTATE_TURNS predicate before calling fm_warm_compact_engine.
  • ⚠️ bin/fm-supervision-host.sh:590 - Fix round 1 did not close review-2 (abortable engine compaction). warm_compact_tick still calls the new runner through a command substitution: verdict=$(run_warm_compact_engine ...). So ENGINE_RUNNING=1 and ENGINE_SUBSHELL (lines 607, 615) are set only in the substitution's subshell, never in the host. The host also waits on a foreground command substitution, and bash defers the host's trap &#39;exit 143&#39; TERM (line 1218) until it returns. Failing sequence: (1) an engine compaction is in flight, for up to FM_WARM_COMPACT_ENGINE_TIMEOUT (300s). (2) A take-over calls stop_recorded on the host (lines 343-355): TERM, wait 10s, then KILL. (3) The TERM is deferred, so the KILL lands. cleanup never runs: no grant release or deactivate, no lease release, no arm retire, and no HOST_RECORD removal. The orphaned substitution subshell keeps polling and keeps the resumed claude alive on the session that the successor resumes. The arm-close and boundary checks inside the runner do fix the wake-latency half. Sibling defect in the same runner: on abandonment, stop_engine_turn TERMs the engine. fm_warm_compact_engine then prints failed into verdict_file before the subshell exits, so the runner returns failed, not the documented nothing (comment at lines 600-602). warm_compact_tick then runs mark_engine_compacted. A compaction abandoned at the park boundary therefore marks the episode done although no compaction happened, and the next host never retries it. Fix: call run_warm_compact_engine directly, without $(...). Return the verdict in a global, for example WARM_COMPACT_VERDICT. Clear the verdict when the loop abandoned the turn. The handle path does the same at lines 1118-1132: it uses a bare wait, so the trap fires at once. Also remove the now-unused WARM_COMPACT_ENGINE_DONE= at line 570. No test covers a signal or an abandonment during a compaction.

🔧 Fix applied.
5 issues (1 error, 3 warnings, 1 info) still open:

  • 🚨 bin/fm-supervision-host.sh:569 - The engine's once-per-idle-episode marker (WARM_COMPACT_ENGINE_DONE) lives only in host process memory, but the engine episode spans host processes. choose_conversation (bin/fm-supervision-host.sh:845-855) resumes the recorded engine session across parks, and ended= in .supervision-host-engine changes only when a turn is handled. Failing sequence: (1) the engine handles a wake at T0. (2) The primary keeps working, and each Stop starts a fresh host with WARM_COMPACT_ENGINE_DONE empty. (3) After T0+idle-seconds, every new host's first tick finds idle>=2700 and compacted=0. (4) Each host then resumes the engine with /compact again. The size guard does not stop this. A /compact adds a compact_boundary and a summary user entry but no new assistant usage line, so fm_warm_compact_context_tokens (bin/fm-warm-compact-lib.sh:64-72) still reads the pre-compaction size. Result: one headless Claude run per primary turn end. Once the cache is cold, each run re-writes the context at the cache-write price, which is the cost Claude primary and supervision host are never compacted before cache expiry, so idle wakes re-write ~400k tokens #7755 (warm-compact) sets out to avoid. This breaks the intent's 'at most once per idle episode'. The primary has the same weakness, because WARM_COMPACT_PRIMARY_DONE (line 568) and the stale transcript size reset whenever the autoarm loop restarts the host in the same idle episode (bin/fm-claude-stop-autoarm.sh:446-451). Fix: persist the marker with the record it guards, for example compacted=&lt;ended&gt; in ENGINE_RECORD, written atomically like write_engine_record, and read it in warm_compact_tick. Also add a host-level test: two host runs over one engine record must produce one /compact. tests/fm-warm-compact.test.sh:118 only passes compacted=1 into the library, so it cannot catch this.
  • ⚠️ bin/fm-supervision-host.sh:592 - The engine compaction runs synchronously inside await_close, through a command substitution. That blocks the park loop for up to FM_WARM_COMPACT_ENGINE_TIMEOUT (300s) plus the engine grace. During that time the host does not see the arm close, so a real wake waits up to about 5 minutes. boundary_reached is also not checked. Bash defers the host's TERM/INT/HUP traps until the foreground command substitution returns, so a take-over or stop also waits that long. The compaction also bypasses ENGINE_RUNNING and ENGINE_PID_FILE, so cleanup/stop_engine_turn (lines 426-437, 448-450) cannot stop the engine. A host killed outright leaves the resumed claude process running on the session the successor resumes next. Its .warm-compact-msg/result/err temp files are also left behind, because the startup sweep only removes .supervision-host-* files (line 400). Fix: run the compaction like handle's engine turn (lines 1073-1090): background the subshell and wait on it, set ENGINE_RUNNING/ENGINE_SUBSHELL, pass ENGINE_PID_FILE to fm_supervision_engine_turn, and name the temp files under the swept .supervision-host-* prefix.
  • ⚠️ bin/fm-supervision-host.sh:585 - The engine check matches only engine= against the record. choose_conversation resumes a recorded session only when key, engine, and model all match and turns < ROTATE_TURNS (bin/fm-supervision-host.sh:845-848). The host can therefore compact a conversation that the next turn will never resume: after a model change, a prompt-key change, or a conversation at its 20-turn rotation limit. Each such compaction is a paid headless run of up to 300s with no benefit. Fix: apply the same model, key, and turns<ROTATE_TURNS predicate before calling fm_warm_compact_engine.
  • ⚠️ bin/fm-supervision-host.sh:590 - Fix round 1 did not close review-2 (abortable engine compaction). warm_compact_tick still calls the new runner through a command substitution: verdict=$(run_warm_compact_engine ...). So ENGINE_RUNNING=1 and ENGINE_SUBSHELL (lines 607, 615) are set only in the substitution's subshell, never in the host. The host also waits on a foreground command substitution, and bash defers the host's trap &#39;exit 143&#39; TERM (line 1218) until it returns. Failing sequence: (1) an engine compaction is in flight, for up to FM_WARM_COMPACT_ENGINE_TIMEOUT (300s). (2) A take-over calls stop_recorded on the host (lines 343-355): TERM, wait 10s, then KILL. (3) The TERM is deferred, so the KILL lands. cleanup never runs: no grant release or deactivate, no lease release, no arm retire, and no HOST_RECORD removal. The orphaned substitution subshell keeps polling and keeps the resumed claude alive on the session that the successor resumes. The arm-close and boundary checks inside the runner do fix the wake-latency half. Sibling defect in the same runner: on abandonment, stop_engine_turn TERMs the engine. fm_warm_compact_engine then prints failed into verdict_file before the subshell exits, so the runner returns failed, not the documented nothing (comment at lines 600-602). warm_compact_tick then runs mark_engine_compacted. A compaction abandoned at the park boundary therefore marks the episode done although no compaction happened, and the next host never retries it. Fix: call run_warm_compact_engine directly, without $(...). Return the verdict in a global, for example WARM_COMPACT_VERDICT. Clear the verdict when the loop abandoned the turn. The handle path does the same at lines 1118-1132: it uses a bare wait, so the trap fires at once. Also remove the now-unused WARM_COMPACT_ENGINE_DONE= at line 570. No test covers a signal or an abandonment during a compaction.
  • ℹ️ bin/fm-supervision-host.sh:619 - The round-2 fix (r2-1) is correct: the runner now runs in the host shell, so ENGINE_RUNNING and ENGINE_SUBSHELL are visible to cleanup, the TERM trap fires within one 0.5s sleep, and an abandoned compaction leaves WARM_COMPACT_VERDICT empty, so it is not marked. But no test covers the new abandon branch. Failing change a test should reject: drop the abandoned=1 guard at line 629, so the runner reads the failed verdict that fm_warm_compact_engine writes after it is TERMed. The episode is then marked although no compaction happened, and every current test still passes. Add a host test: a slow stub engine, close the arm during the compaction, then assert that the record has no compacted= line and that a later tick compacts. The test's oracle is the documented contract (an abandoned compaction is not marked).

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

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-warm-compact-herdr-live-e2e.test.sh:84 - The live e2e helper transcript() took the first jsonl in the project directory. That directory also holds the engine conversation's transcript, so the pending-wake check could read the wrong file and fail. It now selects the pane's own agent session file. This is a test-only change.
  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
An idle Claude primary in a Herdr lab is compacted once through the backend submit path, and not again in that episode ✅ pass live live-e2e.log: 'warm-compact primary sent'; primary transcript has 1 compaction boundary; no second primary compaction in the host log
The supervision host's engine conversation is compacted once by a resumed /compact after an away wake ✅ pass live live-e2e.log: 'warm-compact engine compacted'; engine context 18229 tokens afterward
Compaction never becomes captain-facing news (no wake queued) ✅ pass live the live e2e asserts the wake queue is empty after both compactions and it passed
A compacted primary still picks up a wake queued on disk afterward ✅ pass live live-e2e.log: 'compacted primary drained and acknowledged the wake queued after compaction'
Engine marker persists across host processes, and an engine session the next turn would not resume is skipped ⏸️ untested no The prior payload ran this only as host-suite tests against stub engines (host-subset.log). It did not drive it against the live product, so it records no live result.
A compaction abandoned at the park boundary is not marked done ⏸️ untested no The prior payload ran this only as a host-suite test against stub engines (host-subset.log). It did not drive it against the live product, so it records no live result.
  • bash tests/fm-warm-compact.test.sh
  • FM_WARM_COMPACT_LIVE_E2E=1 tests/fm-warm-compact-herdr-live-e2e.test.sh (run 1 failed at the last step because of the test's transcript lookup; run 2 passed after the fix)
  • bash tests/fm-supervision-host.test.sh (full suite; aborted on an unrelated timing case)
  • subset of tests/fm-supervision-host.test.sh: owner-only dialog files, engine conversation compacted once across hosts, conversation the next turn would not resume is not compacted, compaction abandoned at the park boundary is not marked done
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

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

✅ **Push** - passed

✅ No issues found.

…ecause the two new warm-compact tests had no timing hint. The runner packed them at the 45000 ms default, pushing the largest serial shard to 1204066 ms, over the 1200000 ms limit. I added measured hints in bin/fm-test-run.sh (fm-warm-compact.test.sh 1500, fm-warm-compact-herdr-live-e2e.test.sh 170). `bin/fm-test-run.sh --check-coverage` now passes (largest serial shard 1194253 ms), and tests/fm-supervision-instructions.test.sh passes. A full run of tests/fm-test-run.test.sh was killed at its time limit and did not finish, so it is unverified. The serial-shard failures in the logs were watcher/timing tests unrelated to warm-compact. I did not reproduce them locally. main also has a failing run. They need a rerun, not a code change
@kunchenguid
kunchenguid merged commit c1669d9 into kunchenguid:main Oct 26, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

It stays off unless a home adds config/warm-compact. It follows #7755 closely: it only types into an idle Claude primary with an empty composer, a compaction never reaches the captain, and the live run shows a compacted primary still picking up its wake from disk. All 19 checks were green on 8db254c6.

prishsu0730 pushed a commit to prishsu0730/firstmate that referenced this pull request Oct 29, 2026
…is warm (kunchenguid#7807)

* feat(bin): add opt-in warm-cache compaction for the Claude primary and host engine

Refs kunchenguid#7755

* no-mistakes(review): Persist engine compaction marker, run it abortable, match resume predicate

* no-mistakes(review): Run engine compaction in host shell; skip marker on abandon

* no-mistakes(review): Test abandoned engine compaction is not marked done

* no-mistakes(document): Clarify warm-compact episode and engine resume rules

* no-mistakes(lint): Fix ShellCheck SC2015 in engine compaction marker

* no-mistakes(ci): Test coverage guard and portable parallel 2 failed because the two new warm-compact tests had no timing hint. The runner packed them at the 45000 ms default, pushing the largest serial shard to 1204066 ms, over the 1200000 ms limit. I added measured hints in bin/fm-test-run.sh (fm-warm-compact.test.sh 1500, fm-warm-compact-herdr-live-e2e.test.sh 170). `bin/fm-test-run.sh --check-coverage` now passes (largest serial shard 1194253 ms), and tests/fm-supervision-instructions.test.sh passes. A full run of tests/fm-test-run.test.sh was killed at its time limit and did not finish, so it is unverified. The serial-shard failures in the logs were watcher/timing tests unrelated to warm-compact. I did not reproduce them locally. main also has a failing run. They need a rerun, not a code change

(cherry picked from commit c1669d9)
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.

2 participants