mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-27 19:35:13 +01:00
Attaching an isolated worktree to a pre-existing branch (exact-branch mode, or a literal branchTemplate naming an existing branch) returned created: true because the worktree was new. Heartbeat persistence mapped that to metadata.createdByRuntime, and terminal cleanup then deleted the operator-owned branch at its verified tip via the detached-HEAD guarded delete, leaving its commits unreachable. Separate the two signals. RealizedExecutionWorkspace gains a required branchCreatedByRuntime flag that is true only when realization created the branch ref itself (worktree add -b). Worktree attaches to existing branches, reuse paths, and project_primary all report false; restoring a persisted workspace carries the recorded ownership forward instead of resetting it. Heartbeat now persists metadata.createdByRuntime from this ownership flag, so cleanup keeps deleting genuinely runtime-created branches (still guarded) while removing only the worktree for attached pre-existing branches. `created` keeps its worktree-freshness meaning for provision env and workspace-ready comments. Regression tests run terminal cleanup end-to-end for both attach paths and assert the branch ref survives at its exact tip; they fail against the previous commit. Co-authored-by: Paperclip <noreply@paperclip.ing> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>