Skip to content

fix(review): compare inconclusive as text so Postgres doesn't 500 (#4997) - #5032

Merged
JSONbored merged 1 commit into
mainfrom
fix/4997-ops-anomaly-json-boolean
Jul 11, 2026
Merged

fix(review): compare inconclusive as text so Postgres doesn't 500 (#4997)#5032
JSONbored merged 1 commit into
mainfrom
fix/4997-ops-anomaly-json-boolean

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Fixes fix(review): ops-anomaly scanner's own SQL query is malformed (396 Sentry events, escalating) #4997: ops_anomaly_repo_error: Failed query... fired 396 times over 3 days, escalating, still firing at filing time.
  • Sentry Seer's summary suggested replacing the query with the working findHottestReviewTargetForRepo pattern — traced both instead: findHottestInconclusiveReviewTargetForRepo (src/db/repositories.ts) compares json_extract(metadata_json, '$.inconclusive') = 1 (a bare integer literal). SQLite's json_extract surfaces a JSON boolean as SQL integer 1/0 (so this worked fine in tests/cloud), but the self-host Postgres translation (src/selfhost/pg-dialect.ts) rewrites json_extract(...) to ->>, which always returns text — comparing that text to a bare integer literal throws a Postgres type-mismatch error on every invocation. Confirmed via grep this is the only json_extract(...) = <bare integer> comparison anywhere in the codebase; every other comparison already binds a string parameter.
  • Fix: CAST(json_extract(...) AS TEXT) IN ('1', 'true') — text-to-text on both backends. SQLite: CAST(1 AS TEXT) = '1' (byte-identical to the old = 1 semantics). Postgres: ->>'inconclusive' already yields 'true'/'false'.
  • Extra finding (issue requirement feat(scoring): add situational score projections #3): runOpsAlerts/computeOpsStats run all four per-repo anomaly checks through one Promise.all, so this one query throwing discarded gatePrecision/calibration/reviewBurst too — this bug silently blinded every anomaly detector (not just the review-failure-burst one) for every repo with any AI review activity on self-host, every scan tick.
  • Extra finding (issue requirement chore(release): prepare public gittensory launch #2): the captured vouchdev/vouch repo tag is a real, independently-owned open-source project (verified via the GitHub API) — opsScanRepos only scans rows from this install's own repositories table, so this is a genuine third-party self-host operator's registered repo, not stale/test data or a query-bug artifact. Confirms the bug affects every self-host operator, not just this install.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (Closes #4997).

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • test:coverage (full unsharded): not run end-to-end — ran scoped vitest --coverage for test/unit/db-parsers.test.ts + test/unit/ops-wire.test.ts + test/unit/selfhost-pg-dialect.test.ts (94 tests) and confirmed via lcov that both branches of the changed function's null-guard are covered.
  • actionlint / test:workers / build:mcp / test:mcp-pack / ui:openapi:check / ui:lint / ui:typecheck / ui:build / npm audit: not run — this change touches only src/db/repositories.ts (a query-text change inside an existing Drizzle sql template, no new API/schema/binding/dependency surface) and its tests; no workflow, MCP, UI, or dependency-manifest surface changed.

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. (N/A — no auth surface touched.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A.)
  • UI changes use live API data or real empty/error/loading states. (N/A.)
  • Visible UI changes include a UI Evidence section. (N/A.)
  • Public docs/changelogs are updated where needed. (N/A — internal engine behavior; changelog is not edited in a normal PR.)

Notes

Part of a batch of 13 bug fixes filed from a Sentry-issue triage this session (#4994#5006). This is #4 by priority.

)

findHottestInconclusiveReviewTargetForRepo compared json_extract's
result to a bare integer literal. SQLite's json_extract surfaces a
JSON boolean as 1/0, but the self-host Postgres translation rewrites
json_extract to `->>`, which always returns text -- comparing that
text to an integer literal threw a type-mismatch error on every call,
396 times and escalating. CAST to text first so both backends compare
text to text.

This also explains why the review-burst, gate-precision, and slop
calibration anomaly detectors went silent for every affected repo: all
four run through one Promise.all in runOpsAlerts/computeOpsStats, so
this one query throwing discarded the other three results too.

The captured `vouchdev/vouch` repo tag is a real, independently
registered self-host install (a third-party open-source project, not
one of gittensory's own repos) -- confirms every self-host operator
hit this, not just this install.
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (dcc1601) to head (dfc92bb).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5032   +/-   ##
=======================================
  Coverage   94.36%   94.36%           
=======================================
  Files         458      458           
  Lines       39255    39255           
  Branches    14322    14322           
=======================================
  Hits        37042    37042           
  Misses       1558     1558           
  Partials      655      655           
Flag Coverage Δ
shard-1 46.47% <ø> (-0.29%) ⬇️
shard-2 33.65% <ø> (+0.26%) ⬆️
shard-3 31.38% <ø> (-0.09%) ⬇️
shard-4 32.58% <ø> (-0.22%) ⬇️
shard-5 34.48% <ø> (+1.00%) ⬆️
shard-6 45.33% <ø> (+0.20%) ⬆️

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

Files with missing lines Coverage Δ
src/db/repositories.ts 96.73% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 11, 2026
@JSONbored JSONbored self-assigned this Jul 11, 2026
@JSONbored
JSONbored merged commit a720488 into main Jul 11, 2026
19 checks passed
@JSONbored
JSONbored deleted the fix/4997-ops-anomaly-json-boolean branch July 11, 2026 09:35
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.

Development

Successfully merging this pull request may close these issues.

fix(review): ops-anomaly scanner's own SQL query is malformed (396 Sentry events, escalating)

1 participant