Repository navigation
fix(desktop-backend): allowlist Haiku model for /v2/chat/completions - #7249
Conversation
AgentPill router uses claude-haiku-4-5-20251001 to classify each floating-bar query as chat-vs-agent, but the Rust desktop-backend's MODEL_ROUTES allowlist only contains sonnet/opus variants. Every router call returns HTTP 400 (empty body), and the Swift client silently falls back to the chat route. Net effect: agent pills never spawn from natural-language prompts on any version since the feature shipped — only the explicit "Execute" button on notification/task cards (which bypasses the router) ever triggers them. Confirmed live with curl against both dev (`based-hardware-dev`) and prod (`based-hardware`) Cloud Run desktop-backend instances — both 400 the same way. Add two model routes for the dated ID and the bare alias, both mapping to upstream `claude-haiku-4-5`. Also add Anthropic-published pricing ($1/MTok input, $5/MTok output) to model_cost so cost tracking reflects the right tier instead of defaulting to Sonnet. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Greptile SummaryThis PR fixes a long-standing regression where the AgentPill router classifier (
Confidence Score: 5/5Safe to merge; the change is additive and targeted with verified pricing and a passing test. The change adds two entries to a static allowlist and a cost match arm. Pricing values match Anthropic published rates. The existing resolve_model path and error-handling are untouched. The only finding is a stale doc-comment. No files require special attention; the stale doc-comment on MODEL_ROUTES is the only nit. Important Files Changed
Sequence DiagramsequenceDiagram
participant Swift as AgentPill.swift
participant Backend as Desktop Backend (Rust)
participant Anthropic as Anthropic API
Note over Swift,Anthropic: Before this fix
Swift->>Backend: POST /v2/chat/completions model: claude-haiku-4-5-20251001
Backend->>Backend: resolve_model() returns None
Backend-->>Swift: HTTP 400 (empty body)
Swift-->>Swift: fallback to chat route (agent pills never spawn)
Note over Swift,Anthropic: After this fix
Swift->>Backend: POST /v2/chat/completions model: claude-haiku-4-5-20251001
Backend->>Backend: resolve_model() returns claude-haiku-4-5
Backend->>Anthropic: upstream request model: claude-haiku-4-5
Anthropic-->>Backend: classifier response
Backend-->>Swift: HTTP 200 (router decision)
Swift-->>Swift: spawns agent pill
|
…ponse (#7251) ## What Live log from a user session: ``` AgentPill: router JSON parse failed — raw: ```json {"route":"agent","title":"Build Snake Game Project","ack":"Starting your snake game builder now"} ``` Haiku classified the request as `agent` correctly, but wrapped the JSON in ```json … ``` markdown fences. The Swift parser passes the whole response to `JSONSerialization` which then fails because the bytes start with backticks. Falls back to chat → agent never spawns. ## Fix Extract the first balanced `{…}` from the response before JSON parsing. Robust to markdown fences, leading prose, trailing prose. No prompt change needed. This is the **second** of two bugs blocking natural-language agent-pill spawning. The first (server-side, model not allowlisted) was just fixed in #7249. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
What was broken
The AgentPill router (the Claude Haiku classifier that decides whether a floating-bar query stays in chat or spawns a background agent pill) has been broken since the agent-pills feature shipped. Every router call returns HTTP 400 (empty body) and the Swift client falls back to the chat route — so agent pills never spawn from natural-language prompts. Only the explicit
Executebutton on notification/task cards (which bypasses the router) ever triggers them.Confirmed live with curl against both dev and prod desktop-backend Cloud Run services — same 400 on both.
Root cause:
MODEL_ROUTESindesktop/Backend-Rust/src/models/chat_completions.rsonly allowlists Sonnet/Opus variants. The router sendsclaude-haiku-4-5-20251001(defined inModelQoS.swiftand used inAgentPill.swiftlines 152 + 547).resolve_modelreturns None → 400.Fix
claude-haiku-4-5-20251001(dated) andclaude-haiku-4-5(bare), both upstream →claude-haiku-4-5model_cost($1/MTok in, $5/MTok out) so cost tracking is rightDeploys to
desktop_backend_auto_dev.yml(auto-fires ondesktop/Backend-Rust/**changes) — ~5 minomi-desktop-swift-releaseworkflow alongside the next Swift release — ~25 minUser has a launch in <7h; want this on dev first so beta channel (routed to dev backend via #7232) gets agent pills working in the demo.
🤖 Generated with Claude Code