Skip to content

feat(oracle): @maple/oracle, Effect-first oracle tests (and an on-call service fix it found) - #3270

Open
Makisuo wants to merge 5 commits into
oracle/promql-printfrom
oracle/effect-oracle
Open

Makisuo wants to merge 5 commits into
oracle/promql-printfrom
oracle/effect-oracle

Conversation

@Makisuo

@Makisuo Makisuo commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Stacked on #3268 (on #3266, on #3264).

@maple/oracle (lib/oracle) is an Effect-first take on what @tanstack/oracles gives us: a law, an independent model, and the real code checked against it on generated and hand-built histories. The real code runs as an Effect, so a law can hold a whole service, with its layers, a PGlite database and TestClock. Its first service-level law found a real bug. The on-call oracle now runs on it alone, and the @tanstack/oracles version is deleted.

The bug it found

OnCallSchedulesService read the ±15-day override window sorted from its oldest row, capped at 1,000. With 1,000 expired rows ahead, it dropped the overrides nearest the instant:

  • The next override was dropped. The layer shift was reported ending at next Monday's handoff instead of when Ben's override starts 30 hours later. who_is_on_call reads "next" from endsAt, so it skipped Ben.
  • The override that just ended was dropped. The layer shift was reported starting an hour early.

A random-seed run found it and shrank it to one schedule with a one-hour override. The fix reads the nearest rows on each side of the instant: past overrides by endsAt descending, future ones by startsAt ascending, each capped. This is the same class as the review fixes on #3264, which only covered overrides holding the instant and the newer ones cutting them.

Both cases are now hand-built histories. They are red on the old read and green with the fix.

Still open: the org-wide list read (overlappingOverrides) has the same capped-ascending shape, and no law covers it yet.

The library

  • Oracle.law({ id, statement, authority, limits, histories, resolve, model, run, check, reached, calibrations, work }).
    • run returns an Effect.
    • check returns Option<Violation>.
    • Observations are typed values, not trace checkpoints.
  • Oracle.test(law) registers one Vitest suite per law:
    • each hand-built edge;
    • each built edge (build: (base) => history) planted into sampled bases;
    • the generated histories on a fixed seed and on a random one;
    • each calibration;
    • a check that the histories reach every listed state.
  • Oracle.testLayer(law, layer) builds the layer fresh for every evaluation, including inside shrinking.
  • Generation and shrinking use Effect 4.2's own Arbitrary, not fast-check. Gen adds int, pick, oneOf, option and uniqueArray.
  • Diff reports the first difference with its path, and tells -0 from 0. Effect's Equal treats -0 and 0 as equal.
  • Work, the work bound: a law with work: { ratio } fails a change that does more work for the same answers, so a dropped shortcut is caught.
    • Measure: work is a count, never a time. It is the number of mutation sites the code evaluates during a StrykerJS run: Stryker 10's coverage helper calls plus the active mutant's hits.
    • When it runs: Stryker's dry run records each judged test's work, and a mutant run fails past the bound. It's off without MAPLE_ORACLE_WORK_FILE, so plain test runs are unaffected.
    • What it judges: the hand-built, fixed-seed and reach tests. Random seeds and calibrations are not judged.
    • Why not count activeMutant reads: that measure is biased. An active mutant skips the checks of the mutants after it at its site, which hid extra work.

On-call, on @maple/oracle only

oncall.effect-oracle.test.ts carries the five laws, the model and the hand-built edges, and now the rules header too. oncall-effective and oncall-gaps keep work: { ratio: 1 }. oncall.oracle.test.ts (@tanstack/oracles) is deleted. Its model stays, because the service law shares it. AGENTS.md and the root CLAUDE.md now say which tool owns what: alert hysteresis and the PromQL printer stay on @tanstack/oracles.

Mutation run (StrykerJS)

Stryker 10's Vitest runner works with Vitest 5. It needs a sidecar install with TypeScript 5, because this repo is on TypeScript 7. Its TypeScript checker drops mutants that wouldn't compile, which is the false gap @tanstack/oracles reports. The recipe is in lib/oracle/README.md. It is not added as a dependency.

Results for src/oncall.ts:

Killed Survived Not compiling Never reached
Without the work bound 192 27 180 6
With the work bound 215 4 180 6
  • What the bound killed: 38 mutants, each with a count, e.g. "20,363 site evaluations, more than 1 × the unmodified code's 20,360". They're the window filter, the range checks, the merge comparisons, and a rotation index computed with * for /.

  • The 4 survivors:

    • Line 406's toMs - fromMs → toMs + fromMs. This is the render limit in onCallAt's own fix. Any limit at least as long as the span behaves the same.
    • Line 339's [fromMs, endMs] → [].
    • Two variants of line 272 in the samePiece comparison.

    The last three are not yet analysed. @tanstack/oracles reported 0 gaps on this file, so these are the remaining difference.

  • The 6 never reached: 5 are in localTimeOnDay's fallback. The sixth is in absentParticipants, which no law owns.

Evidence

  • lib/oracle: 5 tests. Typecheck, oxlint -c .oxlintrc.effect.json and oxfmt are clean.
  • packages/alerting-core: 398 tests in 10 files pass. That's the 581 before, minus the deleted file's 183.
  • Backend: the OnCallSchedulesService suites pass, 31 tests including the law's 9, across 5 runs with fresh random seeds.
  • All 53 checks passed on the commit before the work bound.

🤖 Generated with Claude Code

…all oracle ported

Laws run the real code as an Effect, so a law can hold a service with its
layers, database and TestClock, not only a pure function. Histories come
from Effect's own Arbitrary (shrinking, replay tokens); observations are
typed values compared by a differ that tells -0 from 0. Each law gets
constructed edges (fixed, or built into sampled bases), fixed and random
seeds, calibrations and a reach check.

The on-call oracle is ported as the proof: the same laws, model and edges.
On the code before #3264's fix it fails both original bugs (the long
override's own end; an empty interval splitting a gap), the onCallAt one
found by a random-seed run with no constructed help.
… cannot hide the ones bounding its shift

A service-level law over OnCallSchedulesService (PGlite, a fresh database
and TestClock per history) found it on a random seed: the +/-15-day read
was sorted from its oldest row and capped at 1,000, so 1,000 expired rows
dropped the override that just ended (a layer shift reported starting an
hour early) and the next one (the shift reported ending at next Monday's
handoff instead of when Ben's override starts, so who_is_on_call skipped
him). The read now takes the nearest rows on each side of the instant.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f02c40ad-9e96-4c47-b6e0-303ec91e5543

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@maple-review-bot

This comment has been minimized.

An empty list compiled and built int(0, -1), a range no value satisfies,
so the law failed far from the call.
@maple-review-bot

This comment has been minimized.

A law with work: { ratio } records each judged test's work (mutation sites
evaluated, a count) in Stryker's dry run and fails a mutant doing more than
ratio times that. Counted from Stryker 10's coverage helper plus the active
mutant's hits, the same measure in both modes; counting activeMutant reads
is biased, since an active mutant skips the checks after it at its site.
Off without MAPLE_ORACLE_WORK_FILE or outside Stryker.
…; drop the tanstack one

oncall-effective and oncall-gaps carry work: { ratio: 1 }, as before. Under
Stryker the port now kills 215 of oncall.ts's mutants (180 do not compile,
6 are never reached) with 4 surviving, against 27 without the bound. The
rules header moves into the Effect oracle; the model stays, shared with the
service law.
@maple-review-bot

maple-review-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 10/10 · safe to merge. The narrowed override reads are order-independent (oncall.ts:260) and the two dropped-override cases are pinned by the backend law.
no findings · tests covered · risk medium

Adds @maple/oracle, an Effect-first oracle test library with mutation-run work bounds, ports the on-call laws onto it, and fixes the capped-ascending override read in decidingOverrides. Each side of the instant is now read from the instant outward, so the shift-bounding overrides are no longer crowded out; safe to merge.

  • decidingOverrides reads nearest past overrides by endsAt desc and future ones by startsAt asc
  • Work.bounded records site evaluations in a dry run and fails a mutant past ratio
  • The on-call oracle moves to oncall.effect-oracle.test.ts; the tanstack file is deleted
  • packages/alerting-core exports oncall-oracle-model for the backend service law

Before merge

b19c24b · What was checked, coverage and telemetry details are on the Maple / review check. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant