Skip to content

fix(desktop-backend): allowlist Haiku model for /v2/chat/completions - #7249

Merged
kodjima33 merged 1 commit into
mainfrom
worktree-add-haiku-model-route
May 12, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
worktree-add-haiku-model-route

Conversation

@kodjima33

Copy link
Copy Markdown
Collaborator

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 Execute button 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_ROUTES in desktop/Backend-Rust/src/models/chat_completions.rs only allowlists Sonnet/Opus variants. The router sends claude-haiku-4-5-20251001 (defined in ModelQoS.swift and used in AgentPill.swift lines 152 + 547). resolve_model returns None → 400.

Fix

  • Add two MODEL_ROUTES entries: claude-haiku-4-5-20251001 (dated) and claude-haiku-4-5 (bare), both upstream → claude-haiku-4-5
  • Add Anthropic-published Haiku 4.5 pricing to model_cost ($1/MTok in, $5/MTok out) so cost tracking is right
  • Unit test for the new routes

Deploys to

  • Dev Cloud Run via desktop_backend_auto_dev.yml (auto-fires on desktop/Backend-Rust/** changes) — ~5 min
  • Prod Cloud Run via Codemagic omi-desktop-swift-release workflow alongside the next Swift release — ~25 min

User 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

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]>
@kodjima33
kodjima33 merged commit 1aa1172 into main May 12, 2026
2 checks passed
@kodjima33
kodjima33 deleted the worktree-add-haiku-model-route branch May 12, 2026 19:44
@greptile-apps

greptile-apps Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a long-standing regression where the AgentPill router classifier (claude-haiku-4-5-20251001) was blocked by the model allowlist in the Rust desktop backend, causing every router call to return HTTP 400 and agent pills to never spawn from natural-language prompts. The fix adds two MODEL_ROUTES entries for Haiku 4.5 (dated and bare aliases), a matching model_cost arm with verified Anthropic-published pricing, and a unit test.

  • models/chat_completions.rs: Adds claude-haiku-4-5-20251001 → claude-haiku-4-5 and claude-haiku-4-5 → claude-haiku-4-5 routes to MODEL_ROUTES, mirroring the pattern used for Sonnet/Opus pass-through aliases.
  • routes/chat_completions.rs: Adds a model_cost match arm for claude-haiku-4-5 with correct Anthropic pricing ($1/$5 per MTok input/output, 10%/125% cache rates) and a test asserting both model IDs resolve correctly.
  • CHANGELOG.json: Records the fix in the unreleased section.

Confidence Score: 5/5

Safe 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

Filename Overview
desktop/Backend-Rust/src/models/chat_completions.rs Adds two MODEL_ROUTES entries for claude-haiku-4-5-20251001 and claude-haiku-4-5; logic is correct. Doc-comment on MODEL_ROUTES is now stale.
desktop/Backend-Rust/src/routes/chat_completions.rs Adds model_cost arm for claude-haiku-4-5 with correct Anthropic-published pricing ($1/$5 per MTok, 10%/125% cache rates) and adds a unit test covering both the dated and bare model IDs.
desktop/CHANGELOG.json Adds an unreleased changelog entry describing the agent-pill router fix.

Sequence Diagram

sequenceDiagram
    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
Loading

Comments Outside Diff (1)

  1. desktop/Backend-Rust/src/models/chat_completions.rs, line 307-308 (link)

    P2 The doc-comment on MODEL_ROUTES now says "All models resolve to Claude 4.6 (sonnet/opus)" but this PR adds a Haiku 4.5 pass-through that stays on 4.5, making the comment misleading for the next reader.

Reviews (1): Last reviewed commit: "fix(desktop-backend): allowlist claude-h..." | Re-trigger Greptile

kodjima33 added a commit that referenced this pull request May 12, 2026
…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)
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.

1 participant