Repository navigation
Restart a second mate when its conversation passes the context limit - #49
Merged
Merged
Conversation
uayyagari
marked this pull request as draft
October 26, 2026 18:00
uayyagari
marked this pull request as ready for review
October 27, 2026 10:56
A mate that keeps taking wakes without finishing a piece of work never asked for a fresh session, so every call re-read an ever longer conversation. The watcher sweep now reads each local Claude mate's transcript and files the same handover request once it passes FM_SECONDMATE_CONTEXT_LIMIT (default 100000). The existing guards still decide when the restart happens.
A fresh second-mate session starts near 78k tokens of context, not 20k. With that start a 100k limit costs 8.2% more on 26 Oct transcripts; 150k saves 6.0% for second mates and 25.4% for the main supervisor. The restart prompt now says the context limit caused it, and the replay takes --homes and warns when it skips old transcripts.
uayyagari
force-pushed
the
fm/qwr-supervisor-context
branch
from
October 27, 2026 10:59
17cbad2 to
59fe78f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fix
bin/fm-secondmate-fresh-session.sh sweepnow also reads each local Claude mate's newest transcript. PastFM_SECONDMATE_CONTEXT_LIMIT(default 150000, 0 = off) it files the same request and handover note as a finished piece of work (--source context --verb handover).applyguards decide when the restart happens: no open request, no unread steering message, no unacknowledged wake, agent idle. Child workers keep running, and the note points at the session-start digest, which lists open decisions and unread status.bin/fm-context-replay.pyreplays transcripts with a limit for before/after numbers.Worked example
Mate
sm1is at 250105 tokens (250000 cache read + 100 cache creation + 5 input) and has child1 in flight.Proof
bash tests/fm-secondmate-fresh-session.test.sh(new T9: small context and limit 0 do nothing, a large context defers on an unread message then restarts, no second restart) andbash tests/fm-context-replay.test.shpass;bin/fm-lint.shclean.python3 -I bin/fm-context-replay.py 2026-10-24,2026-10-25,2026-10-26 --limit <N>with the measured fresh-session start of 78000 tokens (median first-call context of real second-mate sessions; an earlier 20k start was wrong and made 100k look better than it is):26 Oct alone, second-mate homes: 100k = 8.2% MORE tokens, 120k = 1.2% saved, 150k = 5.5% saved, 200k = 4.7% saved. So the default is 150k. The replay is a best case: it ignores waiting for an idle moment.
Local results after rebasing onto origin/main (PRs 52-55 merged), no final no-mistakes run, no GitHub checks (captain instruction):
tests/fm-context-replay.test.shand the fulltests/fm-secondmate-fresh-session.test.sh(T1-T9) pass;bin/fm-lint.shclean;bin/fm-fork-footprint.sh --base origin/main --upstream upstream/main: 3 upstream files touched (+167/-3), all Fork-only block or on the fork ledger, Result: ok.Fork footprint vs upstream main