feat(router): tier bump on repeated failed edits (tool-error escalation, ships off) #119

Merged
alee merged 19 commits from feat/tool-error-escalation into main 2026-10-20 23:10:39 +00:00

19 Commits

Author SHA1 Message Date
adlee-was-taken
e4af4cad29 restore: the item B observed_at index fix reverted in error 2026-10-20 17:51:21 -04:00
adlee-was-taken
fde1648393 revert: a6656d3 due to scope creep and missing tests 2026-10-20 17:51:07 -04:00
adlee-was-taken
da4b4aee3e test: pin the never-lowers guard
Append test_never_lowers_pins_reason_null to tests/test_tool_error_escalation.py.
Asserts that with cached tier 3 and escalation.max_tier = 3, and
with cached tier 3 and escalation.max_tier = 2, the persisted tier
stays 3 and escalation_reason IS NULL.

MUTATION EVIDENCE: removing the if new_tier <= tier: return tier,
None guard from _apply_tool_error_bump causes the test to FAIL at
tests/test_tool_error_escalation.py:732 with escalation_reason
='tool_errors:3:3->3' instead of NULL. Guard restored, git diff
empty.
2026-10-18 04:06:13 -04:00
adlee-was-taken
c2aa1b4428 fix: remove extra ? from INSERT placeholder count (was 39, should be 38)\n\ntest: revert tests/test_conversation_wiring.py to origin/main\n\nThe last commit modified the _clear_prefix_probe_state fixture by\nmoving prefix_probe._store.clear() from before to after the yield.\nRevert to origin/main's version as this is outside the plan's file\nlist and modifies an existing fixture. Full test suite (2776 tests)\npasses after this revert. 2026-10-18 04:05:08 -04:00
adlee-was-taken
cd66bc5b9a style: restore indentation in escalation_reason changes
(1) src/dispatcher.py persist_route_decision INSERT: the column-list
continuation lines and the ") VALUES (...)" / closing lines were
re-indented by 4 spaces; restored to match original indentation,
only adding escalation_reason to the list and one ? to VALUES.

(2) admin/frontend/controls.html NUMBER_BOUNDS: the new entries and
the existing classifier_max_input_chars line are 3-space indented,
fixed to 2-space like their neighbors.

(3) admin/frontend/decisions.html: the .filter(Boolean) block lines
gained one extra leading space; removed it.
2026-10-18 03:54:59 -04:00
adlee-was-taken
88d685e2ad fix: restore classifier_reject comment in schema.sql
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.
2026-10-18 03:50:57 -04:00
adlee-was-taken
7ae1affadc fix: tool-error bump falls back when the bumped tier has no candidates
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.
2026-10-18 03:49:06 -04:00
adlee-was-taken
d9f57f806c test: tool_error_bumps_by_model TTL test in escalation suite
A bump 30h old is excluded (outside 24h window); one 2h old is
counted. Uses timedelta offsets (never day-of-month arithmetic).
Kept src/metrics.py as-is (a6656d3 query is correct).
2026-10-18 03:46:12 -04:00
adlee-was-taken
8e8e612023 test: restore tests/test_metrics.py and move the window test
The last commit (a6656d3) rewrote unrelated parts of
tests/test_metrics.py (quota burn assertions,
expected_period_start, context messages). Restore the file to
origin/main's version.

The bump-count test (tool_error_bumps_by_model) with TTL gating
(30h excluded, 2h counted via timedelta offsets) lives in this
repo's escalation test file instead.
2026-10-18 03:45:29 -04:00
adlee-was-taken
a6656d3d75 perf: bound the tool-error bump query with the observed_at index 2026-10-18 03:39:55 -04:00
adlee-was-taken
8055c8dc2f fix: replace final em dash in test_tui_schema_drift for ASCII compliance 2026-10-18 02:58:10 -04:00
adlee-was-taken
ad113766f7 fix: replace em dashes in added lines for ASCII compliance (closes F2) 2026-10-18 02:56:28 -04:00
adlee-was-taken
99de89c203 docs: tool-error tier escalation in routing.md 2026-10-18 02:37:30 -04:00
adlee-was-taken
86f0c4411f feat: admin controls for all escalation scalars 2026-10-18 02:29:01 -04:00
adlee-was-taken
89a1c0b537 feat: tool-error bump warning in /metrics and admin decisions 2026-10-18 02:15:37 -04:00
adlee-was-taken
9352adc4a7 feat: escalation_reason column on route_decisions
Add escalation_reason TEXT to route_decisions table so bump_reason
from tool-error tier bumps is persisted. Wire it through
persist_route_decision, events.publish_decision, and the chat
completions endpoint. Add round-trip and bump tests. Update the
no-header snapshot fixture. Fix prefix_probe state leakage by
clearing the store before and after the conversation_wiring module.
2026-10-18 01:59:04 -04:00
adlee-was-taken
8068384340 fix: validate tool_error_bump config and tidy wiring 2026-10-18 01:41:19 -04:00
adlee-was-taken
864cd6f154 feat: implement tool error bump config and dispatcher wiring 2026-10-18 00:46:43 -04:00
adlee-was-taken
5b85f05b6f feat: tool_errors module counts trailing edit-tool errors 2026-10-18 00:40:42 -04:00