Skip to content

feat(cli): lock hermes worktrees so concurrent processes can't clobber them - #48699

Merged
teknium1 merged 2 commits into
mainfrom
salvage/worktree-lock-47029
Jun 19, 2026
Merged

feat(cli): lock hermes worktrees so concurrent processes can't clobber them#48699
teknium1 merged 2 commits into
mainfrom
salvage/worktree-lock-47029

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Hermes-created git worktrees (hermes -w) are now locked while in use, so a second hermes process or a stray git worktree remove/prune can'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 unlock on the actual-removal path (before remove --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.

locked after unlock
git worktree remove --force rc 128 (blocked) rc 0 (removed)

Provenance

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 unless max_concurrent_sessions is set) is intentionally left out.

Infographic

worktree-lock

JoaoMarcos44 and others added 2 commits June 18, 2026 15:56
…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.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/worktree-lock-47029 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11033 on HEAD, 11033 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5781 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists labels Jun 18, 2026
@teknium1
teknium1 merged commit 8568988 into main Jun 19, 2026
35 checks passed
@teknium1
teknium1 deleted the salvage/worktree-lock-47029 branch June 19, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants