Skip to content

fix: start a fresh supervision branch for every main session - #3600

Merged
kunchenguid merged 3 commits into
mainfrom
fm/fm-supervision-branch-fresh-on-session-start-r1
Sep 3, 2026
Merged

kunchenguid merged 3 commits into
mainfrom
fm/fm-supervision-branch-fresh-on-session-start-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 3, 2026 •

Copy link
Copy Markdown
Owner

Intent

Make the Pi supervision branch start a FRESH conversation on EVERY main session start, including /new, /resume, /fork, and reload, instead of reopening the persistent JSONL that had been the same file since 2026-08-24. Captain authorized this on 2026-09-03.

Problem: the persistent branch session was actively harmful. Each session start re-armed the extension generation and the next wake reopened the branch session recorded in state/.branch-session, so the branch reloaded today's generated prompt and then weeks of old thread, letting stale memory (for example an old 'any PR mention is captain-facing' rule) outweigh current verdict rules.

Intent: whenever MAIN goes through a session start, the supervision branch must start a NEW conversation, and the old JSONL must not be reopened as the live branch context.

Must keep, explicitly not regressed: the durable outcome store and processed marker, so captain-facing sequences still re-present until MAIN acknowledges; generation and lock ownership and the fallback-to-main path on a broken branch; the branch prompt still generated from bin/fm-branch-prompt.sh.

Deliberate decisions made while implementing:

  • The branch conversation is now keyed to the main session generation (branchSessionGeneration/branchSessionFile held in memory). Only a record from the CURRENT generation is reopened, so a session start always builds a new conversation while a rebuild inside one session - which is what a model or effort change triggers - still continues that session's own conversation. Keying on the generation rather than a boolean flag is deliberate: it is race-safe when a session start lands while a build is in flight.
  • state/.branch-session is kept, but it is no longer the reopen source. It remains the durable record of the current conversation for operators and for the effort picker's last-resort model lookup, so its write-failure comment was corrected rather than the file removed.
  • The dialog-mirror cursor is deliberately RESET at every main session start, which the task allowed if stated explicitly. A new MirrorCollectionState.reanchor flag makes the first collection of a session ignore the durable cursor and re-anchor to the current main session's start. This is required for mirror correctness: /resume and reload keep main's OWN session file, so the cursor - which records what the PREVIOUS branch conversation received - would otherwise leave the new branch blind to dialog main itself still has. The reset is bounded by the current main session, costs only re-delivered read-only context, is never written from a session that does not own the fleet lock (the durable cursor still advances only in flushMirror), and the cursor keeps advancing incrementally within the session.
  • Earlier branch conversations are deliberately left on disk under state/branch-session/, as Pi keeps its own session files; no retention machinery was added.

Tests are colocated behavioral tests in tests/fm-pi-branch-extension.test.sh and assert observable behavior through the extension's real event and dispatch surface, never implementation source text: a new test proves a main session start (/new and a process restart) builds a NEW branch conversation and repoints state/.branch-session at it while a rebuild inside one session continues the same conversation, and a second new test proves the mirror re-anchor delivers the whole current main session's dialog to the new conversation and stays incremental afterwards. The old test that asserted reopen-from-pointer across restarts is gone, and the model-pin and effort-pin tests were re-targeted so their reopen-restore hazard is asserted on the intra-session rebuild path that still reopens. The stubbed SessionManager.create now names files per process so cross-restart file identity is observable.

Docs updated in their owners without duplicating the contract: docs/pi-supervision-branch.md (the contract owner: the per-main-session conversation, the mirror re-anchor, the cost model, and the verification list), docs/configuration.md (model and effort pins apply on the new conversation each session start opens and on the intra-session reopen), docs/supervision-protocols/pi.md, docs/verification/runtime-backends.md, AGENTS.md's state-layout line, and the extension's own header and inline comments.

Constraints: firstmate shared tracked material, so .agents/skills/firstmate-coding-guidelines applies - bin/fm-timeout-lib.sh stays the single owner of bounded execution, bash stays bash-3.2-safe for macOS, one sentence per line in tracked Markdown, plain dashes, and no co-author trailer on any commit. Delivery is no-mistakes with yolo off: the captain owns the merge, so stop at green CI and do not self-merge.

What Changed

  • Start a new Pi supervision branch conversation on every main session start while continuing the current conversation for model or effort rebuilds within the same session.
  • Re-anchor mirrored main dialog for each fresh branch conversation, then resume incremental cursor advancement within that session.
  • Update supervision documentation and behavioral tests for session replacement, process restart, mirror delivery, and model and effort selection.

Risk Assessment

✅ Low: The change is well-bounded, preserves durable outcome and fallback behavior, and correctly scopes branch conversations and mirror re-anchoring to each main-session generation.

Testing

An initial broad extension test invocation encountered an unrelated stock-rendering mismatch that also reproduces at the base commit; the focused lifecycle, durability, fallback, prompt-generation, generation, and lock-ownership tests passed, the regression failed on the base as expected, and the evidence transcript directly shows fresh files after session replacement/restart, same-file continuation within a session, pointer updates, retained old files, and mirror re-anchoring. No screenshot was captured because this is a non-visual session/state lifecycle change.

Evidence: Fresh branch conversation and mirror re-anchor behavioral transcript

Source: Fresh branch conversation and mirror re-anchor behavioral transcript

{"event":"mirror-reanchor","newConversationMessages":["[captain] standing order: never merge task-7","[captain] and hold task-9 too"],"afterIncremental":["[captain] standing order: never merge task-7","[captain] and hold task-9 too","[captain] task-9 may merge when green"]}
ok - the dialog mirror re-anchors for each session's new branch conversation and stays incremental within it
{"event":"same-process-session-start","initial":"created-75195-1.jsonl","sameSession":"created-75195-1.jsonl","sameSessionReopened":true,"replacement":"created-75195-2.jsonl","replacementReopened":false,"pointer":"created-75195-2.jsonl"}
{"event":"process-restart","prior":"created-75195-2.jsonl","restarted":"created-76880-1.jsonl","restartedOpened":false,"pointer":"created-76880-1.jsonl","priorRetained":true}
ok - every main session start begins a new branch conversation while one session keeps its own

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-pi-branch-extension.test.sh (initial broad invocation stopped at an unrelated installed-Pi stock-rendering mismatch)
  • Targeted tests/fm-pi-branch-extension.test.sh selectors covering dispatch/prompt generation, durable outcomes, fallback, in-flight selection changes, mirror re-anchoring, fresh session creation, generation safety, and lock ownership
  • Fresh-session regression test against base commit e1d1d692674b3908092e480ca0dee1743d9951a6 (failed as expected because it reopened the previous conversation)
  • Instrumented behavioral evidence run for test_branch_mirror_reanchors_for_the_new_session_branch_conversation and test_branch_session_is_new_at_every_main_session_start
  • Baseline stock-rendering check against base commit e1d1d692674b3908092e480ca0dee1743d9951a6 (reproduced the unrelated installed-Pi mismatch)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The supervision branch reopened one recorded conversation forever, so
every main session start reloaded the current generated prompt and then
weeks of accumulated thread, where a superseded rule could still outweigh
today's.

The branch conversation is now scoped to one main session: the session
generation owns the recorded conversation, so a cold start, /new,
/resume, /fork, or a reload always builds a new one, while a rebuild
inside one session (a model or effort change) still continues that
session's own conversation.

The dialog mirror re-anchors with it. Its durable cursor records what the
previous branch conversation received, so a /resume or reload - which
keeps main's own session file - would otherwise leave the new branch
blind to dialog main itself still has. The reset is bounded by the
current main session, and the cursor keeps advancing incrementally within
it. The durable outcome store and its processed marker are untouched, so
unacknowledged captain-facing outcomes still re-present on the new main
session.
@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(ci): Fixed the flaky concurr..." | Re-trigger Greptile

…sition now retries when a competing lock disappears between a failed claim and inspection. Added a behavioral regression covering that race. Verified the full inbox test four times, project lint, and git diff checks
@kunchenguid
kunchenguid merged commit 3d2a08b into main Sep 3, 2026
15 of 16 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-supervision-branch-fresh-on-session-start-r1 branch September 3, 2026 09:09
Marcos-Leyva added a commit to Marcos-Leyva/firstmate that referenced this pull request Sep 3, 2026