Skip to content

fix(gitvcs): answer RecoveryHeadContained with one rev-list walk - #165

Closed
bferanmi806-sketch wants to merge 1 commit into
kunchenguid:mainfrom
bferanmi806-sketch:fix/163-recovery-head-contained
Closed

bferanmi806-sketch wants to merge 1 commit into
kunchenguid:mainfrom
bferanmi806-sketch:fix/163-recovery-head-contained

Conversation

@bferanmi806-sketch

@bferanmi806-sketch bferanmi806-sketch commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #163. DRAFT for review; please do not merge yet (see Unresolved).

Root cause

Since 3.1.0 (#159), recoverQuarantinedEntries runs under the pool state lock before every pool command. For each recovered slot it calls RecoveryHeadContained (internal/vcs/gitvcs/recovery.go), which spawned one git merge-base --is-ancestor HEAD process per ref under refs/remotes, stopping at the first containing ref. With thousands of remote-tracking refs and a HEAD contained nowhere (or late in sort order), every status/get/return blocked for minutes to hours while holding the lock.

Design rationale

One git rev-list -n 1 HEAD --not --remotes [] answers the identical ancestry question with a single commit walk: rev-list prints commits reachable from HEAD but not from any exclusion, and because containment is ancestor-closed (a ref containing HEAD contains all of HEAD's ancestors), empty output is exactly HEAD-is-contained. Kept deliberately narrow per the issue's preferred option:

  • Same candidate set: --remotes covers refs/remotes/*; refs/heads/ and refs/remotes/origin/ are passed only after the existing show-ref --verify check.
  • Same failure contract: any Git failure (bad HEAD, unreadable repo, unresolvable exclusion) fails closed to false.
  • No locking changes; quarantine safety (commit ancestry, not squash equivalence) is untouched.

Tests run

  • New internal/vcs/gitvcs/recovery_test.go: contained by remote ref; contained as ancestor (not just tip) of remote tip; contained only by local base branch; no remote refs (with/without base); HEAD contained nowhere; unborn HEAD; non-repo dir; missing dir; missing base. Each case asserts both the new implementation and a reference copy of the old per-ref loop, so semantic equivalence is checked differentially, not just by expected values.
  • go test ./internal/vcs/... : pass (gitvcs incl. new tests, vcs, jjvcs).
  • Recovery-related pool tests (TestRecovered*, TestRecovery*, TestDamagedRecovered*, TestList_Recovers*, TestReleaseOfRecovered*): pass.
  • go build ./..., go vet, gofmt (LF semantics): clean.
  • Pre-existing environment failures, verified identical on clean main c099281 via stash and NOT caused by this change: root TestNoMistakesGateDecisions fails; full ./internal/pool and ./cmd suites hang past 200s on this Windows box (symlink privilege limits + slow git spawn; the implicated tests pass in isolation).

Limitations / unresolved

  • No-mistakes gate: this PR was opened by hand via gh because no-mistakes is not installed in this environment, so the 'PR must be raised via no-mistakes' check will stay red until the branch is pushed through the gate. Happy to re-push through no-mistakes if given access, or maintainer can drive it.
  • One theoretical divergence analyzed and judged unreachable: if a verified base ref pointed to a non-commit object, the old loop skipped past it while rev-list fails the whole check (fail-closed false). Branch refs always resolve to commits, so this cannot occur via refs/heads/* or refs/remotes/origin/*; flagging in case you want a belt-and-braces ^{commit} peel.
  • Did not implement the issue's optional second change (run recovery outside the lock / cache per HEAD); the single-walk fix restores sub-second checks and keeps the diff minimal.

RecoveryHeadContained ran git merge-base --is-ancestor once per remote ref while pool recovery holds the state lock, blocking every pool command for minutes to hours on repos with thousands of remote-tracking refs.

One rev-list walk answers the identical ancestry question: rev-list prints commits reachable from HEAD but not from any exclusion (--remotes plus the show-ref-verified base refs); empty output means HEAD is contained. All Git failures still fail closed to false, and no locking changes.

Refs kunchenguid#163.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Reviewed tip 68809c3 vs main c099281. Same intended restore for #163 (one rev-list walk instead of per-ref merge-base). Diff looks sound and CI/Nix/Windows are green, but this PR is not mergeable yet:

  1. Marked draft (body: please do not merge yet).
  2. PR must be raised via no-mistakes is red (hand-opened; no matching Pipeline attestation). I will not forge a marker.

VISION.md per-rule (inspected tip recovery.go / recovery_test.go vs main + issue #163):

  • Isolation and reuse — aligns (same containment bar; fail-closed).
  • Safe lifecycle operations — aligns (same ancestry question before auto-free).
  • Ownership and interface — aligns (restores usable pool-command latency under the state lock).
  • Scope and evaluation — aligns (focused gitvcs fix).

contract-class: restore — same class as #164.

Preferring sibling #164 (@nikolauska): ready (not draft), no-mistakes green, Greptile 5/5, design.md + process-count regression test, live 5001-ref evidence. When #164 merges we will close this leftover with thanks. If you want this tip to compete, mark ready-for-review and re-raise via no-mistakes so attestation matches the head — waiting on you for those, not a captain hold. No security risk on the diff.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Optimizes a Git ancestry check in recovery logic.

The PR appears safe to merge; adding multi-ref regression coverage is a non-blocking improvement.

Reviews (1) · Last reviewed commit: "fix(gitvcs): answer RecoveryHeadContaine..."

repoDir := setupContainmentRepo(t)
mustGit(t, repoDir, "reset", "--hard", "HEAD~1")

assertContainment(t, repoDir, "", true)

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 Multiple remote refs remain untested

The remote-containment fixture creates only origin/main. As a result, these tests never check whether the new walk finds a containing ref among several remote-tracking refs, or exercise the many-ref case that caused the lock stall. A multi-ref regression case would guard the behavior this change is meant to preserve.

Knowledge Base Used: Git workspace backend

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing as leftover. Sibling #164 (same #163 restore — single rev-list walk for RecoveryHeadContained) just landed; thank you @bferanmi806-sketch for the parallel work and solid differential tests. Tip looked sound (CI/Nix/Windows green; Greptile 4/5) but stayed blocked on no-mistakes attestation after the hand open. Preferring the ready PR over a duplicate. Reopen if something #164 missed.

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.

Since 3.1.0, every pool command can take minutes to hours: RecoveryHeadContained runs one git merge-base per remote ref under the state lock

2 participants