Skip to content

feat(ci): backtest logic/regex detection changes against recorded history in a dedicated CI job#8147

Merged
JSONbored merged 4 commits into
mainfrom
feat/backtest-logic-check
Jul 23, 2026
Merged

feat(ci): backtest logic/regex detection changes against recorded history in a dedicated CI job#8147
JSONbored merged 4 commits into
mainfrom
feat/backtest-logic-check

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Runs in CI, not ORB's Worker: verifying a logic rewrite requires executing the PR's own code — the same pull_request trust boundary validate-code/validate-tests already rely on (no pull_request_target anywhere; fork runs get no secrets and are skipped with a visible notice job). The base checkout nests inside the head workspace so one npm ci serves both sides. Advisory only: not a required check, never blocks merge (#8105); posts its own comment rather than joining ORB's unified review comment (deliberate — see the issue's Boundaries).

Closes #8139

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 (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • 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:

  • Full npm run test:ci ran green end-to-end (includes every box above). The new scripts/** files are outside coverage.include (established scripts exemption), but the pure core carries 24 dedicated unit tests anyway, including an end-to-end replay through the real buildLinkedIssueSatisfactionResult and an explicit secret_leak-exclusion test at both the registry and scoring layers. The thin-IO CLI is glue only (arg parsing, file IO, dynamic imports, one wrangler call) per the export-d1-data.ts precedent.

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.

Trust-boundary notes: the workflow uses plain pull_request (never pull_request_target), permissions: contents: read + pull-requests: write only, persist-credentials: false on both checkouts, and gates every secret-bearing step behind the job-level fork exclusion (mirroring ci.yml's paired fork convention — forks get a visible skip-notice job instead). secret_leak remains permanently excluded from raw-context replay at both the registry and the scoring guard, each with its own test. The D1 persist is best-effort and can never fail the advisory run; the posted comment contains only backtest metrics, shas, and case counts.

UI Evidence

Not applicable — no UI change.

Notes

…mismatch's fired-event metadata (#8139)

The existing #8129 raw-context capture (issueText/prTitle/prBody/diff) rebuilds
the prompt but never stored what the model actually returned, so a future logic
backtest couldn't replay parseLinkedIssueSatisfactionOpinion/
buildLinkedIssueSatisfactionResult against real history -- only the prompt
inputs, not the output they need to re-parse. Threads the raw text through
runWorkersSatisfactionOpinion and the BYOK path, bounded at the capture site
in processors.ts the same way the other raw-context fields are.

Part of #8139 (logic/regex backtest CI check); the CI job itself is not yet
implemented.
…tory in a dedicated CI job (#8139)

A PR that rewrites detection logic (not just a threshold, #8138/#8142) now gets
the same honest before/after backtest: a new path-filtered workflow checks out
the PR's head AND base, replays linked_issue_scope_mismatch's captured raw
context (#8129/#8130 + the model-response capture) through both versions of
buildLinkedIssueSatisfactionResult, scores them with @loopover/engine's
scoreBacktest/compareBacktestScores, posts its own advisory PR comment, and
persists a calibration.logic_backtest_run audit event for #8140's track record.
backtest-track-record.ts now aggregates both sibling event types, so #8105's
Phase-2 decision reads threshold AND logic runs, not a partial record.

Runs in CI, not ORB's Worker, because verifying a logic rewrite requires
executing the PR's own code -- the same trust boundary validate-code already
uses, and one the credential-holding Worker must never cross. Pure core
(registry scoped to linked_issue_scope_mismatch, secret_leak permanently
excluded per #8130, classify construction, comment/SQL rendering) is fully
unit-tested; the CLI is thin IO glue per the export-d1-data.ts precedent.
Advisory only -- never a required check, never blocks merge (#8105).
@JSONbored JSONbored self-assigned this Jul 23, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

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

…d-X a PR on infra errors (#8139)

First live run surfaced two problems at once: the repo's CLOUDFLARE_API_TOKEN
is scoped Workers Scripts:Edit only (no D1 access), so the corpus export died
with Cloudflare 7403 -- and that red check is not harmless, because the review
engine auto-closes contributor PRs on ANY failed check, required or not. An
advisory job that can go red on an under-scoped token, a D1 outage, or a
comment-post hiccup would let our own plumbing close innocent contributor PRs
touching the watched paths.

Every D1/comment step now catches its own failure, emits a ::notice explaining
exactly what was skipped and why, and keeps the job green -- 'never blocks
merge' (#8105) now holds against the job's own failures, not just its
verdicts. Enabling the backtest for real needs a D1-scoped token in the
CLOUDFLARE_API_TOKEN secret; until then the job is a visible no-op.
@JSONbored

Copy link
Copy Markdown
Owner Author

Heads-up from the first live run of the new workflow (it path-matched this PR itself): the corpus export failed with Cloudflare 7403 — the repo's CLOUDFLARE_API_TOKEN secret is scoped Workers Scripts:Edit only (per ui-preview-deploy.yml's own comment) and has no D1 access.

Pushed a follow-up commit making every D1/comment step fail open (notice + green): the review engine auto-closes contributor PRs on any failed check, so an advisory job must never go red on infra problems. The job is now a visible no-op until the token is fixed.

Action item (needs your Cloudflare dashboard access): add D1 read/write scope for the loopover database to the CLOUDFLARE_API_TOKEN repo secret (or add a separate D1-scoped token and I'll switch the workflow to it). Until then the backtest computes nothing but harms nothing.

… its reproducibility freeze point (#8139)

The persisted run recorded the comparison and both shas but not WHICH corpus
snapshot it scored -- without that, a skeptical re-run can't prove it replayed
the same history. The manifest's own checksum (#8084) is already in hand at
run time; thread it into the persisted metadata and the PR comment, so
checksum + head/base shas + the public scoring code make every run
independently re-runnable end to end (the reproducible-backtest posture
#8136 is evaluating).
@JSONbored

Copy link
Copy Markdown
Owner Author

Re-ran the workflow after the token update (attempt 2, 05:49Z) — still Cloudflare 7403 on the corpus export. Local ground truth narrows it down:

  • The D1 database b2c79dd6-… is owned by account zeronode (918f0f0e2eb26709d1cf4fb76085c8fb) — verified via wrangler whoami + wrangler d1 list, and a remote d1 execute query from that account succeeds.
  • 7403 ("given account is not valid or not authorized") on /accounts/$CLOUDFLARE_ACCOUNT_ID/d1/database/b2c79dd6… is the signature of an identity mismatch, so one of:
    1. the CLOUDFLARE_ACCOUNT_ID repo secret isn't 918f0f0e2eb26709d1cf4fb76085c8fb, or
    2. the D1 permissions were added to a new token whose value never replaced the CLOUDFLARE_API_TOKEN secret (editing the existing token in the dashboard keeps its value; creating a fresh one does not), or
    3. the token is account-restricted to a different account than zeronode.

Once either secret is corrected I (or any push) can re-run and it should go end-to-end. Two harmless observations from the same check: the remote database is still cloud-named gittensory (rename residue — wrangler resolves by the id in wrangler.jsonc, so nothing breaks), and audit_events has 0 calibration.* rows yet, so the first real backtest comment will honestly report an empty corpus.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.03%. Comparing base (b3cb3c9) to head (7ff11c6).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/queue/processors.ts 0.00% 0 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (87.50%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8147      +/-   ##
==========================================
- Coverage   92.03%   92.03%   -0.01%     
==========================================
  Files         764      764              
  Lines       77540    77544       +4     
  Branches    23436    23439       +3     
==========================================
+ Hits        71366    71369       +3     
  Misses       5062     5062              
- Partials     1112     1113       +1     
Flag Coverage Δ
shard-1 57.17% <87.50%> (-0.47%) ⬇️
shard-2 54.43% <12.50%> (+3.51%) ⬆️
shard-3 50.28% <12.50%> (-4.17%) ⬇️

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

Files with missing lines Coverage Δ
src/services/linked-issue-satisfaction-run.ts 100.00% <100.00%> (ø)
src/services/linked-issue-satisfaction.ts 100.00% <100.00%> (ø)
src/queue/processors.ts 95.72% <0.00%> (-0.04%) ⬇️

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 23, 2026
@JSONbored
JSONbored merged commit fec8f12 into main Jul 23, 2026
17 of 18 checks passed
@JSONbored
JSONbored deleted the feat/backtest-logic-check branch July 23, 2026 05:56
JSONbored added a commit that referenced this pull request Jul 23, 2026
…#8114) (#8153)

#8138 (threshold backtest, shipped ORB-native in #8142) and #8139 (logic
backtest CI check, shipped in #8147) are exactly the #3047 failure shape --
new CLI flags, a new CI check with its own trigger/comment behavior, a
gate-adjacent pending policy decision (#8105) -- with no docs. Adds
content/docs/backtest-calibration.mdx (corpus model, the two backtest
mechanisms and why they run where they run, how to read the Pareto-floor
comparison, secret_leak's permanent exclusion, the track-record/corpus-export
CLIs, and the advisory-only guarantee with #8105 noted as pending) plus the
thin route, nav/command-palette entries, and the regenerated route tree.
The two pinned docs-route-count tests move 48 -> 49.
@github-actions

Copy link
Copy Markdown
Contributor

Logic backtest

Replayed 0 historical case(s) for linked_issue_scope_mismatch through the base (b3cb3c9) and head (992c32e) versions of its detection logic.

Backtest comparison: linked_issue_scope_mismatch

Verdict: unchanged — no comparable axis moved.

Advisory only — this check never blocks merge (#8105).

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.

Extend the backtest check to logic/regex changes via a dedicated CI job, using captured raw context

1 participant