Skip to content

Preserve Claude sessions and composer text across subscription moves - #19

Merged
pearson-tfl merged 2 commits into
mainfrom
fm/ahracctmove
Nov 6, 2026
Merged

pearson-tfl merged 2 commits into
mainfrom
fm/ahracctmove

Conversation

@pearson-tfl

@pearson-tfl pearson-tfl commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Remove Firstmate's terminal fingerprint-approval mechanism for config/account-rules. Valid edits apply immediately; malformed/unreadable rules still refuse. Old approval artifacts are ignored, and the obsolete approval helper/test fixture is removed. This security-relevant removal was explicitly authorized for this task; this PR does not authorize its own merge.
  • Run the actual Claude process, not just its profile probe, through cswap run N --share-history -- for rules-selected workers, secondmates, and resumes. Credential bootstrap/refresh ownership stays with cswap.
  • Add fm-control.sh <id> account <N>: save exact composer bytes through an editor bridge, cleanly exit, resume the identical session ID on the requested subscription, verify the native process/session and authenticated email/organization, restore and read back the draft without submitting it, and persist account_override=cswap:N for subsequent launches.
  • Retain and name private composer backups on failures. Account moves inject no startup prompt. Ordinary Ctrl-G still opens the original editor.

No Agent-Harness-Reconfig changes or sibling PR are needed.

Old-harness behavior carried forward

The reconstruction was completed before implementation using archived sessions 8329adce-b91b-4a95-be1e-965c240e631a (launch account selection), ca5eb122-3308-43b5-b2f7-93f7def5a5a0 (account swaps), and 8e106edc-46f5-4bd6-bb4e-91f3fd0c5a0e (stale credential attribution), plus source history:

  • AHR 3f8e890104c3603571ef2fa907cc80cf6bc7e313: actual cswap --share-history launch, restored here rather than probing cswap then bypassing it at launch.
  • AHR e6c996935f8e09dd09fbb43d8da40ca44b688436 and f731cdb14e06fd7eb474bade12f324df4e475682: exact native session identity, idle checking, environment scrubbing, and resume rather than a fresh conversation. This implementation additionally preserves the original composer and uses verified clean exit rather than killing the pane.
  • AHR 9d93b155ee850a1a63d2f184763a65c4c71a6a77's historical incoming-config guard bypass is not copied. Current cswap estate has the later same-default-account protection; bypassing it can seed another copy of a refresh lineage. Firstmate now leaves that decision to cswap.
  • Current estate cswap source 58208cf685979e5a0d678afc0ca31608ee372550 documents that the upstream fix(backends): resolve physical path in orca repo_ensure for symlinked projects kunchenguid/firstmate#279/feat(harness): add cursor and hermes verified adapters kunchenguid/firstmate#280 Keychain ACL theory was refuted and the ACL pin was not adopted. No Keychain ACL writes, custom token refresher, logout, or forced login are introduced here.

Missing shared history and the actual-launch bypass were proven Firstmate divergences. The precise historical live-seat login failure was not conclusively reproduced. A stale stored credential is not proof of an expired account. The live diagnostic confirmed that removing USER/LOGNAME can falsely report account 2 signed out; the new identity check retains them. An existing slot-4 profile also returned a different account identity in a read-only diagnostic; no slot-4 credential reset or move was attempted, and that discrepancy is not claimed repaired. The move refuses success if authenticated identity differs from the requested slot.

Compatibility and safety boundaries

  • Every new canonical Claude launch, fresh or resumed, installs the editor bridge inline using an absolute executable. This avoids dependence on the terminal server inheriting editor variables and avoids Claude's multiword editor-command parsing problem.
  • Legacy sessions without the bridge: empty-composer moves are supported; a session holding text refuses untouched with: move waits for an empty composer or the lane's next relaunch; existing text is untouched. No screen scraping is used for capture.
  • Claude ignores Ctrl-G on an empty composer. Restoration inserts only an unsubmitted nonce and replaces it only if the editor file contains exactly that nonce. Concurrent text causes refusal instead of being overwritten.
  • cswap may defer shared-history migration when another live session uses an old nonshared profile. A move requires its transcript to be shared before clean exit and otherwise leaves the session running; it does not forcibly migrate another live profile.
  • The live proof covers tmux. Herdr/Rex editor-key delivery has portable adapter coverage, not a new live account-move certification.

Live Mac proof

Repository pearson-tfl/firstmate, branch fm/ahracctmove, commit 49daa397386a649ba5a3c82ae62e5010b7e03c2b; Claude Code 2.1.319, cswap 0.27.0b1+estate.1, 2026-11-06.

Only a throwaway scratch lane was moved. Affected credential material was privately backed up before cswap activity; no real seat was moved, logged out, or re-authenticated.

  1. Established session fbafab01-a822-4495-9571-a4e0c6602876 on account 3 with one test prompt.
  2. Put unsubmitted move proof λ, a newline, and second line with spaces plus two trailing spaces in its composer.
  3. Exercised fm-control.sh proof account 3, then fm-control.sh proof account 2 on the committed tree; both returned success.
  4. Read the native record: the same session ID, a matching live process generation, idle status, and durable account=cswap:2 / account_override=cswap:2.
  5. Compared authenticated email and organization with cswap slot 2, and used the actual external-editor file to verify exact composer bytes, SHA-256 48b9af9ccbff79631bb7bd9ccdce1688ff91c7c97af83a9c4d7d254c1cb535a0.
  6. Verified the transcript still had one user message: neither an automatic startup prompt nor the saved draft was submitted.

An earlier replacement-launch refusal also verified that the original conversation remained resumable and the saved draft survived byte-for-byte. Private native records, logs, credential backups, and reconstruction archives remain with the task rather than in this public PR.

Validation

All passed against the tree committed as 49daa397386a649ba5a3c82ae62e5010b7e03c2b:

  • bash tests/fm-claude-draft.test.sh
  • bash tests/fm-claude-session.test.sh
  • bash tests/fm-account-rules.test.sh
  • bash tests/fm-worker-account.test.sh
  • bash tests/fm-control.test.sh
  • bash tests/fm-control-relaunch.test.sh
  • bash tests/fm-backend-rex.test.sh
  • bash tests/fm-backend-herdr.test.sh (synthetic adapter only; no Herdr lifecycle actions)
  • bash bin/fm-lint.sh with the pinned actionlint installed privately
  • bash bin/fm-doc-audience-check.sh --root <repository>
  • New-test ShellCheck, Python AST parsing, and git diff --check

Coverage includes executed launch/editor commands, shared-history flag enforcement, approval-free rules changes, malformed rules, native session/process generation and locale, exact whitespace/Unicode transfer, original-editor delegation, placeholder races, legacy pending-text refusal, empty drafts, durable account metadata, and retained backups on authenticated-identity mismatch.

Review

One implementation self-review round; no independent reviewer or no-mistakes pipeline, following this task's direct-PR contract.

Axis Verdict Reviewer model
Standards PASS: scoped changes, behavioral tests at public commands, shared owners retained, documentation audiences checked openai/gpt-6.1-sol (implementation self-review)
Spec PASS for requested implementation and scratch proof, with the explicit compatibility/diagnostic limits above openai/gpt-6.1-sol (implementation self-review)

Note

Medium Risk
Touches worker account selection, spawn launch lines, and a new control-plane verb that stops/resumes Claude and manipulates credentials paths; behavior is heavily tested but any edge-case mismatch in cswap/auth/editor bridging could strand a lane or mis-route accounts.

Overview
Moves Claude lanes between cswap subscriptions without losing the session or composer text. Adds fm-control.sh <task> account <n>, with preflight checks, byte-exact draft save/restore through a new external-editor bridge (fm-claude-draft.py), native session/process verification (fm-claude-session.py), authenticated identity matching against cswap list, and durable account_override=cswap:<n> metadata carried into spawn.

Runs real Claude launches via cswap run <n> --share-history -- (not just probes) and extends metadata/backends to support editor-bridge env wiring, C-g delivery on tmux/herdr/rex, and account-override plumbing (FM_CONTROL_ACCOUNT, spawn meta fields).

Simplifies account rules: removes captain fingerprint approval (account-rules.approved), makes fm-account-rules.sh status-only, and updates docs/tests/fixtures accordingly while still refusing malformed rules.

Reviewed by Cursor Bugbot for commit 604d40d. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread bin/fm-claude-draft.py
raise ValueError(body.get("error", "draft operation refused"))
return 0
time.sleep(0.1)
raise ValueError("Claude did not acknowledge its external editor; saved draft retained")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed editor request blocks retries

Medium Severity

prepare leaves request.json in place when Claude never opens the editor, then refuses any later prepare until that file is removed. A timed-out account take or restore therefore makes an otherwise retryable live session fail on the next move with a different error.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 49daa397386a649ba5a3c82ae62e5010b7e03c2b. Configure here.

@pearson-tfl

Copy link
Copy Markdown
Owner Author

Rebased onto current main (6232ec6fa1f46241b403727fc9520890adcd956c, merged PR #18) and force-pushed with an explicit lease protecting the previous PR head.

New HEAD: 604d40d.
GitHub read-back reports MERGEABLE, mergeStateStatus: CLEAN, and isDraft: false.
No merge was attempted; merge remains with Firstmate after green checks.

The single production conflict is resolved by retaining both __CLAUDEBIN__ (actual cswap launch) and --name __CLAUDENAME__ in the shared Claude template.
PR #18's pane-id-scoped title protection and quoted name replacement are unchanged.
git range-diff confirms this is the only production difference from the original implementation patch.
A small follow-up updates the dispatch suite's exact launch expectations to include the inline editor environment while retaining the lane-name assertions.

Validation against repository pearson-tfl/firstmate, branch fm/ahracctmove, final tree 604d40dfa6bda7e16c056a0a4dbc68ae5f6a9e5c:

  • PASS: all 13 affected suites: fm-spawn-dispatch-profile, fm-spawn-loadout, fm-secondmate-harness, fm-backend-orca, fm-test-fixtures, fm-claude-draft, fm-claude-session, fm-account-rules, fm-worker-account, fm-control, fm-control-relaunch, fm-backend-rex, and fm-backend-herdr.
  • The full dispatch suite includes the fresh/resume Claude/Pi worker/secondmate matrix for exact names, session identities, and pane-scoped title commands, plus the refusal cases for pane identity/title failures.
  • PASS: pinned lint, documentation-audience check, and whitespace check.
  • Existing capability skips: fish execution is unavailable (its static check ran), and one Cursor secondmate launch case could not resolve that executable.
  • No new live seat/account move or Herdr lifecycle action was performed for this rebase; the original scratch proof remains explicitly tied to its original implementation commit in the PR body.

One additional integration self-review round (openai/gpt-6.1-sol): Standards PASS, Spec PASS for preserving both PRs' launch contracts.
The final local copy is clean.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 604d40d. Configure here.

Comment thread bin/fm-control.sh
local status=$?
if [ -n "${ACCOUNT_BACKUP:-}" ] && [ -f "$ACCOUNT_BACKUP" ]; then
echo "composer backup retained: $ACCOUNT_BACKUP" >&2
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Success reports composer backup retained

Low Severity

control_cleanup prints composer backup retained whenever ACCOUNT_BACKUP exists, including after a successful account-moved. Preflight always creates that file, and the trap ignores the saved exit status, so a completed move still emits the failure-oriented retention line on stderr.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 604d40d. Configure here.

@pearson-tfl
pearson-tfl merged commit 2e77192 into main Nov 6, 2026
1 check passed
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