Skip to content

test(routing): add evidence boundary and invariant tests - #1260

Merged
Gajesh2007 merged 5 commits into
masterfrom
test/routing-invariants
Oct 5, 2026
Merged

Gajesh2007 merged 5 commits into
masterfrom
test/routing-invariants

Conversation

@davidtai

@davidtai davidtai commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add package tests in coordinator/registry for the first-content evidence predicates and for invariants that routing holds by design. The change has tests only. No production code changes.

These tests pass on master. The tests that expose the idle-evidence feedback loop in #1238 fail on master by design, so they are in a separate draft pull request.

Linked issue

Refs #1238

What the tests check

Boundary tables (first_content_evidence_boundary_test.go):

Test Edges
TestFirstContentUnknownReasonBoundaries Capacity age at 5 s and 5 s + 1 ms; performance age at 2 min and 2 min + 1 ms; unknown ages; refusal cutoff; each unknown reason; the order of reasons
TestFirstContentStatusAtBudgetBoundary Conservative forecast equal to the budget is feasible, one step under is predicted late; no deadline is never feasible; an expired deadline has a zero budget
TestFirstContentCandidateAllowedTable Every branch of firstContentCandidateAllowed (ceiling, fresh-feasible, hedge with busy or pending work)
TestExplicitMeasurementTimeBoundaries Sample age at and past 7 days; rate at and past maxPrefillTPS; count regression; changed rate without a new sample; unchanged sample keeps the older time
TestResolveEffectiveTPSPrecedence, TestResolvePrefillTPSPrecedence The decode and prefill fallback chains and their floors and caps

Seeded property tests (first_content_invariants_test.go). Each failure prints the seed and case:

Test Invariant
TestFirstContentForecastInvariants Forecasts are finite and positive; conservative is never earlier than expected; only fresh, complete, idle, loaded evidence inside the budget is feasible (first-content-routing.md, invariant 4)
TestFirstContentForecastRateMonotonicity A faster decode or prefill rate never makes either forecast later
TestFirstContentPreferenceNeverEmptiesPool The preference keeps a nonempty ordered subset, keeps every feasible candidate, and never keeps a predicted-late candidate in place of a feasible one (routing.md, invariant 7)
TestHeartbeatMeasurementDatingInvariants Random heartbeat sequences through Registry.Heartbeat on a testing/synctest clock, legacy and explicit paths: a measurement never becomes younger without a new sample, is never dated after its report, a changed legacy value is dated at the previous accepted report, and a replayed capacity sequence changes nothing

Diagrams

Behavior:

flowchart LR
  subgraph Before
    A1[Evidence predicates] --> B1[Single-decision tests at typical values]
    B1 --> C1[Limits and invariants not pinned]
  end
  subgraph After
    A2[Evidence predicates] --> B2[Tables on both sides of each limit]
    A2 --> C2[Seeded random property checks]
    B2 --> D2[A changed limit or broken invariant fails a named test]
    C2 --> D2
  end
Loading

Code:

flowchart LR
  subgraph Before
    T1[first_content_forecast_test.go] --> F1[estimateFirstContent]
  end
  subgraph After
    T2[first_content_evidence_boundary_test.go] --> F2[firstContentForecastUnknownReason]
    T2 --> G2[firstContentCandidateAllowed]
    T2 --> H2[explicitMeasurementTime]
    T2 --> R2[resolveEffectiveTPS / resolvePrefillTPS]
    T3[first_content_invariants_test.go] --> E3[estimateFirstContent]
    T3 --> P3[preferFirstContentCandidates]
    T3 --> HB3[Registry.Heartbeat to reconcileFirstContentMeasurementsLocked]
  end
Loading

Test plan

  • go test -race ./coordinator/registry/... -count=1
  • New tests 20 times: go test -race ./registry/ -run '<new tests>' -count=20
  • go vet ./registry/..., gofmt -l coordinator/ (clean)
  • golangci-lint run ./coordinator/registry/... with v2.1.6, the CI version: 0 issues
  • make coordinator-test
  • make docs-impact-check BASE=origin/master, make docs-check
  • Mutation check on a local copy of master: each of these changes makes a new test fail: legacy measurement dated at every heartbeat; >= for the capacity limit; the preference returns an empty pool; busy work counted as feasible; an unchanged explicit sample renewed.
  • The new tests also pass on the heads of fix(routing): expire dated idle decode estimates before ranking #1243 and fix(routing): explore idle providers without current first-content evidence #1254 and on a local merge of both onto master.

Components touched

  • coordinator (Go)
  • provider (Rust, legacy)
  • provider-swift (Swift CLI)
  • console-ui (Next.js)
  • enclave (Swift)
  • infra / CI / release
  • docs

Protocol / interface changes

  • No protocol/interface changes
  • Yes — described above and matching side updated

Documentation impact

  • Canonical documentation updated
  • No documentation needed — reason: tests only; *_test.go is outside the docs-impact rules and no behavior changes.

Notes for reviewers

  • The measurement monotonicity invariant (an old decode measurement must not rank an idle provider below the same provider with none) fails on master. It is in the draft closed-loop pull request with the other tests that are red by design.
  • Seeds are fixed. The tests use no wall-clock waits.

🤖 Generated with Claude Code

Refactor Pass

A dedicated refactor subagent reviewed the diff against the AGENTS.md structure, clean-code and refactor rules. Outcome: one test-only cleanup commit, edd8ba6.

  • first_content_invariants_test.go: randomFirstContentSnapshot is now randomFirstContentCandidate, because it returns a candidate. The shared helpers now have domain names: firstContentStatusesOf and isOrderedCandidateSubset.
  • checkHeartbeatMeasurementDating: the renewed and changedByNewValue fields always held the same value in every row, so they are now one newSample field.
  • Every assertion, boundary row, seed and synctest schedule is unchanged. No production code changed.

Validation on the final tree: gofmt -l, go test -count=1 ./registry/..., go vet, golangci-lint v2.1.6 (0 issues), git diff --check, make docs-impact-check BASE=origin/master, and make docs-check (324 OK) all pass.

Needs a port before merge: the branch merges into master c5552d3 with no text conflict, but the merged tree fails. TestCoordinatorTestsAreIsolated rejects both files, because they are outside coordinator/tests/. Also, go test ./registry/ does not compile there: firstContentFreshness, measuredFirstContentCandidate and testLogger are undefined. The tests must be rewritten against exported or internal/ APIs, as package registry_test.

Port to master, 0265f77 plus a09c193 (follow-up): both test files moved to coordinator/tests/registry/ and run through real entry points: forecast.UnknownReason, forecast.Evaluate, forecast.Allows, measurements.History.Reconcile, performance.Rates, selection.Prefer, and Registry.Heartbeat with ReserveProviderEx. The seeds, the 2000 cases and the synctest schedules are kept. The two hedge rows became one, because the scheduler folds busy and pending into one input. A new test, TestFirstContentHedgeSkipsProviderWithPendingReservation, covers the pending case through the scheduler. Mutation checks: min in place of max, removing the clamp and an inclusive cutoff are each caught. Removing the hedge gate's totalPending > 0 term is not caught: wholeMacBusy already covers it, so that term may be dead. Open: the preference-tier rule and the snapshot-to-evidence mapping are covered only through the existing ReserveProviderEx tests.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Add package tests for the first-content evidence predicates and for
invariants that routing holds by design.

Boundary tables cover the capacity and performance freshness limits,
the budget edge between feasible and predicted late, the candidate gate,
the explicit measurement dating rules, and the decode and prefill rate
fallback chains.

Seeded property tests check the forecast invariants, that a faster rate
never makes a forecast later, that the first-content preference never
empties or reorders the pool, and that heartbeats on a virtual clock
never make an unchanged measurement younger. Each failure prints its
seed and case.

All new tests pass on master. The tests that expose the idle-evidence
feedback loop in #1238 are in a separate draft pull request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

After #1243 merges, the decode fallback table needs a row for an idle
provider whose decode measurement is older than 30 minutes. The row
cannot be added yet because the age field does not exist on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Sep 30, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

Rename the random candidate generator and pool helpers to say what they
return, and merge the two identical new-sample flags in the dating check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits October 4, 2026 19:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tor/tests

Master keeps every coordinator test under coordinator/tests in the
external package, and the first-content predicates now live in internal
packages. Move both files to coordinator/tests/registry and test each
predicate at the package that owns it:

- forecast.UnknownReason, forecast.Evaluate and forecast.Allows for the
  freshness, budget and candidate gate tables and the seeded forecast
  invariants.
- measurements.History.Reconcile for the explicit measurement dating
  table.
- performance.Rates for the decode and prefill rate chains.
- selection.Prefer for the seeded pool narrowing invariant.
- Registry.Heartbeat and ReserveProviderEx for the synctest dating
  invariant. The routing age now comes from the routing decision.

The scheduler folds busy and pending work into one occupied input, so
the two hedge rows become one table row plus a scheduler test where a
pending reservation keeps a hedge off the provider. All rows, seeds and
synctest schedules are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head a09c1934df8e against base 5b7a675c7490.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Ten-PR pilot complete; maintainer evaluation required

Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging.

Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned.

Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens.

@Gajesh2007 Gajesh2007 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head a09c193 and rechecked clean integration against master b52b393. The delta is limited to two external registry test files with no serving-code change. All eleven added boundary/property/heartbeat test functions passed locally on this head; current coordinator, integration, release-integrity, documentation and signature checks passed. These tests protect current evidence invariants and do not establish the stronger starvation policy proposed in draft #1262. Low incremental merge and deployment risk.

@Gajesh2007
Gajesh2007 merged commit ec03360 into master Oct 5, 2026
28 of 33 checks passed

This branch was successfully deployed

No deployments
benchmarks — a09c1934 Deployed Oct 5, 2026 by davidtai via E2E Benchmarks #2238
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.

2 participants