Decouple mode/tier classification from tab/session naming → eliminates the ~25% fail-safe rate
Summary
In hooks/PromptProcessing.hook.ts, mode/tier classification shares a single claude inference call with tab-title + session-name generation. That combined call uses a large (~3,000-word) system prompt on the standard (sonnet) level. Because the call is slow and occasionally returns unparseable JSON, classification fails on a large fraction of prompts — and every failure falls to the conservative fail-safe (ALGORITHM E3), which defeats the point of the classifier.
Evidence
From one install, ~1,700 logged classifications in MEMORY/OBSERVABILITY/prompt-processing.jsonl:
- ~25% of classifications fell to
source: fail-safe. - Breakdown of the failures: ~82% timeouts (25s), ~15% JSON-parse failures, the rest non-zero exit / PATH.
- Classifier latency p50 ≈ 14s, p90 ≈ 22s, p95 ≈ 24s — right at the 25s timeout cliff, which is why the tail times out.
Root cause
One heavy call does three jobs. The cost and latency of naming — the non-critical part, which already has deterministic fallbacks — is coupled to classification, the executor-gating part. So a slow or unparseable naming response forces classification to fail-safe.
Fix that worked
Split mode/tier into its own dedicated call with a tiny (~120-word) classify-only prompt on the fast (haiku) level, run in parallel with the naming call:
- Classification dropped to ~6–15s and rarely fails.
- A slow/unparseable naming response can no longer force a fail-safe.
- Post-change the fail-safe rate dropped to single digits.
Two correctness fixes pair naturally with it: hardening the --json parser in Inference.ts (see #1323) and scrubbing leftover CLAUDE_CODE_* env vars before the child spawn (see #931). #1158 (slash-prefixed prompts) is a separate fail-safe trigger this doesn't address.
Happy to share the diff if it's useful.
Independent confirmation of your numbers, plus measurements that may sharpen the diagnosis.
Our latency signature is nearly identical to yours. On a separate v5.0.0-derived install
(macOS, subscription-billed claude --print spawn path via Inference), the last 400 classified
prompts show:
- p50 blocking latency 12.0s, p90 20.0s (your ~14s / ~22s)
- fail-safe rate 8% background, spiking to 88% on a heavy day (22/25 prompts)
- 84 cumulative minutes of dead pre-prompt wait across those 400 prompts
Two data points that go beyond coupling-as-cause:
-
The spawn path, not the model, dominates — and it degrades under concurrency. A solo probe through the same inference path (Haiku, tiny prompt) completes in 3.8s; running 4 concurrent calls → ~8s each (measured). With several sessions open (each with inference-calling hooks) plus subagents, per-call e2e lands at 13–20s+ and the cap trips. That explains why our fail-safe rate swings 8%→88% with load while the code is unchanged — and it means a decoupled-but-still-blocking classifier (your 6–15s result) still pays the contention tax on every prompt.
-
Telemetry-driven alternative we're testing: full detach + advisory logging. The hook keeps its deterministic zero-latency fast-paths (ratings/praise → MINIMAL), emits no mode line otherwise (the executor-side fallback rules in the shipped system prompt already cover this case — they were governing 88% of our prompts anyway), and a detached child still runs the naming inference AND logs its mode/tier opinion to telemetry as
source: advisorywithout emitting it. That converts the classifier from a per-prompt latency tax into a free-running agreement measurement — you can quantify executor-vs-classifier divergence per model generation and re-attach with evidence if a given executor under-tiers.
Happy to share the eval script (reads prompt-processing.jsonl, prints fail-safe rate /
latency percentiles / a keep-vs-detach verdict) if useful.
This exact split landed: classification now lives in its own dedicated router hook (with deterministic fast-paths, a result cache, and a classify-only prompt), while PromptProcessing keeps only tab/session naming — so a slow naming call can never force a classification fail-safe again. One divergence from your proposal: the classifier deliberately runs on the strongest model rather than the fastest, since routing decisions gate everything downstream. Your telemetry breakdown was genuinely useful — thanks.