From e8f913fe15099a6e18b53ec8d4915d4c1fd74f0e Mon Sep 17 00:00:00 2001 From: Arjun Madhavan Date: Sun, 22 Nov 2026 11:22:04 -0500 Subject: [PATCH 1/5] feat(stow-guard): the token-line ask asks for a quick save, the daily ask keeps the full pass The context ask now asks for /stow quick, which runs only the knowledge sweep and open-record persistence. The age ask still asks for the full pass, and a stow Skill call whose first argument word is quick does not move last_stow, so the full pass still comes due once a day. --- .agents/skills/stow/SKILL.md | 21 +++- bin/fm-stow-guard.sh | 29 +++-- docs/configuration.md | 12 +- .../2026-11-22-stow-guard-quick-save.md | 12 ++ tests/fm-stow-guard.test.sh | 117 +++++++++++++++++- 5 files changed, 173 insertions(+), 18 deletions(-) create mode 100644 docs/fork-decisions/2026-11-22-stow-guard-quick-save.md diff --git a/.agents/skills/stow/SKILL.md b/.agents/skills/stow/SKILL.md index b31232fa..265d4eb2 100644 --- a/.agents/skills/stow/SKILL.md +++ b/.agents/skills/stow/SKILL.md @@ -2,7 +2,7 @@ name: stow description: >- Sweep the session for uncaptured durable knowledge and unfiled or wrong open work records, and curate startup memory. - Use when the captain invokes /stow (e.g. "/stow", "stow what you've learned"), before a session reset or context compaction, or periodically to keep operational memory current. + Use when the captain invokes /stow (e.g. "/stow", "stow what you've learned"), before a session reset or context compaction, or periodically to keep operational memory current; `/stow quick` is the short save the stow guard asks for at its token line. user-invocable: true metadata: internal: true @@ -16,6 +16,18 @@ Sweep this session for durable knowledge and open-work record state that exist o Memory entries are tiered and decay between passes, and stale material retires to a cold archive instead of being deleted. This skill writes only through the existing Firstmate ownership and write boundaries. +## Quick save (`/stow quick`) + +The mode is chosen by the first argument word: `quick`, in any case, selects the quick save, and anything else, including no argument, is the full pass every other section describes. +A `/stow` the captain types with no argument is always the full pass. +The stow guard asks for the quick save at its token line, because the full pass does not fit between that line and compaction; its daily age ask still asks for the full pass ([Stow guard](../../../docs/configuration.md#stow-guard-configstow-guard)). + +The quick save runs only [Knowledge sweep and routing](#knowledge-sweep-and-routing) and [Open-record persistence](#open-record-persistence): file unfiled findings, correct stale row notes, and record each captain answer held only in conversation through `bin/fm-captain-hold.sh answer`. +It skips the whole required startup-memory pass, so it reads no memory file in full and runs no decay, migration, consolidation, budget eviction, or offload; it also skips the cascade and the restart question. +A finding whose owner is a startup memory file gets a new entry only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave it on its task row, or in the receipt when it has none, for the next full pass. +Its receipt is a few lines: what it filed or corrected, and anything it left for the full pass. +It never says the session is reset-safe, so it never asks the captain to start fresh, even after a `/stow quick` he typed. + ## Memory tiers and entry markers Markers are compact trailing HTML comments, deliberately cheap because marker bytes are counted content: @@ -81,7 +93,7 @@ While the flag is present: ## Required startup-memory pass -Every `/stow` invocation performs this complete pass, even when the session contains no new finding: +Every full `/stow` pass performs this complete pass, even when the session contains no new finding; only the [quick save](#quick-save-stow-quick) skips it: 1. Run `bin/fm-startup-memory-budget.sh report` before considering a write. Record its effective budget and each file's estimated-token total. @@ -229,7 +241,7 @@ A local skill exists only in this home, so offloading an entry out of `data/capt Match each finding against the home's declared memory tiers first and capture a tier-owned finding to that tier, falling back to the local files only for classes no declared tier owns. When the owning tier is unreachable from this session, write the finding to the startup-loaded local memory file its class would otherwise use, or keep it where it already lives, carrying the pending-capture marker for that tier; it is still an exception for the receipt, never a reason to treat the local copy as sufficient. 3. **Write within the existing boundaries.** - - Captain preferences and fleet-local operational facts belong in the destination selected by AGENTS.md after the required whole-file curation pass. + - Captain preferences and fleet-local operational facts belong in the destination selected by AGENTS.md after the required whole-file curation pass, which a quick save replaces with its budget check. Create `data/learnings.md` only for a genuinely new local learning with no stronger owner. - In a primary home, curate shared captain preferences only under the existing primary-authoritative shared-preference contract. In a secondmate home, route a newly discovered shared preference to the main firstmate through marked status or a document pointer instead of editing the inherited file. @@ -272,6 +284,7 @@ The first pass after adoption performs a one-time revalidation sweep of editable ## Completion receipt +This is the full pass's receipt; the [quick save](#quick-save-stow-quick) writes its own short one. Report the outcome in plain captain-facing language with all of these facts: - effective startup-memory budget and total estimated tokens before and after; @@ -295,7 +308,7 @@ Apart from that re-run for his answer, ask nothing and leave `request` unrun aft ## Automatic cascade to secondmates -In a primary home, every `/stow` cascades to every registered secondmate after this home's own required pass and knowledge sweep are complete. +In a primary home, every full `/stow` pass cascades to every registered secondmate after this home's own required pass and knowledge sweep are complete. In a secondmate home, `/stow` curates that home only and never cascades further. The cascade changes nothing until `/stow` is invoked: it adds no notification, no digest section, and no background work. diff --git a/bin/fm-stow-guard.sh b/bin/fm-stow-guard.sh index 14c170c8..0071c607 100755 --- a/bin/fm-stow-guard.sh +++ b/bin/fm-stow-guard.sh @@ -17,8 +17,12 @@ # # The context ask fires once when the newest usage in the transcript tail is at # or above the token line, then again only after a later read falls below -# two-thirds of that line. The age ask fires when the newest seen /stow is -# older than the hour line, and then not again for an hour. It is skipped when +# two-thirds of that line. It asks for the stow skill's quick save +# (`/stow quick`), because a full pass does not fit between the line and +# compaction. The age ask fires when the newest seen full /stow is older than +# the hour line, and then not again for an hour; it asks for the full pass. +# When both are due on one stop, the context ask wins, and its ask time holds +# the age ask off for the next hour. The age ask is skipped when # a /stow timestamp cannot be read, including when python3 is missing, so a # just-completed /stow is not asked for again from a stale clock. The stored # state is what makes each ask once per crossing, so a continuation stop @@ -27,13 +31,15 @@ # # Context size is the same sum warm-cache compaction uses: input + cache_read # + cache_creation on the newest usage object in the last 2MB of the transcript. -# A /stow is a Skill tool call whose skill is stow, in that same tail. The -# newest one is remembered in state/.stow-guard.json, so a later tail that no -# longer contains it does not rewind the clock. +# A full /stow is a Skill tool call whose skill is stow, in that same tail, +# unless the first word of its args is quick (any case). A quick save does not +# move the clock, so the full pass still comes due after quick saves. The +# newest full one is remembered in state/.stow-guard.json as last_stow, so a +# later tail that no longer contains it does not rewind the clock. # -# The ask never offers a fresh restart and never writes an offer, so the -# /stow it asks for saves and keeps the session. It carries an existing offer -# through unchanged. +# Neither ask offers a fresh restart or writes an offer, so the /stow it asks +# for saves and keeps the session. It carries an existing offer through +# unchanged. # # With restart=1, `fm-stow-guard.sh prompt` is the one writer of that offer: # it records offer:{sid, at} for the session, and changes nothing else in the @@ -240,6 +246,8 @@ if [ -n "$transcript" ] && [ -r "$transcript" ]; then fromjson? | .timestamp as $ts | select($ts != null) | .message.content[]? | select(.type == "tool_use" and .name == "Skill" and .input.skill == "stow") + | select((.input.args // "" | tostring | ascii_downcase + | [splits("[[:space:]]+")] | map(select(. != "")) | .[0] // "") != "quick") | $ts ' | python3 -c 'import datetime, sys best = 0 @@ -279,15 +287,16 @@ reason= has_fired=$(jq -r --arg sid "$sid" 'if .[$sid] == true then "1" else "0" end' <<<"$fired") || exit 0 if [ "$tokens" -ge "$threshold" ] && [ "$has_fired" -eq 0 ]; then reason="fm-stow-guard: context is ${tokens} tokens, near auto-compaction." + reason="$reason Run the stow skill now with the argument quick (/stow quick) for a quick save, then continue the turn you were in." fired=$(jq -c --arg sid "$sid" '.[$sid] = true' <<<"$fired") || exit 0 elif [ "$saves_readable" -eq 1 ] && [ -z "$last_stow" ]; then last_stow=$now elif [ "$saves_readable" -eq 1 ] && [ $((now - last_stow)) -ge "$max_age" ] && [ $((now - asked)) -ge 3600 ]; then - reason="fm-stow-guard: the last /stow is older than ${hours}h." + reason="fm-stow-guard: the last full /stow is older than ${hours}h." + reason="$reason Run the /stow skill now (full pass, no argument), then continue the turn you were in." fi if [ -n "$reason" ]; then asked=$now - reason="$reason Run the /stow skill now (full pass), then continue the turn you were in." fi tmp=$(mktemp "$STATE/.stow-guard.json.XXXXXX") || exit 0 diff --git a/docs/configuration.md b/docs/configuration.md index fe8daac5..06e14aa1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1469,9 +1469,14 @@ The skill text owns the marker spelling, the tick order, and the reinforcement r Without the file the session is unchanged. With the file present, the Claude Stop hook `bin/fm-stow-guard.sh` blocks one turn end and tells that session to run the existing `/stow` skill. -It asks when the newest context reading in the transcript tail is at least `tokens` (default 300000), once per crossing, and again only after a later reading falls below two-thirds of that line. -It also asks when the newest `/stow` it has seen is at least `hours` old (default 24), and then not again for an hour. +It makes two asks. +The context ask comes when the newest context reading in the transcript tail is at least `tokens` (default 300000), once per crossing, and again only after a later reading falls below two-thirds of that line. +It asks for `/stow quick`, the skill's quick save: it files and corrects the open work records and findings the session holds, and skips the startup-memory curation, the cascade, and the restart question, so it fits in the room left before compaction. +The age ask comes when the newest full `/stow` it has seen is at least `hours` old (default 24), and then not again for an hour. +It asks for the full pass, and a quick save does not reset its clock, so the full pass still comes due once a day. +When both are due at one turn end, the context ask wins and the age ask waits an hour. That age ask is skipped when a `/stow` timestamp cannot be read. +The [stow skill](../.agents/skills/stow/SKILL.md#quick-save-stow-quick) owns what the quick save does. The stored state is what makes each ask once per crossing, so a continuation stop is handled like any other stop. A hook error does not block the turn, and the hook never compacts the session itself. It runs for a plain Claude primary checkout of this home. @@ -1484,7 +1489,8 @@ Remove the file to turn the ask off. The script header owns the transcript read, the state file, and the block message. With `restart=1`, a `/stow` the captain types himself in the primary's tmux or Herdr pane offers a fresh restart in place of compaction, through the same script's UserPromptSubmit hook. -A `/stow` that the guard's own ask, an agent, or the stow cascade starts makes no offer, so it saves everything and keeps the session. +A `/stow` that the guard's own ask, an agent, or the stow cascade starts makes no offer, so it saves and keeps the session. +A quick save never asks the fresh-start question, even when the captain types `/stow quick`. When the typed `/stow`'s receipt says the session is reset-safe, the primary asks the captain whether to start fresh now or keep the session. Only "Start fresh now" runs `bin/fm-helm-refresh.sh request`, and once its turn ends the session is cleared with Claude Code's `/clear` and started again by one doorbell. The process, its session lock, its parked supervision, its Remote Control session, and its session name stay the same, while the context drops back to the fresh-start set. diff --git a/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md b/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md new file mode 100644 index 00000000..a5574d61 --- /dev/null +++ b/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md @@ -0,0 +1,12 @@ +2026-11-22: Arjun answered "Yes" in the helm to the recommendation that the stow guard ask for a quick save at its token line and keep the full pass for its daily age ask. +The guard asks at `tokens=240000` against a compaction near 300K, and a full pass (budget report, all three memory files, date checks, curation, the cascade) used up that gap: compaction hit in the middle of the pass, the helm re-read its 69KB startup digest to finish, and the pass captured only a few lines because open work was already on durable records. +Decision: the context ask asks for `/stow quick`, which runs only the knowledge sweep and open-record persistence, adds a memory entry only when the budget report shows room, skips the startup-memory pass, the cascade and the restart question, and never says reset-safe. +The age ask (`hours=`, default 24) still asks for the full pass, and a quick save does not move its clock (`last_stow` in `state/.stow-guard.json`), so the full pass still comes due once a day after quick saves. +The guard tells them apart by the stow Skill call's args: a first word of `quick` is a quick save, anything else is the full pass. +The once-per-crossing state, the offer handling and `restart=1` are unchanged, and a guard ask still never offers a restart; the fresh restart still follows only a `/stow` the captain types and his "Start fresh now" pick, so this amends the "saves everything" wording of [the typed-stow restart record](2026-11-22-typed-stow-restarts-helm.md) and nothing else in it. +No upstream proposal yet: the stow guard is upstream's, but its token line and this fleet's long-running helm are what made the full pass too big for the gap. + +| What | Files or functions | Upstream code touched | Status | Last checked sync | +| --- | --- | --- | --- | --- | +| The stow guard's context ask asks for `/stow quick`, its age ask for the full pass, and a quick save does not move the full pass's clock | `bin/fm-stow-guard.sh` (header, transcript read, block messages), `tests/fm-stow-guard.test.sh`, `docs/configuration.md` ("Stow guard") | `bin/fm-stow-guard.sh`, `tests/fm-stow-guard.test.sh`, `docs/configuration.md` | carried | 427056c4 | +| The stow skill gains a quick save mode selected by the `quick` argument | `.agents/skills/stow/SKILL.md` (description, "Quick save", startup-memory pass, sweep step 3, receipt, cascade) | `.agents/skills/stow/SKILL.md` | carried | 427056c4 | diff --git a/tests/fm-stow-guard.test.sh b/tests/fm-stow-guard.test.sh index 81edf835..15cb32ed 100755 --- a/tests/fm-stow-guard.test.sh +++ b/tests/fm-stow-guard.test.sh @@ -121,7 +121,7 @@ test_guard_ask_never_offers_a_restart() { payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" \ TMUX_PANE=%7 HERDR_ENV= || rc=$? [ "$rc" -eq 0 ] || fail "the guard's ask with restart=1 must exit 0, got $rc" - assert_block "the guard's ask with restart=1" "Run the /stow skill now (full pass), then continue the turn you were in." + assert_block "the guard's ask with restart=1" "with the argument quick (/stow quick) for a quick save, then continue the turn you were in." ! grep -q 'fm-helm-refresh' "$OUT" || fail "the guard's ask offered a restart: $(cat "$OUT")" jq -e 'has("offer") | not' "$CASE_STATE/.stow-guard.json" >/dev/null \ || fail "the guard's ask recorded an offer: $(cat "$CASE_STATE/.stow-guard.json")" @@ -391,6 +391,118 @@ test_recorded_stow_sets_the_age_clock() { pass "a Skill /stow sets the age clock and a later tail does not rewind it" } +# write_stow []: append a stow Skill call, with args only +# when given, so a call with no args stays the shape Claude Code writes. +write_stow() { + jq -nc --arg ts "$1" --arg args "${2-}" --argjson has_args "$([ $# -ge 2 ] && echo true || echo false)" \ + '{timestamp:$ts,message:{content:[{type:"tool_use",name:"Skill",input:({skill:"stow"} + (if $has_args then {args:$args} else {} end))}],usage:{input_tokens:10,cache_read_input_tokens:0,cache_creation_input_tokens:0}}}' \ + >> "$CASE_TRANSCRIPT" +} + +iso_epoch() { + python3 -c 'import datetime, sys; print(int(datetime.datetime.fromisoformat(sys.argv[1].replace("Z", "+00:00")).timestamp()))' "$1" +} + +test_each_ask_names_its_pass() { + local rc=0 now=1700000000 + prepare_case ask-context + printf 'tokens=1000\n' > "$CASE_CONFIG/stow-guard" + write_usage 1200 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "the context ask must exit 0, got $rc" + assert_block "the context ask" "Run the stow skill now with the argument quick (/stow quick) for a quick save" + ! grep -q 'full pass' "$OUT" || fail "the context ask asked for the full pass: $(cat "$OUT")" + + prepare_case ask-age + : > "$CASE_CONFIG/stow-guard" + printf '{"last_stow":%s,"asked":0,"fired":{}}\n' "$((now - 86400))" > "$CASE_STATE/.stow-guard.json" + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "the age ask must exit 0, got $rc" + assert_block "the age ask" "Run the /stow skill now (full pass, no argument)" + ! grep -q 'quick' "$OUT" || fail "the age ask asked for a quick save: $(cat "$OUT")" + pass "the context ask asks for /stow quick and the age ask asks for the full pass" +} + +test_quick_save_does_not_move_the_full_pass_clock() { + local rc=0 full quick now + command -v python3 >/dev/null 2>&1 || { + pass "a quick save does not move the full pass clock (skipped, python3 not found)" + return + } + prepare_case quick-clock + : > "$CASE_CONFIG/stow-guard" + full=$(iso_epoch 2026-01-01T00:00:00Z) + quick=$(iso_epoch 2026-01-01T06:00:00Z) + write_stow 2026-01-01T00:00:00Z + write_stow 2026-01-01T06:00:00Z quick + now=$((quick + 100)) + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "a tail with a full and a newer quick save must exit 0, got $rc" + assert_silent "a tail with a full and a newer quick save" + jq -e --argjson full "$full" '.last_stow == $full' "$CASE_STATE/.stow-guard.json" >/dev/null \ + || fail "a newer quick save moved the clock past the full pass: $(cat "$CASE_STATE/.stow-guard.json")" + + # Only quick saves after it, each spelled another way: the age ask still comes due. + : > "$CASE_TRANSCRIPT" + write_stow 2026-01-01T12:00:00Z ' Quick' + write_stow 2026-01-01T18:00:00Z $'quick\tat the token line' + write_stow 2026-01-01T23:00:00Z QUICK + now=$((full + 86400)) + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "a quick-only tail a day after the full pass must exit 0, got $rc" + assert_block "a quick-only tail a day after the full pass" "Run the /stow skill now (full pass, no argument)" + jq -e --argjson full "$full" '.last_stow == $full' "$CASE_STATE/.stow-guard.json" >/dev/null \ + || fail "quick saves moved the clock: $(cat "$CASE_STATE/.stow-guard.json")" + + # A stow call with other args, or a word that only starts with quick, is a full pass. + : > "$CASE_TRANSCRIPT" + write_stow 2026-01-02T01:00:00Z 'quickly please' + now=$(($(iso_epoch 2026-01-02T01:00:00Z) + 100)) + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "a stow call with other args must exit 0, got $rc" + assert_silent "a stow call with other args" + jq -e --argjson stamp "$(iso_epoch 2026-01-02T01:00:00Z)" '.last_stow == $stamp' "$CASE_STATE/.stow-guard.json" >/dev/null \ + || fail "a stow call with other args did not move the clock: $(cat "$CASE_STATE/.stow-guard.json")" + + # On the first opt-in stop, a quick-only tail starts the clock at now, as an empty tail does. + prepare_case quick-first + : > "$CASE_CONFIG/stow-guard" + write_stow 2026-01-01T06:00:00Z quick + now=$((quick + 100)) + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "a first stop with only a quick save must exit 0, got $rc" + assert_silent "a first stop with only a quick save" + jq -e --argjson now "$now" '.last_stow == $now' "$CASE_STATE/.stow-guard.json" >/dev/null \ + || fail "a quick-only first stop did not start the clock at now: $(cat "$CASE_STATE/.stow-guard.json")" + pass "a quick save leaves last_stow on the newest full pass, the age ask still comes due, and other args count as a full pass" +} + +test_both_asks_due_asks_quick_then_full_an_hour_later() { + local rc=0 now=1700000000 + prepare_case both-due + printf 'tokens=1000\n' > "$CASE_CONFIG/stow-guard" + printf '{"last_stow":%s,"asked":0,"fired":{}}\n' "$((now - 2 * 86400))" > "$CASE_STATE/.stow-guard.json" + write_usage 1200 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$now" || rc=$? + [ "$rc" -eq 0 ] || fail "a stop with both asks due must exit 0, got $rc" + assert_block "a stop with both asks due" "(/stow quick) for a quick save" + + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$((now + 60))" || rc=$? + [ "$rc" -eq 0 ] || fail "the next stop inside the hour must exit 0, got $rc" + assert_silent "the next stop inside the hour" + + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$((now + 3600))" || rc=$? + [ "$rc" -eq 0 ] || fail "the stop an hour later must exit 0, got $rc" + assert_block "the stop an hour later" "Run the /stow skill now (full pass, no argument)" + pass "with both asks due the context ask asks for a quick save, and the age ask asks for the full pass an hour later" +} + test_crew_worktree_is_silent() { local child="$TMP_ROOT/child" rc=0 git -C "$PRIMARY" add AGENTS.md @@ -567,6 +679,9 @@ fm_test_run \ test_continuation_stop_blocks_once_per_crossing \ test_age_interval_blocks_once_per_hour \ test_recorded_stow_sets_the_age_clock \ + test_each_ask_names_its_pass \ + test_quick_save_does_not_move_the_full_pass_clock \ + test_both_asks_due_asks_quick_then_full_an_hour_later \ test_crew_worktree_is_silent \ test_secondmate_home_is_silent \ test_missing_python_skips_the_age_ask \ From 0d2459048e9dcf5df39d1bdfc509064de106bbed Mon Sep 17 00:00:00 2001 From: Arjun Madhavan Date: Sun, 22 Nov 2026 11:24:54 -0500 Subject: [PATCH 2/5] fix(stow): a quick save leaves existing memory entries alone and budget-checks every new one --- .agents/skills/stow/SKILL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.agents/skills/stow/SKILL.md b/.agents/skills/stow/SKILL.md index 265d4eb2..a59cc72a 100644 --- a/.agents/skills/stow/SKILL.md +++ b/.agents/skills/stow/SKILL.md @@ -24,7 +24,8 @@ The stow guard asks for the quick save at its token line, because the full pass The quick save runs only [Knowledge sweep and routing](#knowledge-sweep-and-routing) and [Open-record persistence](#open-record-persistence): file unfiled findings, correct stale row notes, and record each captain answer held only in conversation through `bin/fm-captain-hold.sh answer`. It skips the whole required startup-memory pass, so it reads no memory file in full and runs no decay, migration, consolidation, budget eviction, or offload; it also skips the cascade and the restart question. -A finding whose owner is a startup memory file gets a new entry only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave it on its task row, or in the receipt when it has none, for the next full pass. +Within the sweep, it leaves existing memory entries alone: archiving, offloading, consolidating, and retiring superseded copies of a ruling in memory all wait for the next full pass, while it still records answers and corrects open records. +It adds any new startup-memory entry, a pending-capture fallback included, only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave the finding on its task row, or in the receipt when it has none, for the next full pass. Its receipt is a few lines: what it filed or corrected, and anything it left for the full pass. It never says the session is reset-safe, so it never asks the captain to start fresh, even after a `/stow quick` he typed. From 06da7f5c213e07c1cae441440eb79b68bbb3cbc8 Mon Sep 17 00:00:00 2001 From: Arjun Madhavan Date: Sun, 22 Nov 2026 11:25:48 -0500 Subject: [PATCH 3/5] fix(stow): a quick save leaves a superseding memory write to the full pass --- .agents/skills/stow/SKILL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.agents/skills/stow/SKILL.md b/.agents/skills/stow/SKILL.md index a59cc72a..82f16a1d 100644 --- a/.agents/skills/stow/SKILL.md +++ b/.agents/skills/stow/SKILL.md @@ -25,7 +25,8 @@ The stow guard asks for the quick save at its token line, because the full pass The quick save runs only [Knowledge sweep and routing](#knowledge-sweep-and-routing) and [Open-record persistence](#open-record-persistence): file unfiled findings, correct stale row notes, and record each captain answer held only in conversation through `bin/fm-captain-hold.sh answer`. It skips the whole required startup-memory pass, so it reads no memory file in full and runs no decay, migration, consolidation, budget eviction, or offload; it also skips the cascade and the restart question. Within the sweep, it leaves existing memory entries alone: archiving, offloading, consolidating, and retiring superseded copies of a ruling in memory all wait for the next full pass, while it still records answers and corrects open records. -It adds any new startup-memory entry, a pending-capture fallback included, only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave the finding on its task row, or in the receipt when it has none, for the next full pass. +A finding that would replace or contradict an existing memory entry, such as a changed captain ruling, gets no new memory entry either: record the answer on its origin row and leave the memory write to the full pass. +It adds any other new startup-memory entry, a pending-capture fallback included, only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave the finding on its task row, or in the receipt when it has none, for the next full pass. Its receipt is a few lines: what it filed or corrected, and anything it left for the full pass. It never says the session is reset-safe, so it never asks the captain to start fresh, even after a `/stow quick` he typed. From cb635ef2ed5156efe4eb345be76ae110212f9e25 Mon Sep 17 00:00:00 2001 From: Arjun Madhavan Date: Sun, 22 Nov 2026 11:26:34 -0500 Subject: [PATCH 4/5] docs(stow): a quick save routes a non-answer superseding finding to its row or receipt --- .agents/skills/stow/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.agents/skills/stow/SKILL.md b/.agents/skills/stow/SKILL.md index 82f16a1d..995db295 100644 --- a/.agents/skills/stow/SKILL.md +++ b/.agents/skills/stow/SKILL.md @@ -25,7 +25,7 @@ The stow guard asks for the quick save at its token line, because the full pass The quick save runs only [Knowledge sweep and routing](#knowledge-sweep-and-routing) and [Open-record persistence](#open-record-persistence): file unfiled findings, correct stale row notes, and record each captain answer held only in conversation through `bin/fm-captain-hold.sh answer`. It skips the whole required startup-memory pass, so it reads no memory file in full and runs no decay, migration, consolidation, budget eviction, or offload; it also skips the cascade and the restart question. Within the sweep, it leaves existing memory entries alone: archiving, offloading, consolidating, and retiring superseded copies of a ruling in memory all wait for the next full pass, while it still records answers and corrects open records. -A finding that would replace or contradict an existing memory entry, such as a changed captain ruling, gets no new memory entry either: record the answer on its origin row and leave the memory write to the full pass. +A finding that would replace or contradict an existing memory entry, such as a changed captain ruling, gets no new memory entry either: record a captain answer on its origin row, leave any other such finding on its task row or in the receipt, and leave the memory write to the full pass. It adds any other new startup-memory entry, a pending-capture fallback included, only when `bin/fm-startup-memory-budget.sh report` shows the new entry fits within the effective budget; otherwise leave the finding on its task row, or in the receipt when it has none, for the next full pass. Its receipt is a few lines: what it filed or corrected, and anything it left for the full pass. It never says the session is reset-safe, so it never asks the captain to start fresh, even after a `/stow quick` he typed. From 37007e0cc32bc34fc3a854c84cfcb253dc51df5b Mon Sep 17 00:00:00 2001 From: Arjun Madhavan Date: Sun, 22 Nov 2026 11:29:26 -0500 Subject: [PATCH 5/5] fix(stow-guard): the age ask waits while the context is over the token line --- bin/fm-stow-guard.sh | 9 ++++++--- docs/configuration.md | 3 ++- .../2026-11-22-stow-guard-quick-save.md | 1 + tests/fm-stow-guard.test.sh | 20 ++++++++++++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/bin/fm-stow-guard.sh b/bin/fm-stow-guard.sh index 0071c607..1e3251a5 100755 --- a/bin/fm-stow-guard.sh +++ b/bin/fm-stow-guard.sh @@ -21,8 +21,10 @@ # (`/stow quick`), because a full pass does not fit between the line and # compaction. The age ask fires when the newest seen full /stow is older than # the hour line, and then not again for an hour; it asks for the full pass. -# When both are due on one stop, the context ask wins, and its ask time holds -# the age ask off for the next hour. The age ask is skipped when +# It waits while the context reading is at or above the token line, so the +# full pass comes after a compaction or a fresh start, never in the gap before +# compaction. When both are due on one stop, the context ask wins, and its ask +# time holds the age ask off for the next hour. The age ask is skipped when # a /stow timestamp cannot be read, including when python3 is missing, so a # just-completed /stow is not asked for again from a stale clock. The stored # state is what makes each ask once per crossing, so a continuation stop @@ -291,7 +293,8 @@ if [ "$tokens" -ge "$threshold" ] && [ "$has_fired" -eq 0 ]; then fired=$(jq -c --arg sid "$sid" '.[$sid] = true' <<<"$fired") || exit 0 elif [ "$saves_readable" -eq 1 ] && [ -z "$last_stow" ]; then last_stow=$now -elif [ "$saves_readable" -eq 1 ] && [ $((now - last_stow)) -ge "$max_age" ] && [ $((now - asked)) -ge 3600 ]; then +elif [ "$saves_readable" -eq 1 ] && [ "$tokens" -lt "$threshold" ] \ + && [ $((now - last_stow)) -ge "$max_age" ] && [ $((now - asked)) -ge 3600 ]; then reason="fm-stow-guard: the last full /stow is older than ${hours}h." reason="$reason Run the /stow skill now (full pass, no argument), then continue the turn you were in." fi diff --git a/docs/configuration.md b/docs/configuration.md index 06e14aa1..15f589d5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1474,7 +1474,8 @@ The context ask comes when the newest context reading in the transcript tail is It asks for `/stow quick`, the skill's quick save: it files and corrects the open work records and findings the session holds, and skips the startup-memory curation, the cascade, and the restart question, so it fits in the room left before compaction. The age ask comes when the newest full `/stow` it has seen is at least `hours` old (default 24), and then not again for an hour. It asks for the full pass, and a quick save does not reset its clock, so the full pass still comes due once a day. -When both are due at one turn end, the context ask wins and the age ask waits an hour. +It waits while the context reading is at or above `tokens`, so the full pass runs after a compaction or a fresh start, not in the gap before compaction. +When both are due at one turn end, the context ask wins and the age ask waits at least an hour. That age ask is skipped when a `/stow` timestamp cannot be read. The [stow skill](../.agents/skills/stow/SKILL.md#quick-save-stow-quick) owns what the quick save does. The stored state is what makes each ask once per crossing, so a continuation stop is handled like any other stop. diff --git a/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md b/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md index a5574d61..e4465842 100644 --- a/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md +++ b/docs/fork-decisions/2026-11-22-stow-guard-quick-save.md @@ -3,6 +3,7 @@ The guard asks at `tokens=240000` against a compaction near 300K, and a full pas Decision: the context ask asks for `/stow quick`, which runs only the knowledge sweep and open-record persistence, adds a memory entry only when the budget report shows room, skips the startup-memory pass, the cascade and the restart question, and never says reset-safe. The age ask (`hours=`, default 24) still asks for the full pass, and a quick save does not move its clock (`last_stow` in `state/.stow-guard.json`), so the full pass still comes due once a day after quick saves. The guard tells them apart by the stow Skill call's args: a first word of `quick` is a quick save, anything else is the full pass. +The age ask also waits while the context reading is at or above the token line, because once quick saves stop resetting its clock it could otherwise ask for the full pass in the same gap before compaction; the merge-gate review on the PR found that case. The once-per-crossing state, the offer handling and `restart=1` are unchanged, and a guard ask still never offers a restart; the fresh restart still follows only a `/stow` the captain types and his "Start fresh now" pick, so this amends the "saves everything" wording of [the typed-stow restart record](2026-11-22-typed-stow-restarts-helm.md) and nothing else in it. No upstream proposal yet: the stow guard is upstream's, but its token line and this fleet's long-running helm are what made the full pass too big for the gap. diff --git a/tests/fm-stow-guard.test.sh b/tests/fm-stow-guard.test.sh index 15cb32ed..bc748c88 100755 --- a/tests/fm-stow-guard.test.sh +++ b/tests/fm-stow-guard.test.sh @@ -481,7 +481,7 @@ test_quick_save_does_not_move_the_full_pass_clock() { pass "a quick save leaves last_stow on the newest full pass, the age ask still comes due, and other args count as a full pass" } -test_both_asks_due_asks_quick_then_full_an_hour_later() { +test_both_asks_due_asks_quick_then_full_below_the_line() { local rc=0 now=1700000000 prepare_case both-due printf 'tokens=1000\n' > "$CASE_CONFIG/stow-guard" @@ -496,11 +496,21 @@ test_both_asks_due_asks_quick_then_full_an_hour_later() { [ "$rc" -eq 0 ] || fail "the next stop inside the hour must exit 0, got $rc" assert_silent "the next stop inside the hour" + # An hour later the context is still over the line, so the full pass waits. + write_usage 1300 rc=0 payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$((now + 3600))" || rc=$? - [ "$rc" -eq 0 ] || fail "the stop an hour later must exit 0, got $rc" - assert_block "the stop an hour later" "Run the /stow skill now (full pass, no argument)" - pass "with both asks due the context ask asks for a quick save, and the age ask asks for the full pass an hour later" + [ "$rc" -eq 0 ] || fail "the stop an hour later over the line must exit 0, got $rc" + assert_silent "the stop an hour later over the line" + + # After a compaction drops the context below the line, the full pass is asked for. + : > "$CASE_TRANSCRIPT" + write_usage 500 + rc=0 + payload | invoke_guard "$PRIMARY" "$CASE_STATE" "$CASE_CONFIG" FM_STOW_GUARD_NOW="$((now + 3700))" || rc=$? + [ "$rc" -eq 0 ] || fail "the stop below the line must exit 0, got $rc" + assert_block "the stop below the line" "Run the /stow skill now (full pass, no argument)" + pass "with both asks due the context ask asks for a quick save, and the age ask waits until the context is below the line" } test_crew_worktree_is_silent() { @@ -681,7 +691,7 @@ fm_test_run \ test_recorded_stow_sets_the_age_clock \ test_each_ask_names_its_pass \ test_quick_save_does_not_move_the_full_pass_clock \ - test_both_asks_due_asks_quick_then_full_an_hour_later \ + test_both_asks_due_asks_quick_then_full_below_the_line \ test_crew_worktree_is_silent \ test_secondmate_home_is_silent \ test_missing_python_skips_the_age_ask \