feat: add recoverable primary session handoff - #1239
Open
tmad4000 wants to merge 8 commits into
Open
Conversation
Owner
|
Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for firstmate#1239 at |
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.
Intent
Implement a first-class, recoverable primary-session takeover primitive for Firstmate using the 2026-07-29 live Paseo/Claude credit-exhaustion incident as the reproduction. Provide an agent-ergonomic scan/takeover/restore command family that persists or resolves the exact visible provider identity, proves it is the live lock owner, deterministically refuses busy, captain-action, unresolved-input, child-agent, wedged, unknown, or unsupported sessions, soft-archives only a safely recoverable idle or rate-limited provider, verifies the recorded process tree is gone, and then uses the canonical stale-lock acquisition and ordinary session-start path without deleting or weakening a live lock or permitting dual orchestration. Preserve provider transcripts and all fleet/task state; write privacy-safe durable receipts; make restoration explicit, refuse it under a live successor, and require normal lock reacquisition before restored mutation. Include a fleet-wide read-only captain-action scan, clearly classify supported primary harness/runtime combinations, place mechanics in script help with conditional policy in an agent-only skill and human/verification material in docs, and add deterministic safety and recovery tests using only fake/disposable providers. Do not manipulate any real current provider or agent while developing or validating.
What Changed
Risk Assessment
✅ Low: Captain, the change is large but tightly scoped around a guarded primary-session handoff path with fail-closed transaction checks and focused fake-provider regressions; I did not find a material merge blocker in the changed code.
Testing
Captain, I exercised the documented fake-Paseo primary-session handoff suite plus the adjacent lock, session-start, native-nudge, and watcher-lock regressions; all passed, evidence logs were saved under the requested directory, and the ignored transient
state/directory created during validation was cleaned up.Evidence: Dedicated primary-session handoff behavior transcript
Evidence: Dedicated primary-session handoff timing artifact
Evidence: Adjacent lock/startup/nudge/watch behavior transcript
Evidence: Adjacent regression timing artifact
Evidence: Reviewer-visible handoff behavior highlights
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-primary-session.sh:538- The takeover eligibility check is stale by the time the provider is archived: afterclassify_targetreturnsidle/paused-rate-limited, the code only performs an unvalidated inspect before writing the receipt and callingpaseo agent archive. If the visible session receives input, entersrunning, or gains a pending permission in that window, takeover can still archive a no-longer-safe primary. Re-run the full safety classification immediately before the lifecycle call, or use a provider-side conditional archive if Paseo supports one.bin/fm-primary-session.sh:129- Malformed quota window data is treated as available quota. In jq,(.percentRemaining | numbers)emits no value for missing or non-numeric fields, soany(...)can return false andquota_classificationreportsavailableinstead of failing unknown. Validate that the relevant fresh session/weekly windows have numericpercentRemainingbefore classifying, otherwise return failure so takeover refuses on unavailable quota evidence.🔧 Fix: Captain, fail-close takeover revalidation and quota
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bin/fm-session-start.shsed -n '1,220p' .agents/skills/primary-session-handoff/SKILL.mdsed -n '1,220p' docs/verification/primary-session-handoff.mdbin/fm-test-run.sh --json /var/folders/04/j5yqtsfs3l527xrkvtxzy60h0000gn/T/no-mistakes-evidence/01KYPQCHDQJ4HFRF0BS419ASV3/fm-primary-session.test.json tests/fm-primary-session.test.sh 2>&1 | tee /var/folders/04/j5yqtsfs3l527xrkvtxzy60h0000gn/T/no-mistakes-evidence/01KYPQCHDQJ4HFRF0BS419ASV3/fm-primary-session.test.logbin/fm-test-run.sh --json /var/folders/04/j5yqtsfs3l527xrkvtxzy60h0000gn/T/no-mistakes-evidence/01KYPQCHDQJ4HFRF0BS419ASV3/primary-session-adjacent.test.json tests/fm-claude-stop-autoarm.test.sh tests/fm-session-start.test.sh tests/fm-sessionstart-nudge.test.sh tests/fm-watcher-lock.test.sh 2>&1 | tee /var/folders/04/j5yqtsfs3l527xrkvtxzy60h0000gn/T/no-mistakes-evidence/01KYPQCHDQJ4HFRF0BS419ASV3/primary-session-adjacent.test.loggit status --short --ignoredafter cleanup✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.