Repository navigation
fix(desktop): agent-pill router strips markdown fences from Haiku response - #7251
Conversation
…n fences
Live log proof from a real user session:
AgentPill: router JSON parse failed — raw: ```json
{"route":"agent","title":"Build Snake Game Project",...}
Haiku's "Reply with ONLY a single-line JSON object" instruction is
non-deterministic; sometimes the model wraps the JSON in ```json …
``` markdown fences. The parser passed the whole response straight to
`JSONSerialization.jsonObject` which then failed because the bytes
start with backticks, not `{`. Falls back to chat, agent never spawns
even when Haiku correctly classified it as agent.
Robust fix: extract the first balanced `{…}` from the response before
JSON parsing. Resilient to markdown fences, leading prose, trailing
prose. No prompt change needed.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Greptile SummaryThis PR fixes a JSON parse failure in the AgentPill router that occurred when Claude Haiku wrapped its routing decision in markdown code fences, causing the Swift parser to receive raw backtick bytes instead of JSON and silently fall back to
Confidence Score: 3/5The router fix is correct and unblocks agent spawning, but the same markdown-fence failure mode survives in generateTitleAndAck and will silently degrade pill titles and voice acknowledgements. The runRouterCall change is a clean, targeted fix for the described bug. However, generateTitleAndAck makes the same Haiku call with the same no-markdown instruction, parses the result the same way, and was not updated — leaving the title/ack generation broken under the same conditions. The generateTitleAndAck function in AgentPill.swift (around line 587) needs the same brace-extraction applied before its JSONSerialization call. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant AgentPillsManager
participant Haiku as Claude Haiku (via proxy)
User->>AgentPillsManager: classify(query)
AgentPillsManager->>Haiku: POST /v2/chat/completions (router prompt)
Haiku-->>AgentPillsManager: response (may be wrapped in fences)
Note over AgentPillsManager: NEW: extract first brace block before JSON parse
AgentPillsManager->>AgentPillsManager: parse route / title / ack
AgentPillsManager-->>User: RouterDecision(route: .agent)
AgentPillsManager->>Haiku: POST /v2/chat/completions (title/ack prompt)
Haiku-->>AgentPillsManager: response (may be wrapped in fences)
Note over AgentPillsManager: NOT FIXED: still uses raw trimmed string
AgentPillsManager->>AgentPillsManager: JSON parse fails silently
AgentPillsManager-->>User: heuristic title, no ack
|
What
Live log from a user session:
Haiku classified the request as
agentcorrectly, but wrapped the JSON injson …markdown fences. The Swift parser passes the whole response toJSONSerializationwhich 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