Skip to content

fix(engine): key denyResult decision off eventType, not stage - #9002

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
nghetien:fix/issue-8864-a2-fix-engine-budget-cap
Jul 26, 2026
Merged

fix(engine): key denyResult decision off eventType, not stage#9002
JSONbored merged 1 commit into
JSONbored:mainfrom
nghetien:fix/issue-8864-a2-fix-engine-budget-cap

Conversation

@nghetien

Copy link
Copy Markdown
Contributor

Summary

Fixes the governor ledger misclassifying the budget-cap termination ceiling as deny instead of paused.

denyResult in packages/loopover-engine/src/governor/chokepoint.ts computed the ledger's decision field by checking stage === "kill_switch". But the budget-cap termination ceiling reaches denyResult with stage: "budget_cap" and eventType: "kill_switch" (see budget-cap.ts:87-92 — the termination dimension is deliberately the most severe verdict, kill_switch). Because the stage label isn't literally "kill_switch", that path recorded decision: "deny" even though the same eventType is mapped to "paused" on the top-level kill-switch path. The ternary now checks eventType instead of stage, so any chokepoint stage whose event type is kill_switch consistently records decision: "paused".

Scope

  • packages/loopover-engine/src/governor/chokepoint.ts — the ternary fix
  • packages/loopover-engine/test/chokepoint.test.ts — regression assertion on the existing termination-ceiling test

Validation

  • npx turbo run build --filter=@loopover/engine && npx turbo run build --filter=@loopover/mcp && npx turbo run build:tsc build:verify --filter=@loopover/miner — green
  • npx vitest run --changed=upstream/main --passWithNoTests — 109 files / 1745 tests, all passed
  • npm test — 21981/22002 tests passed (21 skipped); the package's own chokepoint.test.ts suite (27 tests) passes including the new assertion

Notes

This is a two-line, engine-only logic fix — no UI/frontend files were touched, so no screenshot evidence applies.

Closes #8864

denyResult mapped decision to "paused" only when stage === "kill_switch",
so the budget-cap termination ceiling (stage "budget_cap", eventType
"kill_switch") recorded decision "deny" instead of "paused" in the
governor ledger. Switch the ternary to check eventType, matching the
vocabulary the ledger event already carries.
@nghetien
nghetien requested a review from JSONbored as a code owner July 26, 2026 15:35
@superagent-security

Copy link
Copy Markdown
Contributor

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

1 similar comment
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@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 93.87%. Comparing base (904aeb9) to head (5187ae5).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9002      +/-   ##
==========================================
- Coverage   93.87%   93.87%   -0.01%     
==========================================
  Files         807      807              
  Lines       80464    80464              
  Branches    24398    24398              
==========================================
- Hits        75538    75534       -4     
  Misses       3561     3561              
- Partials     1365     1369       +4     
Flag Coverage Δ
backend 95.15% <100.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...ackages/loopover-engine/src/governor/chokepoint.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@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 15:55:13 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a correct, minimal fix: `denyResult`'s `decision` field previously keyed off `input.stage === "kill_switch"`, which missed the budget-cap termination ceiling (stage `"budget_cap"`, eventType `"kill_switch"`); the ternary now checks `eventType` instead, so any stage whose eventType is `kill_switch` consistently records `decision: "paused"`. The regression test at chokepoint.test.ts:97 directly asserts the previously-mislabeled path now records `paused`, and this doesn't disturb the other ternary arms (`throttled`->`throttle`, else `deny`) which are unaffected by the change since those eventTypes never collide with the kill_switch check. The fix is at the correct layer (the ledger-decision mapping itself, not a stage-specific patch), matching the existing top-level kill-switch call site's own eventType semantics.

Nits — 3 non-blocking
  • The PR doesn't explicitly show it addresses any additional call sites recording `decision` based on stage elsewhere in the codebase — worth double-checking `governor-ledger.ts` or callers don't duplicate the old stage-based logic.
  • Consider adding a comment near the ternary noting that `decision` must be derived from `eventType`, not `stage`, to prevent a future regression re-introducing the same bug (chokepoint.ts:137).
  • Code changes lack test evidence — Add focused regression tests or explain why existing coverage is sufficient.

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 #8864
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: 4 registered-repo PR(s), 1 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor nghetien; Gittensor profile; 4 PR(s), 0 issue(s).
Improvement ℹ️ None detected risk: low · value: none · LLM: moderate
Linked issue satisfaction

Addressed
The ternary now checks input.eventType === "kill_switch" instead of input.stage, exactly as required, and the existing termination-ceiling test gains an explicit assertion that ledgerEvent.decision === "paused".

Review context
  • Author: nghetien
  • 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: 4 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
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.

Decision record
  • action: hold · clause: ai_review_inconclusive
  • config: 03a7f8b529a9 · pack: oss-anti-slop
  • record: 782a57468959 (schema v2, head 5187ae5)

🟩 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 added the manual-review Gittensor contributor context label Jul 26, 2026
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. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(engine): budget-cap kill-switch ceiling misclassifies as "deny" in the governor ledger

2 participants