Repository navigation
[WRONG BRANCH] fix(routing): enforce hard policy cost ceilings on unknown estimates #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os"; | |
| import { join } from "node:path"; | ||
| import { costEvidenceForCandidate, costScore } from "../src/routing/cost"; | ||
| import { evaluatePolicyProfile, COST_UNKNOWN_PENALTY_SCORE } from "../src/routing/evaluator"; | ||
| import { NoEligiblePolicyCandidateError, routeModel } from "../src/router"; | ||
| import type { OcxConfig } from "../src/types"; | ||
|
|
||
| let testDir = ""; | ||
|
|
@@ -100,6 +101,29 @@ describe("cost-aware scoring (RI-08)", () => { | |
| expect(result.selectedIndex).toBeNull(); | ||
| }); | ||
|
|
||
| test("runtime routing fails closed when a hard cost ceiling cannot be estimated", () => { | ||
| const limited = config({ | ||
| routingProfiles: { | ||
| cost: { | ||
| candidates: [{ provider: "anthropic", model: "claude-opus-5" }], | ||
| limits: { maxEstimatedCostUsd: 0.000001 }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(() => routeModel(limited, "policy/cost")).toThrow(NoEligiblePolicyCandidateError); | ||
| try { | ||
| routeModel(limited, "policy/cost"); | ||
| } catch (error) { | ||
| const trace = (error as NoEligiblePolicyCandidateError).trace; | ||
| expect(trace.candidates[0]).toMatchObject({ | ||
| eligible: false, | ||
| cost: { incomplete: true, limitUsd: 0.000001 }, | ||
| exclusions: [{ code: "unknown-price", detail: "maxEstimatedCostUsd" }], | ||
| }); | ||
| } | ||
| }); | ||
|
Comment on lines
+104
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Cover the The test does not set Also add cases for As per path instructions, 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
| test("unknown cost follows the profile policy (exclude / penalize / allow)", async () => { | ||
| const strict = config({ | ||
| routingProfiles: { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the routing documentation to describe this new precedence: because
routeModelcurrently constructs cost evidence without request usage, any live profile withmaxEstimatedCostUsdnow rejects every candidate withunknown-price, regardless ofunknownEvidence.cost. The documented example combines this limit withcost: "penalize", while the reference still says the cap applies when evidence is known, so users following it will receiveNoEligiblePolicyCandidateError/404 responses unexpectedly. Revise the English reference and translations to explain the fail-closed behavior and correct the example.AGENTS.md reference: src/AGENTS.md:L28-L28
Useful? React with 👍 / 👎.