Skip to content

fix: keep failed checkouts accurate and speed up branch switches - #40

Merged
Blankeos merged 2 commits into
mainfrom
fix/failed-checkout-branch-state
Oct 6, 2026
Merged

Blankeos merged 2 commits into
mainfrom
fix/failed-checkout-branch-state

Conversation

@Blankeos

@Blankeos Blankeos commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Stop optimistically changing HEAD before checkout succeeds, so rejected checkouts keep the actual branch visible after dismissing the error.
  • Make successful switches fast without speculation: read the confirmed HEAD hash/ref on the checkout worker and apply it before the next paint, without waiting for a full model reload.
  • Start post-checkout refresh immediately instead of waiting through an idle 50ms/200ms input poll. Pending refreshes keep the input loop on its 16ms async cadence.
  • Discard pre-checkout model/files-refresh results so stale data cannot overwrite confirmed HEAD. A failed metadata read falls back to the immediate background refresh without falsely reporting checkout failure.
  • Preserve the busy-operation guard and normal push/pull/fetch refresh behavior.

Measured latency

Headless event-loop benchmark on a local two-branch fixture, 10 successful switches per mode; measures request to both displayed branch marker and HEAD identity updating (not total full-panel refresh or terminal rendering):

Auto-refresh Before After
Enabled 110.6ms median 36.8ms median
Disabled 258.4ms median 35.6ms median

Timing is machine/repository dependent. Git's checkout command and hooks are unchanged; the improvement removes application-side waiting after checkout.

Run the manual benchmark with cargo test checkout_visibility_latency -- --ignored --nocapture.

Regression coverage

  • Rejected checkout due to conflicting local changes, error dismissal, retry, and preservation of edits via Space, previous branch (-), and ref picker (c).
  • Confirmed HEAD updates before the full refresh for branch and detached tag checkouts.
  • Stale in-flight refresh invalidation, metadata-read fallback, missing-ref branch creation, busy-operation handling, and normal remote-operation behavior.
  • Nested branch names, annotated tags, and unborn HEAD metadata.

Validation

  • cargo fmt --check
  • cargo test — 295 passed, 1 manual benchmark ignored
  • Manual checkout visibility benchmark — passed
  • cargo clippy --all-targets — completed with warnings

Implemented in a separate worktree branched from origin/main; no edits made to the original worktree.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T17:25:20.138822Z 66fc823 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.

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

Copy link
Copy Markdown

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: 66fc823b16

ℹ️ 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 on lines +208 to +209
// Keep HEAD sourced from Git: a rejected checkout must not change the
// displayed branch. Successful completion triggers the normal model refresh.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refresh HEAD when checkout reports a post-hook error

When a repository has a post-checkout hook that exits nonzero, Git has already switched branches but propagates the hook's exit status; the official documentation confirms that the hook cannot affect the checkout outcome and only changes the command's exit status (Git githooks documentation). Here the closure consequently returns Err, while receive_remote_op_results does not request a refresh on errors; after removing the optimistic updates, the model therefore continues showing the old branch and hash even though the real HEAD moved. Refresh the model—or explicitly re-read HEAD—after a checkout error before deciding which branch to display.

Useful? React with 👍 / 👎.

@Blankeos Blankeos changed the title fix: preserve displayed HEAD when branch checkout fails fix: keep failed checkouts accurate and speed up branch switches Oct 6, 2026
@Blankeos
Blankeos merged commit 60cf46c into main Oct 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant