Skip to content

feat(chat): model router behind model "auto" (DIP 0035) - #356

Merged
ralyodio merged 3 commits into
masterfrom
feat/model-router
Nov 12, 2026
Merged

ralyodio merged 3 commits into
masterfrom
feat/model-router

Conversation

@ralyodio

Copy link
Copy Markdown
Collaborator

Copilot Fusion-style routing for c0mpute, built to fix Fusion's published weaknesses. Design: dips/0035-model-router.md.

model: "auto" (or absent, or auto:fast|standard|high|max) now:

  1. Classifies the task deterministically (category, difficulty, JSON, script), with reasons.
  2. Scores every live model: size/family priors, house specialists (tax/legal/business fine-tunes get their questions), learned per-category quality (Beta posterior in router_stats), Infernet price, measured speed, health (failing models benched).
  3. Plans single / cascade / critique / fuse by expected quality - cost - latency for the effort. Cascades only when expected cost beats the strong model alone; quality floor; trivial chats never fan out.
  4. Executes with deterministic checks first (truncation, loops, invalid JSON, broken code, refusals, stub text), escalation, fallbacks, and hedged requests to cut slow-node tails. Hard max_cost_usd / max_latency_ms.
  5. Explains: x-c0mpute-route header plus a full x_c0mpute_route receipt (every call, tokens, cost, verdict). POST /api/v1/route gives the plan for free.

Streaming at fast/standard passes straight through on the planned model (no first-token penalty) and is verified afterwards to keep learning. High/max run the plan with SSE keepalives. Resumable /chat turns route too. Any router error falls back to the old direct path; C0MPUTE_ROUTER=off disables it.

Tests (vienna, bun): router 20/20, glue 6/6. Web lib suite 147 pass. The 3 failures are environmental: two content-policy tests read node/, which my rsync left out, and the music test is a time-format assertion in an untouched module. tsc reports no errors in the touched files.

🤖 Generated with Claude Code

`model: "auto"` (or absent, or auto:fast|standard|high|max) now routes each
request: classify the task, score every live model for it (size/family
priors, house specialists, learned per-category quality, price, speed,
health), pick single / cascade / critique / fuse by expected quality, cost
and latency for the effort, run it with deterministic checks, escalation,
fallbacks and hedged requests, learn from the outcome, and return a receipt.

- lib/router: framework-free classify, registry, stats, planner, verify,
  engine; 20 tests
- lib/chat/routed.ts: Infernet calls billed per user, live pool + price
  cache, router_stats in SQLite Cloud, JSON/SSE responses, streamed
  pass-through that still learns; 6 tests
- /v1/chat/completions and resumable runs route; any router error falls
  back to the direct path; C0MPUTE_ROUTER=off disables
- POST /api/v1/route explains a plan for free; /v1/models lists auto entries;
  /chat picker offers auto:fast/high/max

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if (/^(js|javascript|mjs|cjs)$/i.test(lang)) {
try {
// Parses only; the code is never run.
new Function(code);
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

17 finding(s)

HIGH/CRITICAL: 1 | MEDIUM: 12 | LOW: 4

Severity Rule Location
HIGH js-ssrf-outbound-request apps/web/public/sw.js:24
MEDIUM js-unescaped-html-sink apps/web/src/app/blog/[slug]/page.tsx:53
MEDIUM js-unescaped-html-sink apps/web/src/app/layout.tsx:109
MEDIUM sql-template-interpolation apps/web/src/lib/chat/convo-store.ts:116
MEDIUM sql-template-interpolation apps/web/src/lib/chat/convo-store.ts:117
MEDIUM sql-template-interpolation apps/web/src/lib/chat/push.ts:476
MEDIUM js-dynamic-code-execution apps/web/src/lib/router/verify.ts:91
MEDIUM sh-remote-script-execution scripts/dev-setup.sh:25
MEDIUM sh-eval-expansion scripts/dev-setup.sh:35
MEDIUM sh-remote-script-execution scripts/install.sh:185
MEDIUM sh-remote-script-execution scripts/install.sh:210
MEDIUM sh-remote-script-execution scripts/install.sh:408
MEDIUM sh-remote-script-execution scripts/install.sh:450
LOW py-ssrf-outbound-request examples/business-strategist-agent/chat.py:37
LOW py-ssrf-outbound-request examples/business-strategist-agent/train.py:54
LOW secret-generic-credential node/crates/c0mpute-core/src/webhook.rs:1171
LOW py-path-traversal node/crates/c0mpute-core/tests/fixtures/fake-infernet-text:29

Snippets are redacted; ThreatCrush never prints matched credential material.

ralyodio and others added 2 commits November 12, 2026 11:36
#355 made PricingConfig::default() carry a $0.001 minimum; the e2e workers
built with it stopped bidding on the buyers' zero caps (inference_e2e:
'no bids received within 2s'). Same fix shape as #357 for container_run.

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

Copy link
Copy Markdown
Collaborator Author

Also carries two test-only commits so CI can pass on current master. #355 raised PricingConfig::default() to a $0.001 floor, so e2e test workers stopped bidding against the buyers' zero caps ("no bids received"):

@ralyodio
ralyodio merged commit c5b247f into master Nov 12, 2026
13 checks passed
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