Skip to content

fix(repo): refuse a push that moves a checked-out branch during a stopped merge, pick or rebase - #198

Merged
tonibergholm-codento merged 2 commits into
mainfrom
recv-guard
Oct 19, 2026
Merged

tonibergholm-codento merged 2 commits into
mainfrom
recv-guard

Conversation

@tonibergholm

@tonibergholm tonibergholm commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

Flagged at the P21 final review and still on the Deferred list: LocalTransport::update_ref moves a branch tip with only a CAS/fast-forward gate and no in-progress check on the RECEIVING side. A push into a repo with a stopped merge or cherry-pick moves its checked-out tip from underneath the operation, and the completing sc commit (built from the working tree and the now-moved tip) silently drops the pushed commits (the P19-I1 discard shape, reached by a remote writer). A stopped rebase has its own moved-tip backstop; merge and pick completion did not.

Change

update_ref (shared by sc push to a local path and the wire UpdateRef, hence sc serve) refuses for the receiving repo's checked-out branch while a merge, cherry-pick or rebase is in progress there (MergeInProgress/PickInProgress/RebaseInProgress), before any write and inside the repo lock. Branches that are not checked out are unaffected, and the push is accepted again once the op is over.

Verification

  • Two transport tests: a stopped merge and a stopped pick refuse the checked-out branch with no ref moved, accept another branch, and accept the push after merge --abort.
  • cargo fmt, cargo clippy --workspace --all-targets -D warnings, cargo test --workspace, and the push demos (remote, git remote, http, http auth, ssh, limits, partial clone, lazy fetch) pass.
  • ROADMAP entry marked fixed; CLAUDE.md notes the receiving-side refusal.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Local pushes are now refused when they would update the checked-out branch of a repository with a merge, cherry-pick, or rebase in progress. Pushes to other branches remain unaffected, and an update is accepted if the branch already points to the requested commit.
    • Pushes are allowed again after the in-progress operation ends.

…pped merge, pick or rebase

LocalTransport::update_ref (sc push to a local path, and the wire UpdateRef)
moved a branch with only a CAS/fast-forward gate. A push into a repo with a
stopped merge/pick moved the checked-out tip from underneath it, and the
completing commit then silently dropped the pushed work. It now refuses for
the receiving repo's checked-out branch while one of those ops is in progress;
other branches are unaffected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T11:05:56.242884Z 7944cdf New commits
🔒 Security Review ✅ Completed 2026-10-19T11:07:34.153274Z 7944cdf New commits
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2cfe05e1-e8e8-4f98-b96d-249cce433809
📥 Commits

Reviewing files that changed from the base of the PR and between fb6705c and 7944cdf.

📒 Files selected for processing: 3
  • CLAUDE.md
  • ROADMAP.md
  • crates/repo/src/transport.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📝 Walkthrough

LocalTransport::update_ref now refuses updates to the checked-out branch during a stopped merge, cherry-pick, or rebase. Updates to other branches remain allowed. Tests cover these cases and documentation describes the guard.

Changes: Receiving push guard

Layer / File(s) Summary
Guard checked-out branch updates
crates/repo/src/transport.rs, CLAUDE.md, ROADMAP.md
update_ref checks for a stopped operation before changing the checked-out branch. Tests cover merge and cherry-pick refusals, idempotent updates, unreadable HEAD, updates to another branch, and updates after the merge ends. Documentation clarifies the restriction and marks the roadmap item fixed.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7944c

The receiving-side guard covers wire pushes while preserving updates to other branches during a stopped rebase. No merge-blocking issue remains after normal checks.

Security architecture risk: ⚪ Minimal · up to 7944c

The change strengthens branch-integrity protection without adding a new entrypoint or granting additional write authority. Existing concurrency checks and harmless retry behavior remain intact. No material security risk introduced or worsened by this PR was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed control applies to branch-ref mutation in the receiving repository reached through LocalTransport, including wire UpdateRef. It narrows an existing caller-controlled write path; the inspected delta does not introduce a new endpoint or expand repository authority.

Security Findings and Attack Paths

  • inferred — The guard closes the preexisting route by which a receiving update could move the checked-out branch beneath an unfinished operation. A caller submitting UpdateRef can no longer use this implementation to perform that mutation while the operation marker remains present.

Trust Boundaries and Controls

  • observed — Caller-supplied branch names pass existing validation during the locked tip read, before the new branch-identity comparison. The validator rejects separators, dot-prefixed names, whitespace, and control characters. The existing CAS check and atomic branch write remain downstream of the new refusal.

Resilience and Maintainability Implications

  • inferred — Push transfers objects before updating the ref, so a refusal may leave transferred objects without moving the branch. This preserves branch integrity on partial failure and permits a later retry. Existing completion-time ref-write and cleanup failure windows predate this PR; a remaining operation marker keeps the new receiving guard closed.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and specifically summarizes the main change: refusing pushes that move a checked-out branch during a stopped merge, cherry-pick, or rebase.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@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: 76a3a66270

ℹ️ 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/repo/src/transport.rs Resolved
Comment thread crates/repo/src/transport.rs Resolved
… HEAD during a stopped op

Codex: a retry of a push that already landed (a lost response) must still
succeed regardless of a stopped op, so the guard now runs after the
already-at-that-id check; and HEAD is read only when an op is stopped, with a
read failure then propagating instead of silently skipping the guard.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tonibergholm-codento
tonibergholm-codento merged commit 6d6a7f3 into main Oct 19, 2026
8 checks passed
@tonibergholm
tonibergholm deleted the recv-guard branch October 19, 2026 11:14
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.

2 participants