feat(cli): lock hermes worktrees so concurrent processes can't clobber them - #48699
Merged
Conversation
…r them git worktree lock at creation and unlock before removal. A locked worktree refuses 'git worktree remove' (and prune), so a second hermes process or a stray cleanup can't silently delete an in-use isolated worktree. Fail-soft on both paths — a lock/unlock error never blocks the session or cleanup. Salvaged from #47029 (Issue #46303). Unlock moved to the actual-removal path so a preserved (unpushed-commits) worktree stays locked while in use.
Contributor
🔎 Lint report:
|
1 task
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.
Summary
Hermes-created git worktrees (
hermes -w) are now locked while in use, so a second hermes process or a straygit worktree remove/prunecan't silently delete an isolated worktree out from under a running session.Changes
cli.py_setup_worktree:git worktree lock --reason "hermes pid=<pid>"right after the worktree is provisioned.cli.py_cleanup_worktree:git worktree unlockon the actual-removal path (beforeremove --force), so a preserved worktree with unpushed commits stays locked while in use. Both lock and unlock are fail-soft — an error never blocks the session or cleanup.Validation
Real-repo E2E: a locked worktree refuses
git worktree remove --force(rc 128, "is locked"); unlock-then-remove succeeds and the worktree is gone.git worktree remove --forceProvenance
Salvaged from #47029 (Issue #46303), @JoaoMarcos44's authorship preserved. Only the worktree lock/unlock hardening is taken here — the rest of #47029 (system-prompt injection of concurrent-session notes, which breaks the byte-stable system-prompt invariant; a default flip of the Honcho
session_strategy; and a concurrency-warning path that is dead unlessmax_concurrent_sessionsis set) is intentionally left out.Infographic