v0.42.0 — Session clean-up fix (session worktrees and run state survive clean-up)
Consumers act once.
- Pre-set
ticket_lint,worktree_sweepanddocker_lintif you want other than the defaults. - Run
claude plugin update marvin, then/marvin:upgrade-agent-osin one session. - Restart the other open sessions.
- Run the upgrade again once the sessions it deferred have finished (
upgrades/v0.42.0.md).
Why. Two architects lost live state. The v0.37 sweep treated every worktree under .claude/worktrees/ as disposable. A desktop session that had made no commit of its own and had been quiet for 15 minutes passed every guard, and another session's sweep removed it. The orchestrator's git-ignored ledger, briefs and run reports lived inside that worktree and went with it (CAL-184; Erik's questions).
Host facts (verified on CLI 2.1.289 and the desktop app).
- SessionEnd fires with reason
otheron the app's 15-minute idle pause as well as on archive. A hook cannot tell the two apart, so the kit uses no session lock. /clearchangessession_id; resume keeps it.- The app's archive pools a worktree and keeps its ignored files.
- The app's built-in write guard blocks Write and Edit into the main checkout from worktree sessions and their sub-agents, but not Bash.
- SubagentStop fires before Claude Code removes a clean agent worktree. Its
cwdis.claude/worktrees/agent-<agent_id>.
What changed.
- Sweep scope (AOS-223).
- A
marvin-ownedmarker is written at SubagentStop for exactly the agent's own isolated worktree. A worktree made by hand is marked with/marvin:clean-worktrees --mark, which refuses one older than 60 minutes. - The sweep considers only marked worktrees. Everything else is the app's.
- G8 keeps a worktree whose ignored
.env*differs from, or is missing in, the main checkout. It does not look inside wholly ignored folders. - G9 keeps a worktree whose carried run file is not identical in the project.
--at-riskreports both, for every worktree.
- A
Run state (AOS-224). Writers write in their own checkout. Hooks carry the files to
<project>/.marvin/runs/<UTC>-<session_id>/<KEY|adhoc>/, which is the only copy readers use:- SessionStart creates the folder, the
.gitignoreand seeds the local copies. - PostToolUse copies the orchestrator's writes; a ledger only when it extends the project copy.
- SubagentStop copies brief-named reports, with clash sidecars.
- Stop catches up a Bash-written ledger or build brief.
Ledgers chain across sessions (
chain:first line). The prune follows the new layout. The key rule admits single-letter prefixes and bare GitHub issue numbers.- SessionStart creates the folder, the
- Settings (AOS-225, AOS-228, AOS-230).
worktree_sweep: on | check | off; absent = check.- An absent
ticket_lintmeans advise. docker_lint: advise | off.- A missing mode key never enforces, and hooks never gate on the kit version.
- Recovery (AOS-226).
session-recovery.md, with the recreate and prune recipe inworktrees.mdWhere. - Windows (AOS-227).
mh_pathdecodes and normalises hook paths. There is awindows-latestCI job, non-blocking until its first green run, plus LF.gitattributesand a README section. - Update gate (AOS-229). U3 needs five bold points and U4 a heading after the last status line, in any language. English stays the documented default.
- Precedence (AOS-231). Only selective staging and the tagging authority stay gated. The branch model, merge style and push cadence are project-refinable.
- Upgrade readiness (AOS-237). Step 6b runs on every upgrade. It probes first, and only when there is run state to move does it ask which sessions are open, defer them, run
marvin-runs-migrate.sh, report at-risk files and both sweeps'--checkoutput, and ask for a restart.
Acceptance.
- Gates:
- all 17 test suites green;
validate-kit22/22, with new checksruns-layoutandrun-patterns;- full migration mutation sweep 119/119 caught.
- Rule-5 scratch-install walk-throughs passed: install plus run state, recovery, and upgrade readiness. The defects they found are fixed.
- The branch had per-task reviews, a whole-branch review and a merge review against v0.41.0.
This note's scope: was derived over v0.41.0..HEAD, non-merge commits only; the container epic AOS-222 is excluded.
Upgrade
Consumer-facing: the automatic worktree sweep now removes only worktrees Marvin marked as its own, and run state (ledger, briefs, run reports) lives in the project's .marvin/runs/<session>/<KEY>/, carried there by hooks from any worktree. Rules: .marvin/agents/worktrees.md and .marvin/agents/briefing.md item 11.
- Before updating the plugin, decide enforcement in
.marvin/PROJECT-INFO.mdfrontmatter. An absent key never enforces:ticket_lint→ advise,worktree_sweep→ check (report only),docker_lint→ advise. The upgrade writesticket_lint: block,worktree_sweep: onanddocker_lint: adviseonly where a key is missing, directly afterticket_lint. - Update with the procedure the SessionStart notice prints. Then run
/marvin:upgrade-agent-osin ONE session. It refreshes the cascade (newsession-recovery.md;briefing.md,worktrees.md,tidying.md,git-strategy.md,ticket-filing.md,escalation-ladder.md,validation-agent.md,session-budget.md, the kit core). Its new step 6b moves existing run state into the per-session layout withmarvin-runs-migrate.sh. It asks which sessions are still open mid-task and defers those. - Restart every other open session, because sessions started earlier run the old, unscoped sweep until restarted.
/clearor restart the upgrading session before its next task. - Once the deferred sessions have finished or been cleared, run
/marvin:upgrade-agent-osagain. It moves the run state it deferred. - Agent worktrees made before this release are never swept by the kit; remove them by hand or leave them. Desktop session worktrees are left to the app's own clean-up.
Changes
Added
worktree_sweep: on | check | offinPROJECT-INFO(absent = check, report only); the upgrade writesonwhen missing.docker_lint: advise | offinPROJECT-INFO(absent = advise).- Run-state hooks carry the ledger, build briefs and run reports to the project's
.marvin/runs/<UTC>-<session_id>/<KEY|adhoc>/from any worktree (SessionStart, PostToolUse, SubagentStop, and a Stop catch-up for Bash-written ledgers); a clash keeps both copies and saves a.clash-*sidecar. /marvin:clean-worktrees --mark <path>and the sweep's report-only--at-riskmode..marvin/agents/session-recovery.md: the procedure when a session's worktree vanishes mid-task.- Upgrade step 6b (session readiness) and
scripts/marvin-runs-migrate.sh: run state moved into the per-session layout, open sessions deferred, at-risk files and both sweeps'--checklines reported. - A Windows CI job (Git Bash), a README Windows section and LF
.gitattributes; the job is non-blocking until its first green run.
Changed
- The worktree sweep removes only worktrees Marvin marked as its own (agent worktrees at stop, hand-made ones via
--mark); session and older worktrees are never touched. G8/G9 keep a worktree whose ignored.env*or carried run file is not safely in the main checkout. - Ledgers chain across sessions (the newest earlier ledger for a key is authoritative), and the milestone prune follows the per-session layout.
- An absent
ticket_lintnow means advise; an unknown explicit value still blocks. - The update gate checks the structure of callouts and tails, not their English labels, so a project may write them in its own language.
- The precedence clause gates only selective staging and the tagging authority; the branch model, merge style and push cadence are project-refinable.
- Hook stdin paths are decoded and compared in one form (
mh_path), so WindowsC:\paths work. - The task key rule admits single-letter prefixes and bare GitHub issue numbers.
- Codex: the forwarder's prompt file is
<base>.prompt.txt, and its DATA files are passed as absolute paths under the orchestrator's checkout.
Action needed
- Pre-set
ticket_lint,worktree_sweepanddocker_lintbefore updating the plugin if you want other than the defaults. Restart other open sessions after/marvin:upgrade-agent-os, and run the upgrade again once deferred sessions have finished.