Skip to content

fix(miner): fail closed when a chat-action handler throws#7049

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/chat-dispatch-handler-catch-6989-v2
Jul 17, 2026
Merged

fix(miner): fail closed when a chat-action handler throws#7049
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/chat-dispatch-handler-catch-6989-v2

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What

dispatchChatAction (packages/loopover-miner/lib/chat-action-dispatch.js) wraps its paramsValidator call in a try/catch — explicitly "fail closed" — but the next line, await registered.handler(request), was unguarded. A handler that throws (e.g. a network error from a governor action) would surface as an unhandled rejection instead of the module's own typed { ok, status } contract that every other failure path returns.

This is latent today (the dashboard-chat REST endpoint that invokes it is still an open epic, #6839), but wiring it live would turn any handler throw into an unhandled rejection.

How

Wrap registered.handler(request) in try/catch, returning { ok: false, status: "handler_error", action } on throw. The distinct "handler_error" status (vs "invalid_params") lets a caller tell an execution failure apart from a validation failure.

The thrown value is deliberately not echoed back in the result. A handler wraps arbitrary action work (e.g. a network call), so its error could carry external detail — the sibling fail-closed paths named in the issue (sentry.js, pretooluse-hook.js) likewise swallow rather than surface the thrown value. Fail-closed with a typed status, no raw error string.

Validation

Tests added to the existing test/unit/miner-chat-action-dispatch.test.ts: a handler throwing an Error and a handler throwing a non-Error both fail closed with the same { ok: false, status: "handler_error", action } shape. Confirmed both fail against the unfixed code (unhandled rejection) and pass with the fix; 100% statement and branch coverage on the file.

Closes #6989

dispatchChatAction wrapped its paramsValidator call in a try/catch
("fail closed") but left the next line, await registered.handler(request),
unguarded -- a throwing handler became an unhandled rejection instead of
the module's typed { ok, status } contract every other failure path
returns.

Wrap the handler call in try/catch, returning
{ ok: false, status: "handler_error", action } on throw. The distinct
handler_error status lets a caller tell an execution failure from a
validation failure; the thrown value is not surfaced (it may carry
external detail), matching the sibling fail-closed paths in sentry.js
and pretooluse-hook.js.

Closes JSONbored#6989
@shin-core
shin-core requested a review from JSONbored as a code owner July 17, 2026 19:38
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 17, 2026
@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 95.98%. Comparing base (8c81187) to head (bdb11d9).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7049      +/-   ##
==========================================
+ Coverage   93.74%   95.98%   +2.23%     
==========================================
  Files         692      609      -83     
  Lines       68706    48137   -20569     
  Branches    18760    15132    -3628     
==========================================
- Hits        64409    46202   -18207     
+ Misses       3302     1118    -2184     
+ Partials      995      817     -178     
Flag Coverage Δ
rees ?
shard-1 43.39% <66.66%> (-0.41%) ⬇️
shard-2 36.85% <0.00%> (-0.01%) ⬇️
shard-3 33.16% <0.00%> (-0.11%) ⬇️
shard-4 34.39% <100.00%> (+0.49%) ⬆️
shard-5 31.66% <66.66%> (-0.58%) ⬇️
shard-6 46.06% <0.00%> (+0.31%) ⬆️

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

Files with missing lines Coverage Δ
...ackages/loopover-miner/lib/chat-action-dispatch.js 100.00% <100.00%> (ø)

... and 83 files with indirect coverage changes

@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

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-17 19:57:17 UTC

2 files · 1 AI reviewer · no blockers · CI green · unstable

⏸️ Suggested Action - Manual Review

Review summary
This is a small, correctly-scoped fix: it wraps the previously-unguarded `registered.handler(request)` call in try/catch, returning the module's typed `{ ok: false, status: "handler_error", action }` shape on throw, consistent with the existing paramsValidator catch above it. The change closes #6989 exactly as described, adds direct tests for both Error and non-Error throws, and deliberately omits echoing the thrown value, matching the documented convention in sibling fail-closed paths. The diff is narrow, well-tested, and traces cleanly to a real gap (an unguarded await that would otherwise become an unhandled rejection).

Nits — 2 non-blocking
  • chat-action-dispatch.js:76 uses a bare `catch {}` while the paramsValidator catch above it captures `error` and includes `error.message`/String(error) in the result — worth a one-line comment (already present) but the asymmetry between the two catch blocks could confuse a future reader scanning for why one surfaces error text and the other doesn't.
  • Consider logging the swallowed handler error (e.g. via an injectable logger) even though it's not echoed to the caller, so operators have some visibility when this path goes live post-Miner dashboard chat: governor action-dispatch #6839.
Flagged checks (non-blocking)
  • Contributor trust — Contributor flagged for review

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 #6989
Related work ⚠️ 1 scoped overlap Top overlaps are listed below; lower-confidence bulk is hidden.
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: 55 registered-repo PR(s), 33 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 55 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Review context
  • Author: shin-core
  • 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: 55 PR(s), 0 issue(s).
  • Related work: Titles/paths share 6 meaningful terms. (issue #6839, issue #6989)
Contributor next steps
  • Start here: Review top overlaps.
  • Then work through the remaining 2 steps 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.

@JSONbored
JSONbored merged commit 8ba48bd into JSONbored:main Jul 17, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chat-action-dispatch.js doesn't catch handler exceptions (unlike its own paramsValidator call)

2 participants