Skip to content

fix(miner): fail acquire() on an attempt_id/repo mismatch - #8964

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-8858-worktree-acquire-repo-mismatch
Jul 26, 2026
Merged

fix(miner): fail acquire() on an attempt_id/repo mismatch#8964
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-8858-worktree-acquire-repo-mismatch

Conversation

@jeffrey701

Copy link
Copy Markdown
Contributor

What

worktree-allocator.ts's acquire(attemptId, repoFullName) early-return
(existing?.status === "active") keyed only on attemptId — it never compared the existing
allocation's repo_full_name against the newly-requested repoFullName. So a second acquire
call for the same attemptId but a different repo silently got back the first repo's
allocation, with no error. Only the same-repo re-acquire case was tested.

Change

On that early-return path, throw a clear attempt_id_repo_mismatch error when
existing.repo_full_name !== normalizedRepo, instead of silently returning the mismatched
allocation. Same-repo re-acquire stays idempotent (returns the same allocation, unchanged).

Validation

  • New test in test/unit/miner-worktree-allocator.test.ts: re-acquiring the same active attempt
    for the same repo returns the same allocation, but for a different repo throws
    attempt_id_repo_mismatch.
  • npx vitest run test/unit/miner-worktree-allocator.test.ts → the new test passes; both sides of
    the new repo-match branch are covered (the same-repo side by existing idempotence tests). The two
    pre-existing failures in this file (resolves DB … env overrides, creates a permissioned SQLite store) are Windows-only baseline (Unix file-mode / path-separator assumptions) — they fail
    identically on a clean checkout and pass on Linux CI.

Closes #8858

@jeffrey701
jeffrey701 requested a review from JSONbored as a code owner July 26, 2026 14:27
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.61%. Comparing base (6aaea39) to head (f2923a5).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8964      +/-   ##
==========================================
+ Coverage   90.56%   90.61%   +0.05%     
==========================================
  Files          96       97       +1     
  Lines       22490    22613     +123     
  Branches     3884     3918      +34     
==========================================
+ Hits        20367    20490     +123     
  Misses       1945     1945              
  Partials      178      178              
Flag Coverage Δ
backend 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-miner/lib/worktree-allocator.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 14:43:29 UTC

2 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This fixes a real bug: `acquire()`'s early-return keyed only on `attempt_id`, so re-acquiring the same attempt with a different `repo_full_name` silently returned the first repo's stale allocation. The fix adds a repo comparison on the existing active row and throws `attempt_id_repo_mismatch` on divergence, while preserving idempotent same-repo re-acquire. The in-transaction raced re-check path a few lines below has the identical gap (it returns `rowToAllocation(raced)` without a repo check), but that's pre-existing and out of this diff's stated scope, worth flagging as a nit rather than a blocker.

Nits — 5 non-blocking
  • The in-transaction race-recheck branch (`if (raced?.status === "active") return rowToAllocation(raced)` in worktree-allocator.ts, just below the diff) has the same unguarded mismatch this PR fixes for the pre-transaction path — worth a follow-up so a same-attempt/different-repo race doesn't still silently hand back a stale allocation.
  • Throwing a plain `Error` with a string-prefixed code (`attempt_id_repo_mismatch: ...`) matches the file's existing convention (`invalid_attempt_id`, `worktree_capacity_exceeded`), so this is consistent, but consider whether callers parse the message vs. use `error.message.startsWith(...)`, since the mismatch message also embeds interpolated repo names that could shift matching if trimmed differently.
  • The new test only exercises the pre-transaction early-return path; it doesn't cover the in-transaction `raced` branch, so that latent gap remains untested.
  • Consider applying the same `repo_full_name` check to the `raced` branch (worktree-allocator.ts, the `BEGIN IMMEDIATE` block) for full parity, even if it's a narrower race window.
  • Reference the mismatch error code as a constant if it's likely to be pattern-matched by callers elsewhere in the codebase, to avoid drift between the thrown string and any consumer's check.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8858
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 80 registered-repo PR(s), 36 merged, 18 issue(s).
Contributor context ✅ Confirmed Gittensor contributor jeffrey701; Gittensor profile; 80 PR(s), 18 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds the exact repo_full_name check on the early-return path in acquire(), throwing an 'attempt_id_repo_mismatch' error when repos differ, matching the issue's requirement precisely.

Review context
  • Author: jeffrey701
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 80 PR(s), 18 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb 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.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 266b07d into JSONbored:main Jul 26, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(miner): worktree-allocator.acquire() silently returns the stale allocation on a repo-mismatched re-acquire

1 participant