Repository navigation
feat(auto-routing): custom router contracts and schema - #7784
Conversation
Adds ADR 0005 shared contracts: custom router model IDs, pool entry schemas, the public decide API, client eval protocol schemas, web REST schemas, and the signed auto-decision token. AutoRoutingModeSchema moves next to AutoRouterSchema so the new module does not import the package entry.
Inside the accuracy band a candidate whose estimated request cost is exactly 0 outranks every paid candidate and drops the cost term (ADR 0005), ordered by effectiveLatency^1.5 / wilson^15. Paid ordering is unchanged. Bumps RANKING_POLICY_VERSION so tables republish.
Stores ADR 0005 custom router definitions with an XOR owner check, one unique slug per owner, and entries typed by the contracts pool entry union. Soft delete removes a user's own routers.
Consumers that typecheck packages/db source would otherwise pull in the contracts source, which needs a newer TypeScript lib than some of them set (services/ai-attribution failed on toSorted). The jsonb entry union mirrors the contracts shape, so call sites that pass contracts values still fail to compile if the shape drifts.
|
No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Files Reviewed (1 file)
Cross-checks performed against current HEAD
Both prior Code Review Findings remain resolved at current HEAD: Previous Review Summaries (5 snapshots, latest commit 984555c)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 984555c)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Files Reviewed (1 file)
Both prior Code Review Findings are resolved in current code:
The changed Previous review (commit eeb767d)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Files Reviewed (2 files)
Previous review (commit c18af20)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Files Reviewed (4 files)
Previous review (commit f5e4253)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental commit Overview
Files Reviewed (2 files, incremental)
Re-verified since the previous review: the gateway/candidate namespace is now disjoint ( Previous review (commit 2c6a989)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (15 files)
Also verified: the signed-decision token (canonical base64url, constant-time WebCrypto verify, expiry after signature check), the Reviewed by deepseek-v4.1-flash · Input: 38.7K · Output: 4K · Cached: 313.9K Review guidance: REVIEW.md from base branch |
…ical An entries update must now send defaultEntryKey so the stored default cannot fall outside the new pool, and gateway model IDs must not start with the reserved client: prefix so a candidate model string maps to exactly one entry.
Implements PR 0 of ADR 0005 (docs/adr/0005-custom-auto-routers.md): the ADR plus the shared contracts and PostgreSQL schema every later layer builds on. No worker or web behavior here.
Contracts (
@kilocode/auto-routing-contracts)custom-router.ts: custom router model IDs with slug validation and the reserved personalorgslug, pool entry schemas for gateway and client entries, entry keys, entry refs, and the candidate-model helpers that keep client entries (client:<provider>/<model>) from colliding with gateway IDs in deny lists.POST /v1/deciderequest/response, the error code enum with its HTTP status table, and the client eval protocol schemas (plan, case, result upload). Golden answers and checks are deliberately absent from every schema.MirrorPayloadSchemagains an optional custom router reference and client entries;AutoRoutingDecisionSchemagains optionalentry,stale, andfallbackfields so old readers and writers keep parsing during a rolling deploy.signAutoDecision/verifyAutoDecisionover WebCrypto HMAC-SHA256 (Cloudflare Workers and Node), constant-time verification, canonical base64url, and expired/malformed rejection, covered by tamper, expiry, and round-trip tests.Ranking
Within the accuracy band a candidate whose estimated request cost is exactly zero now outranks every paid candidate and takes no cost term, ordered by effective latency and Wilson accuracy alone. Paid ordering is unchanged.
RANKING_POLICY_VERSIONis bumped so tables republish, and the benchmark service README documents the rule.PostgreSQL
New
auto_routing_custom_routerstable with an exclusive owner check, one unique slug per owner via partial unique indexes, owner lookup indexes, andentriesjsonb typed with the contracts entry union. Generated withpnpm drizzle generate; soft delete removes a user's own routers.Later PRs (benchmark worker, serving worker, web/gateway, cutover) and the CLI build on these contracts.