Skip to content

Prevent checkout under an external index lock - #15641

Open
krlvi wants to merge 1 commit into
masterfrom
hermes/pc-337cd7b12782-index-lock-preflight
Open

Prevent checkout under an external index lock#15641
krlvi wants to merge 1 commit into
masterfrom
hermes/pc-337cd7b12782-index-lock-preflight

Conversation

@krlvi

@krlvi krlvi commented Aug 29, 2026

Copy link
Copy Markdown
Member

Context

Trigger: run safe checkout while the repository index is already locked by another process.

Symptom: checkout can change worktree files before returning the index-lock error, leaving a failed operation partially applied.

Change

Probe the exact worktree index lock before checkout starts. A lock held at the probe now fails before worktree, index, HEAD, or ref mutation; uncontended checkout behavior stays on the existing libgit2 path. This is a fail-fast preflight, not full checkout serialization: contention beginning after the probe remains outside this bounded change. Regression coverage includes repository-state preservation and linked-worktree index paths.

Related: #5390

Copilot AI lite review requested due to automatic review settings August 29, 2026 02:19
@github-actions github-actions Bot added the rust Pull requests that update Rust code label Aug 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-29T02:31:16.866188Z 569a487 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@krlvi krlvi added the bounded fix Autonomous fix with bounded scope and explicit validation label Aug 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an early “index lock” preflight to but_core::worktree::safe_checkout_from_head() so a checkout fails immediately if the worktree’s index is already externally locked, preventing libgit2 from partially mutating the worktree before reporting the error. It also adds regression tests covering repository-state preservation and correct index-path handling for linked worktrees.

Changes:

  • Add a preflight probe for the worktree’s index lock before invoking libgit2 checkout logic.
  • Add tests ensuring an external index lock prevents any checkout side effects (worktree/index/HEAD/ref) and that linked worktrees use their own index path.
  • Wire the new test module into the existing worktree test suite.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/but-core/src/worktree/checkout/function.rs Adds an early index-lock acquisition attempt to fail before libgit2 performs any worktree mutations.
crates/but-core/tests/core/worktree/mod.rs Registers the new checkout_index_lock test module.
crates/but-core/tests/core/worktree/checkout_index_lock.rs New regression tests for index-lock preflight behavior and linked-worktree index paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/but-core/src/worktree/checkout/function.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 569a4873d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/but-core/src/worktree/checkout/function.rs
Copilot AI review requested due to automatic review settings August 29, 2026 02:45
@krlvi
krlvi force-pushed the hermes/pc-337cd7b12782-index-lock-preflight branch from 569a487 to e35d420 Compare August 29, 2026 02:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bounded fix Autonomous fix with bounded scope and explicit validation rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants