Skip to content

fix(miner): make governor-run-halt's ledger recording a genuine transition detector - #9367

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
galuis116:fix/governor-run-halt-transition-detector-9326
Jul 27, 2026
Merged

fix(miner): make governor-run-halt's ledger recording a genuine transition detector#9367
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
galuis116:fix/governor-run-halt-transition-detector-9326

Conversation

@galuis116

Copy link
Copy Markdown
Contributor

Summary

  • evaluateRunLoopBoundaryGate in packages/loopover-miner/lib/governor-run-halt.ts decided whether to append a governor-ledger row using newlyHalted || (!wasHalted && !verdict.shouldHalt). Tracing all four (wasHalted, shouldHalt) combinations: the steady "never halted, still not halted" case appended a row on every single iteration of a healthy run (pure ledger noise, no transition), while the resume transition (wasHalted=true, shouldHalt=false) — symmetric with the halt-trip case the old condition did correctly capture — was never recorded at all, leaving no ledger trace when a run recovered from a halted state.
  • Replaced the condition with wasHalted !== verdict.shouldHalt: a genuine transition detector, true exactly on the halt-trip and resume cases, false on both steady states.
  • Does not touch evaluateRunLoopHalt's own halt/no-halt determination logic, newlyHalted, the releasedItem/markFailed logic, or buildRunLoopHaltGovernorLedgerEvent's signature/contents — only the recorded condition.

Scope

Validation

  • git diff --check
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries
  • npm run actionlint
  • npm --workspace @loopover/miner run build (typecheck + check-syntax.mjs)
  • A scoped tsc --noEmit (root tsconfig.json's full flag set) against both changed files — clean
  • npx vitest run test/unit/miner-governor-run-halt.test.ts test/unit/miner-loop-cli.test.ts — 53/53 passing. Covers: the steady never-halted case appends nothing (asserted directly against a spy, not just the returned field); the resume transition now records (verified by forcing the collaborator's verdict for one call, since evaluateRunLoopHalt's own real implementation latches shouldHalt:true unconditionally once runHalted:true is passed in — a genuine resume only happens once an operator externally clears that latch outside this call, so this isolates evaluateRunLoopBoundaryGate's own transition-detection logic from that collaborator's current coupling); the existing halt-trip and still-halted-latched cases continue passing unmodified; loop-cli.ts (the one real caller) still passes its full 46-test suite unmodified.
  • Scoped coverage on packages/loopover-miner/lib/governor-run-halt.ts — 100% statements/branches/functions/lines

If any required check was skipped, explain why:

  • The whole-repo npm run typecheck/npm run test:coverage (unsharded) reliably OOM in this sandbox regardless of diff size — a known sandbox resource constraint, not a signal about this change. packages/loopover-miner/** is not included in vitest.config.ts's coverage.include (confirmed empirically), so it is not Codecov-gated; the gate here is npm run test:ci staying green with real branch coverage, which the checks above satisfy directly.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

UI Evidence

This is a backend-only fix (packages/loopover-miner/lib/governor-run-halt.ts, a ledger-recording condition) with no rendered UI delta — before and after are the same production capture at each required viewport. apps/loopover-ui is dark-mode-only, so only the Dark row per viewport applies.

Viewport · Theme Before After
Desktop · Dark Desktop · Dark before Desktop · Dark after
Tablet · Dark Tablet · Dark before Tablet · Dark after
Mobile · Dark Mobile · Dark before Mobile · Dark after

…ition detector

The old recorded condition (newlyHalted || (!wasHalted && !shouldHalt)) appended a
governor-ledger row on every single healthy iteration of a never-halted run, while
the resume transition (wasHalted=true, shouldHalt=false) -- symmetric with the halt
trip the old condition did correctly capture -- was never recorded at all. Replaced
with wasHalted !== verdict.shouldHalt: true exactly on the two real transitions,
false on both steady states.
@galuis116
galuis116 requested a review from JSONbored as a code owner July 27, 2026 14:30
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.38%. Comparing base (09eb223) to head (c9dedf2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9367   +/-   ##
=======================================
  Coverage   75.38%   75.38%           
=======================================
  Files         275      276    +1     
  Lines       58023    58036   +13     
  Branches     6181     6189    +8     
=======================================
+ Hits        43739    43752   +13     
  Misses      14014    14014           
  Partials      270      270           
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/governor-run-halt.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 27, 2026
@loopover-orb

loopover-orb Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-27 14:43:13 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
The one-line fix in governor-run-halt.ts:66 replaces `newlyHalted || (!wasHalted && !verdict.shouldHalt)` with `wasHalted !== verdict.shouldHalt`. Tracing the old boolean algebra confirms the PR's claim exactly: `newlyHalted` is `!wasHalted && verdict.shouldHalt`, so the old condition reduces to simply `!wasHalted` — it appended a ledger row on every healthy iteration (noise) and never appended on the halt→resume transition (silent gap). The new XOR-style condition is true exactly on both real transitions and false on both steady states, which is the correct fix, and the accompanying tests (steady-state spy assertion, forced resume-transition test, latched-halt no-append test) cover all four `(wasHalted, shouldHalt)` combinations.

Nits — 6 non-blocking
  • The new 'resume transition' test (test/unit/miner-governor-run-halt.test.ts, 'records a resume transition...') has to `vi.spyOn(engineModule, 'evaluateRunLoopHalt').mockReturnValueOnce(...)` to force a cleared verdict, and its own comment admits the real `evaluateRunLoopHalt` latches `shouldHalt:true` unconditionally once `runHalted:true` is passed in — worth confirming (not shown in this diff) that the miner-loop-cli caller actually has a path to clear `runHalted` externally between iterations, otherwise the resume branch this PR now records for is exercised only synthetically, not through the real collaborator chain.
  • The PR description's validation checklist references coverage beyond what's visible in the truncated diff (e.g. miner-loop-cli.test.ts); nothing here contradicts it, but that portion isn't verifiable from the given diff alone.
  • Consider adding a brief comment at governor-run-halt.ts:66 noting the XOR-as-transition-detector intent inline (the PR body explains it well, but a future reader skimming just the file won't see that context).
  • If the resume path is only reachable via an operator clearing `runHalted` outside this module, it may be worth a short integration test at the miner-loop-cli level (if not already present) to confirm the wiring actually reaches this branch in practice.
  • Possible screenshot-table issue: identical images (row 1) — Advisory only — verify the screenshot-table images against the stated change before deciding.
  • Possible screenshot-table issue: identical images (row 2) — Advisory only — verify the screenshot-table images against the stated change before deciding.

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 #9326
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: 1854 registered-repo PR(s), 1211 merged, 54 issue(s).
Contributor context ✅ Confirmed Gittensor contributor galuis116; Gittensor profile; 1854 PR(s), 54 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff replaces the `recorded` condition with exactly `wasHalted !== verdict.shouldHalt` as required, leaves verdict/newlyHalted/releasedItem/markFailed logic untouched, and adds tests for both the steady no-op case and the resume transition while updating existing tests to match the corrected (and previously buggy) expectations rather than leaving them contradicted.

Review context
  • Author: galuis116
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, Python, TypeScript, Dart, HTML, MDX, Rust, C++
  • Official Gittensor activity: 1854 PR(s), 54 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.

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.

ams: governor-run-halt records a ledger event on every steady-state iteration instead of only on halt/resume transitions

1 participant