Skip to content

Clear main and second mates into a fresh conversation past a set size - #40

Merged
jjtylr merged 1 commit into
mainfrom
fm/fm-auto-context-reset
Nov 27, 2026
Merged

jjtylr merged 1 commit into
mainfrom
fm/fm-auto-context-reset

Conversation

@jjtylr

@jjtylr jjtylr commented Nov 27, 2026

Copy link
Copy Markdown
Owner

What this is

Main and every second mate get a fresh conversation once theirs grows large: from 150,000 tokens they are cleared at their next idle moment, and always before 200,000. A clear starts a new conversation after the supervisor writes down its open work (the /stow skill's open-record persistence only). It never compacts. config/supervisor-clear can change both sizes or turn the policy off.

How it works

  • bin/fm-supervisor-clear.sh owns the policy. Its header holds the rules, and docs/configuration.md "Supervisor clear policy" holds the settings.
  • Where it runs: the watcher runs one pass every two minutes. Restarts and the /clear helper run in their own process group, so nothing new is added to supervision.
  • Measurement: sizes come from the existing bin/fm-context-size.sh, unchanged, which already reads remote mates.
  • Second mates:
    • A mate over 150,000 that is idle by its busy state is restarted with fm-secondmate-restart.sh --keep-profile --reason context.
    • A busy mate is tried again on a later pass.
    • At 200,000 a busy mate is restarted anyway. The save request waits behind its current turn and asks it to finish that step first. The restart waits for its answer.
    • --keep-profile keeps the harness, model and effort in the mate's record, for both local and remote mates. Without the flag, the update-time restart works as before.
  • Main:
    • At 150,000, main gets a check: supervisor-clear: notification. It asks main to save its open work, run fm-supervisor-clear.sh saved, and end the turn.
    • A helper outside main's conversation then types /clear into main's pane. Session start records that pane (backend and target from main's own environment), so it is never guessed. The helper types only when all of these hold:
      • Herdr reports the agent idle, and no busy footer shows.
      • The input box is proven empty on two reads 3 seconds apart.
      • Nothing on screen changed between those reads.
      • No model call ran in the last 10 seconds.
    • If any check fails, it types nothing and tries again on the next pass. Main's session start then re-records the pane, which confirms the clear.
    • At 200,000, if main never saved, the pane was never safe, or the runtime cannot be cleared this way (anything but Claude in tmux or Herdr), main is told to tell the captain in one line that main needs a /clear.
  • Log: every ask, save, clear, skip and restart is one line in state/supervisor-clear/clear.log (who, size before, when).

Tests

  • New tests/fm-supervisor-clear.test.sh has 14 cases. It uses real size reads from a sample session log, the real busy-state record, and a stand-in pane.
    • Trigger cases: an idle mate is restarted; a busy mate waits until the hard size; attempts are spaced apart; readings from before a restart are ignored; main is told once per level; the config file and an invalid config; a second mate's home never clears itself.
    • Pane-typing guard cases: text in the input box, a turn in progress, a changing pane, and a recent model call each stop the typing. A clean idle pane gets exactly one /clear, and the clear is confirmed and logged.
  • New case in tests/fm-secondmate-restart.test.sh: a restart with --keep-profile --reason context keeps the recorded model and effort, both locally and over the remote hop. Today's code rejects the flag, so this case fails there.
  • Ran and passing: both of those files, all 12 watcher suites, fm-session-start.test.sh, bin/fm-lint.sh, and bin/fm-doc-audience-check.sh.

Notes

  • bin/fm-test-run.sh --check-coverage already reports a shard over its 900,000 ms target on main without this change. Fixing that needs CI timing hints, which this PR does not change.
  • Not done: a live run in a Herdr lab that types /clear into a real Claude pane. The guard uses the busy and input-box checks the away-mode injection already relies on. A live check can be added if wanted.
  • Out of scope and unchanged: ship and scout workers, autocompact settings, startup context size, and models or effort.

A supervisor whose conversation reaches 150,000 tokens is cleared at its
next idle moment, and always before 200,000; config/supervisor-clear
changes both or turns the policy off. A clear is a fresh conversation after
the supervisor writes down its open work, never a compaction.

- bin/fm-supervisor-clear.sh owns the policy. The watcher runs one pass
  every two minutes; restarts and the /clear helper run detached.
- Second mates over the soft size and idle, or any at the hard size, are
  restarted through fm-secondmate-restart.sh --keep-profile --reason
  context, which keeps the recorded harness, model and effort and asks a
  mate mid-turn to finish its step first.
- Main is told through a check wake to save its open work and run
  `fm-supervisor-clear.sh saved`. A helper outside main's conversation then
  types /clear into main's recorded pane only when the pane is idle, the
  input box is proven empty, nothing changed between two reads, and no
  model call just ran. Session start records main's pane and confirms the
  clear. At the hard size, anything that blocks the clear becomes one line
  for the captain.
- Every ask, save, clear, skip and restart is logged in
  state/supervisor-clear/clear.log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant