Skip to content

fix(miner): retain a crashed attempt's worktree for post-mortem - #6867

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-attempt-retain-worktree-on-throw-6759
Jul 17, 2026
Merged

fix(miner): retain a crashed attempt's worktree for post-mortem#6867
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
jeffrey701:fix-attempt-retain-worktree-on-throw-6759

Conversation

@jeffrey701

Copy link
Copy Markdown
Contributor

Closes #6759

Problem

attempt-cli.js only set worktreeResult.attemptOk = result.outcome === "submitted" after runAttemptPipeline returned normally. When it throws, execution jumps straight to the outer catch and that line never runs, leaving attemptOk undefined. The finally block then calls:

await cleanupWorktree(..., worktreeResult.attemptOk ?? true);

so the ?? true default deletes the worktree of a genuinely crashed attempt — precisely the one that most needs post-mortem inspection. shouldRetainWorktree(attemptOk) (packages/loopover-engine/src/miner/worktree-plan.ts) returns !attemptOk, and its header explicitly states a FAILED attempt's worktree is retained for inspection. The existing throw-path test exercised this route but only asserted the claim release, never what cleanupAttemptWorktree received.

Fix

  • Wrap the runAttemptPipeline call so an uncaught exception records attemptOk = false (retain) before rethrowing. The ?? true default is left intact for the earlier blocked paths (rejection / worktree-prep-failure / infeasible) it was actually written for — nothing ran in those worktrees to postmortem.
  • Correct the stale finally-block comment, which described only the "earlier blocked path" cases and never the exception case.

Tests

test/unit/miner-attempt-cli.test.ts adds a regression test asserting cleanupAttemptWorktree is called with attemptOk === false when runMinerAttempt throws. It fails before the fix (the call arrived with true).

Validation

  • npx vitest run test/unit/miner-attempt-cli.test.ts68 passed, 70 total. The 2 failures are pre-existing on Windows only and byte-identical to the pristine baseline (2 failed | 67 passed before this change, 2 failed | 68 passed after) — zero net-new failures, +1 new passing test.
  • npm run typecheckclean (0 errors)
  • Scope: 1 source file + 1 test file

@jeffrey701
jeffrey701 requested a review from JSONbored as a code owner July 17, 2026 09:37
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.65%. Comparing base (81a3a03) to head (bc08424).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6867   +/-   ##
=======================================
  Coverage   93.65%   93.65%           
=======================================
  Files         685      685           
  Lines       68247    68250    +3     
  Branches    18707    18707           
=======================================
+ Hits        63914    63917    +3     
  Misses       3348     3348           
  Partials      985      985           
Flag Coverage Δ
shard-1 43.22% <0.00%> (-0.46%) ⬇️
shard-2 36.93% <100.00%> (+0.25%) ⬆️
shard-3 32.59% <0.00%> (-0.12%) ⬇️
shard-4 34.36% <0.00%> (-0.40%) ⬇️
shard-5 31.48% <0.00%> (+0.32%) ⬆️
shard-6 45.98% <0.00%> (+0.27%) ⬆️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/attempt-cli.js 98.08% <100.00%> (+0.02%) ⬆️

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

loopover-orb Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-17 09:45:48 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR fixes a real bug where a crashed runMinerAttempt call left worktreeResult.attemptOk undefined, causing the finally block's `?? true` default to delete the worktree of a crashed attempt instead of retaining it for post-mortem. The fix correctly wraps the pipeline call in try/catch to set attemptOk = false before rethrowing, preserving the existing `?? true` default for the earlier blocked paths it was actually intended for. The regression test directly asserts cleanupAttemptWorktree is called with attemptOk === false on throw, closing the gap the description calls out in the prior throw-path test.

Nits — 4 non-blocking
  • The inline comment block in the catch (attempt-cli.js) is fairly verbose for a one-line fix; could be trimmed to a single sentence.
  • Consider also asserting the rethrown error propagates/exitCode reflects a crash distinctly from other failure paths, though exitCode 2 is already checked.
  • file:packages/loopover-miner/lib/attempt-cli.js — the fix and updated finally-comment are clear and consistent with shouldRetainWorktree's documented policy.
  • test/unit/miner-attempt-cli.test.ts — good regression test; could also add a case verifying `attemptOk` is not overwritten if the finally block runs after a successful catch-and-rethrow chain, though this is optional given current coverage.

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 #6759
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ❌ 8/20 High 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: 121 registered-repo PR(s), 59 merged, 30 issue(s).
Contributor context ✅ Confirmed Gittensor contributor jeffrey701; Gittensor profile; 121 PR(s), 30 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff wraps runAttemptPipeline in try/catch to explicitly set worktreeResult.attemptOk = false before rethrowing on an uncaught exception, preventing the `?? true` default from deleting a crashed attempt's worktree, and updates the stale finally-block comment to describe the exception case. It also adds a regression test asserting cleanupAttemptWorktree is called with attemptOk === false when r

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: TypeScript, Clojure, JavaScript, Rust
  • Official Gittensor activity: 121 PR(s), 30 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add a concise scope and risk note.
  • Then work through the remaining 1 step in the Signals table above.
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 8ef43a4 into JSONbored:main Jul 17, 2026
16 checks passed
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.

Worktree retention policy is bypassed when runMinerAttempt throws mid-execution

1 participant