feat(router): tier bump on repeated failed edits (tool-error escalation, ships off) #119
Reference in New Issue
Block a user
Delete Branch "feat/tool-error-escalation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
When an agent keeps failing its own edits (exact-match
editerrors), the router now raises the tier by one for that request. Detection is stateless and read from the request body: eachrole: "tool"result is paired with the assistanttool_callsentry that produced it, and consecutive edit-class argument errors at the tail are counted. Nothing is stored per session, so the signal cannot go stale and it clears the moment the model lands a good edit.Motivating case (2026-10-17): a worker was routed to
gemma-4-31bat tier 1 for 17 of 21 turns and failed 4 of its 6editcalls; earlier workers on stronger models failed 1 in 13 and 1 in 17. Nothing in the router reacted to the failures.Behavior
edit,write,apply_patch,patch,multiedit) whose result matches an argument-error pattern.Tool execution abortedis neutral (neither counts nor resets);bashfailures and read errors are ignored.escalation.tool_error_bump.threshold(default 3) consecutive errors. Action:min(tier + max_bump, escalation.max_tier), this request only, never lowers a tier.escalation.tool_error_bump.enabled: false). While off it still logstool_error_scan id=... errors=N would_escalate=... tier=T, so the real message shape can be checked in the journal before enabling.escalation.enabledswitch anditeration.max_rebill_prompt_tokens(a bump can switch models and lose the prompt cache).tool_error_escalation_skipped(a bump never turns a working request into a 422).Observability and controls
route_decisions.escalation_reason(e.g.tool_errors:3:1->2), additive migration, shown as a badge in the admin Decisions log./metricstool_error_bumpsplus a warning class in the TUI warnings panel, grouped by the model that was failing (the previous decision's model in the same session). The query is bounded and usesidx_route_decisions_observed(EXPLAIN QUERY PLAN:SEARCH d USING INDEX, noSCAN d).escalationsettings, in thesafety_netscategory; the knob-coverage gate passes unchanged.docs/routing.md: new "Tool-error tier escalation" section.Verification
tests/test_metrics.pyandtests/test_conversation_wiring.pyare identical to main; no existing test lines are removed.Notes for review
c2aa1b4has a mangled message (two items squashed into one subject line, with a literal\n\n). Content is correct; not rewritten.bashfailures.Deploy (operator)
git pull --ff-only origin main, then back upconfig/config.local.yaml(command cp -f).systemctl --user restart llm-router.service.journalctl --user -u llm-router.service | grep tool_error_scanfor a day:errors=should be nonzero on real failed-edit turns and reset after a good edit.escalation.tool_error_bump.enabledon from Admin > Controls (runtime + persisted).🤖 Generated with Claude Code
VERIFIED BUG: with no tier>=3 models, 3 edit errors bumped tier 1->3 (max_bump=2, max_tier=3) returned HTTP 422 'No model satisfies the hard filters (tier >= 3 ...)', while with the knob off the same request returned 200. Fix in src/dispatcher.py chat_completions, BOTH the cached branch and the classify branch: after the bump re-route, if bump_reason is not None and decision.selected is None, log tool_error_escalation_skipped, reset bump_reason to None, and route() AGAIN with the ORIGINAL tier. Avoids 12-line TaskRequest duplication via local _route_at(tier) function next to each route() call. Tests appended to tests/test_tool_error_escalation.py: (1) cache-miss path: delete tier-3 rows, bump enabled, threshold 3, max_bump 2 -> status 200, UNBUMPED tier (1), escalation_reason IS NULL (2) cached branch: same with seeded session cache Mutation evidence: removing the fallback if block causes test (1) to FAIL with 422 at tests/test_tool_error_escalation.py:629.The classifier_reject column comment lost its first line ('-- NULL when the answer was used,') and was re-indented by 3 spaces. Restore the ORIGINAL comment block exactly as in origin/main. The only change to the column line is adding the comma after 'classifier_reject TEXT' (no longer the last column). Keep the escalation_reason column and its short comment after it.a6656d3due to scope creep and missing tests fde1648393