paseo icon indicating copy to clipboard operation
paseo copied to clipboard

worktree: paseo metadata branch name goes stale after first-agent auto-rename

Open whme opened this issue 6 months ago • 7 comments

Summary

When paseo's first-agent auto-rename renames a worktree's branch (placeholder slug → user-supplied name), the worktree's paseo metadata is not updated. Anything that later resolves the worktree's branch via metadata sees the obsolete placeholder.

Repro

  1. Create a worktree without naming the branch (paseo assigns a placeholder slug, e.g. amazing-swan).
  2. Let the first-agent auto-rename fire, renaming the branch to e.g. feat/foo. The worktree directory still has the slug amazing-swan.
  3. Inspect $worktree/.git/paseo/worktree.json — there is no branchName, and consumers (e.g. the PASEO_BRANCH_NAME during teardown) that need the worktree's current branch fall back to the directory slug amazing-swan, which no longer corresponds to a real branch.

Expected

Paseo's worktree metadata should reflect paseo's own actions. After paseo renames the branch, the metadata should record the new name, and any code that needs the worktree's branch should prefer that recorded name.

Actual

attemptFirstAgentBranchAutoName performs the rename but does not write the new branch name back into the worktree metadata. resolveBranchNameForWorktreePath consults only git branch --show-current and falls back to basename(worktreePath) — so on detached HEAD it returns the stale slug.

Proposed fix

  1. Add an optional branchName field to the v2 worktree metadata schema and a writer that other writers preserve.
  2. Have attemptFirstAgentBranchAutoName write the post-rename branch name to that field (best-effort).
  3. Change resolveBranchNameForWorktreePath so metadata is the primary source of truth, git overrides only when it's on a non-detached branch that disagrees, and the directory slug is the final fallback.

Happy to open a PR if there is alignment on this approach. (I have a draft on my fork: https://github.com/whme/paseo/pull/1)

whme avatar May 06 '26 15:05 whme

thanks for the report @whme

i've been thinking about this and my conlusion is that im not even sure that we shoul be exposing PASEO_BRANCH_NAME

your fix works to ensure the branch name is fine at teardown in case of detached

but now the problem is that the $PASEO_BRANCH_NAME doesn't match for setup and teardown, to make this fully work we'd have to await the auto name branch but that'd be slow and unreliable since it can fail

to top it all off, the branch name is no guaranteed to be stable, during the lifetime of the worktree you can change it or do whatever you want, so it also seems like the wrong thing to use for resources

for example, if you're spinning resources like a database that needs tearing down, id use the workspace basename instead which is guaranteed to be stable from start to finish

what's your use case for the branch name at teardown?

boudra avatar May 07 '26 10:05 boudra

Thanks for looking into it and your feedback!

the branch name is no guaranteed to be stable, during the lifetime of the worktree you can change it or do whatever you want

I do agree.

what's your use case for the branch name at teardown?

Glad you asked and maybe the issue is my use case.

I like the workspaces a lot, I usually create one workspace for one task and once the code is committed and pushed, I archive the workspace again. And while it says archive, I really use it more like a delete. I have setup the teardown to cleanup the branch, which is where the $PASEO_BRANCH_NAME reflecting the actual branch name at teardown time comes in really handy. I am thinking "Paseo creates the branch for me when it creates the workspace, it should also delete the branch when I no longer need the workspace".

whme avatar May 07 '26 13:05 whme

Confirmed this is still reproducible on current main. After first-agent auto-name renames a placeholder branch to feat/foo, detaching HEAD and running teardown still supplies the placeholder directory slug through PASEO_BRANCH_NAME.

The auto-name path records the attempt but not the resulting branch in worktree metadata, and the detached-HEAD fallback still returns the worktree directory basename. The proposed fork PR remains open and unmerged.

Keeping this open as a p2 bug. The impact is limited to consumers that need the renamed branch during teardown after the worktree has entered detached HEAD; attached worktrees continue to resolve the current Git branch.

paseo-bot avatar Jul 30 '26 20:07 paseo-bot

@whme there have been no new reports on this in 60 days, so I'm checking whether it still affects you.

Does it still happen on v0.11.4, the current release?

A reply here sends it back to diagnosis. Without one in 14 days, the issue closes, and replying after that reopens it.

paseo-bot[bot] avatar Oct 18 '26 06:10 paseo-bot[bot]

Yes it is still an issue on v0.11.4.

whme avatar Oct 18 '26 18:10 whme

Thanks @whme. I've removed needs-more-info, so this goes back to diagnosis. Nothing else is needed from you, and updates go on this issue.

paseo-bot[bot] avatar Oct 18 '26 20:10 paseo-bot[bot]

Thanks for the report. I'm closing this because it has been quiet for a month. If this still happens on v0.16.2, please open a new issue.

paseo-bot[bot] avatar Nov 19 '26 07:11 paseo-bot[bot]