feat(routing): add cost-aware policy scoring and limits - #1015
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RI-08 of the Router Intelligence / Routing Control Plane programme. Adds
cost-aware policy scoring and hard cost limits, reusing the canonical
price/cost normalization (
src/usage/cost.ts).Estimated cost, price-source provenance, estimated-vs-authoritative
distinction, and cost-limit exclusions are all recorded in the route-decision
trace. Unknown prices stay unknown (never free).
Scope
src/routing/cost.ts:costEvidenceForCandidate()-estimateRequestCost-backed evidence:estimatedUsd,priceSource(jawcode / expected / unmatched),incomplete(estimated usage OR expected-price overlay),
limitUsd,excludedByLimit.costScore()- deterministic relative score (cheaper is better, reference=
COST_SCORE_REFERENCE_USD1.0 or the profile limit when set); unknownreturns null.
src/routing/evaluator.ts:estimatedUsd > limits.maxEstimatedCostUsd->cost-limitexclusion, ineligible;
unknownEvidence.cost):exclude->unknown-priceexclusion,
penalize-> deterministic 0.3 floor,allow-> priority only;components.cost.src/router.ts- execution assembles cost evidence per candidate (usage isunknown pre-dispatch, so execution-time cost is honestly unknown unless
evidence is supplied via dry-run/evaluate).
tests/cost-scoring.test.ts- 6 tests.Estimated vs authoritative
incompleteis set when usage was estimated OR the price came from theexpected-price overlay; authoritative jawcode prices with reported usage are
complete.
Privacy / security
per-request payloads beyond the bounded trace field.
bun run privacy:scanpasses.Compatibility
RI-04). RI-05..07 behavior preserved when
optimize.cost: 0andunknownEvidence.cost: allow.Dependency
Branch base:
feat/ri-07-quota-aware-routinghead9dbdce2ab.Non-goals
are enforced on evidence supplied via dry-run/evaluate; execution-time cost
stays unknown-until-proven).
Local verification (exact)
bun x tsc --noEmit-> PASSED (0 errors)bun run test tests/cost-scoring.test.ts-> 6/6 passbun run privacy:scan-> passedSummary by CodeRabbit
New Features
Documentation
Tests