Skip to content

feat(calibration): pure BacktestCase corpus builder from fired/override events#8093

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
michiot05:feat/backtest-corpus
Jul 22, 2026
Merged

feat(calibration): pure BacktestCase corpus builder from fired/override events#8093
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
michiot05:feat/backtest-corpus

Conversation

@michiot05

Copy link
Copy Markdown
Contributor

Summary

  • Closes calibration: pure BacktestCase corpus builder from RuleFiredEvent/HumanOverrideEvent pairs #8083: adds packages/loopover-engine/src/calibration/backtest-corpus.ts — a pure, storage-agnostic builder that turns the calibration module's raw RuleFiredEvent/HumanOverrideEvent history into a labeled BacktestCase[] corpus (each "this rule fired against this target, a human later said reversed/confirmed" pair), the replayable input a backtest scorer needs.
  • BacktestCase and buildBacktestCorpus(ruleId, fired, overrides) match the issue spec exactly: only events whose ruleId matches are considered (mirrors overrideMatchesRule's event.ruleId === ruleId filter in signal-tracking.ts); a firing with no matching override (same rule AND targetKey) is excluded, not emitted unlabeled (the same "only the decided ones count" discipline as computeRulePrecision); when a target was fired+judged more than once, each firing pairs with the nearest override strictly after it, else the most recent override; metadata is omitted entirely (never set to undefined) when the firing has none, honoring the package's exactOptionalPropertyTypes discipline. Pure — no IO/DB/env/clock (Date.parse on the events' own occurredAt strings is deterministic parsing, not a clock read).
  • Added export * from "./calibration/backtest-corpus.js"; to packages/loopover-engine/src/index.ts, on its own line immediately after the existing signal-tracking.js export, as specified. Additive only — no existing consumer changes, signal-tracking.ts untouched.

Tests

Two test files, deliberately — this repo's engine coverage architecture requires it:

  • packages/loopover-engine/test/backtest-corpus.test.ts — the issue-required node:test file, mirroring the signal-tracking.test.ts precedent from feat(calibration): shared ORB+AMS signal-tracking module, with AMS wired live #8079; it gates the engine workspace's own npm run test --workspace @loopover/engine (all 615 engine tests pass). This suite runs against dist and is invisible to Codecov.
  • test/unit/backtest-corpus.test.ts — a vitest unit test importing the engine src path directly, which is what provides codecov/patch coverage: vitest's coverage.include measures packages/loopover-engine/src/**, but the engine's node:test suite runs against dist with no c8/source-map harvest step (only review-enrichment has one — see ci.yml's REES coverage note), so a node:test-only file would report 0% to Codecov. This vitest test independently exercises every branch (has/no override; single/multiple overrides incl. the no-strictly-following fallback; matching/non-matching ruleId; present/absent metadata; empty input) — 100% of the diff's lines and branches, verified locally via npm run test:coverage.

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:

  • The @loopover/engine build + its 615-test node:test suite, whole-repo typecheck, test:engine-parity, engine-parity:drift-check, docs:drift-check, and the unsharded test:coverage (confirming 100% patch coverage on the new file) were all run and pass. This change is a single pure, self-contained new engine file plus one additive barrel-export line and two test files — it touches no API/OpenAPI, migration, generated artifact, command, setting, or dependency, so the remaining test:ci steps (workers, mcp/miner packs, ui:build, db/drift checks) cannot be affected by it.

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

Not applicable — a pure calibration-engine function with no visible UI, frontend, docs, or extension change.

Notes

@michiot05
michiot05 requested a review from JSONbored as a code owner July 22, 2026 21:54
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.00%. Comparing base (321c192) to head (9a64b9b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8093      +/-   ##
==========================================
- Coverage   92.01%   92.00%   -0.01%     
==========================================
  Files         754      755       +1     
  Lines       77188    77201      +13     
  Branches    23335    23337       +2     
==========================================
+ Hits        71021    71030       +9     
  Misses       5061     5061              
- Partials     1106     1110       +4     
Flag Coverage Δ
shard-1 59.58% <0.00%> (+4.48%) ⬆️
shard-2 51.09% <0.00%> (-0.10%) ⬇️
shard-3 50.47% <100.00%> (-5.73%) ⬇️

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

Files with missing lines Coverage Δ
...loopover-engine/src/calibration/backtest-corpus.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

…de events

Closes JSONbored#8083. Adds packages/loopover-engine/src/calibration/backtest-corpus.ts
with the BacktestCase type and buildBacktestCorpus(ruleId, fired, overrides):
pairs each rule firing with the human verdict that decided it (nearest
override strictly after the firing, else most recent), excludes undecided
firings, mirrors overrideMatchesRule's ruleId filter and computeRulePrecision's
doc-comment style. Pure: no IO/DB/env/clock. Adds the barrel export and both
the node:test (engine gate) and a vitest src-path test (codecov coverage).
@loopover-orb

loopover-orb Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-22 22:20:50 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This adds a pure, well-tested function that pairs RuleFiredEvent/HumanOverrideEvent records into labeled BacktestCase entries, filtering unmatched rule/target pairs and using a documented nearest-after-else-most-recent override selection rule. The implementation logic is correct and internally consistent with the described pairing semantics, and the barrel export addition is a clean one-line, additive change. The dual test setup (node:test against dist, vitest against src) is a deliberate pattern already used elsewhere in this repo for coverage purposes, not redundant scope creep.

Nits — 5 non-blocking
  • The candidates array is filtered and sorted freshly for every firing sharing a targetKey (backtest-corpus.ts's loop), which is O(n*m) for large event histories — fine at current scale but worth a comment or optimization note if corpora grow large.
  • The `sorted[sorted.length - 1]!` non-null assertion is safe here since candidates.length===0 was already checked, but a brief inline comment noting why the assertion is safe would help future readers.
  • Verify that `overrideMatchesRule` in signal-tracking.ts is actually named/shaped as described in the header comment (I could not see that file's contents in this diff) since the doc comment leans heavily on that cross-reference.
  • Consider extracting the repeated sort/find pairing logic into a small named helper if this pairing strategy is reused elsewhere in the calibration module later.
  • The JSDoc block is quite long relative to the function size; consider trimming to the essential contract (inputs, exclusion rule, pairing rule) for readability.

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 #8083
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: 24 registered-repo PR(s), 9 merged, 3 issue(s).
Contributor context ✅ Confirmed Gittensor contributor michiot05; Gittensor profile; 24 PR(s), 3 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds backtest-corpus.ts with the exact BacktestCase type and buildBacktestCorpus signature specified, implements the nearest-following/fallback-to-most-recent pairing with a doc comment, excludes unmatched firings, handles optional metadata correctly, and adds the barrel export in the specified location; tests cover all listed branch cases (no-override, single pair, multiple overrides wit

Review context
  • Author: michiot05
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Rust
  • Official Gittensor activity: 24 PR(s), 3 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.

🟩 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.

@loopover-orb
loopover-orb Bot merged commit 423a3d1 into JSONbored:main Jul 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

calibration: pure BacktestCase corpus builder from RuleFiredEvent/HumanOverrideEvent pairs

1 participant