A throttled read retried after its cooldown is the correct move, but the
exact-args failure streak counted it like any identical failure: from the
second attempt the result carried "This looks like a loop; ... change strategy
instead of retrying it unchanged", steering the model away from a valid retry
(seen with Slack MCP rate limits behind an enterprise connector).
A failed result that says it was throttled (a retry_after field, a 429 status,
or rate-limit wording in its error) no longer advances the exact-args streak.
It still counts toward same_tool_failure, so an endpoint that never recovers is
warned at 3 and halted at 8 on unattended platforms, as before.
Follow-up to the cherry-picked top-level-shape rule. Once a JSON object no
longer reaches the substring scan, two failure shapes that only the scan
caught would go silent:
- {"status": "failed"} / {"status": "error"} with no top-level error key
(pinned by test_real_error_and_failed_markers_still_flag on main).
- A "results" batch where EVERY item carries an error: delegate_task with
all children interrupted, a connector batch with every call refused.
shape_failure_error in tool_result_classification covers both and is used
by _detect_tool_failure and classify_tool_failure alike. "timeout" stays out
of the failed statuses because process(wait) returns it for a running job.
Audit against 200,000 real tool results from a live state.db: zero results
newly flagged as failed. The results that stop flagging are partial batches
(some items succeeded) and exit-0 execute_code runs whose nested tool_errors
held one failed inner call; all-failed batches still flag.
Tests trimmed to one invariant covering both classifiers (nested error is
data; top-level error, all-failed batch, and plain-text failures still flag).
has_failure_marker cut the text at 500 chars before testing whether the
error value was empty, so a successful result whose `"error": null` began
just before the cut read as `"error": nu` and was flagged failed in both
classifiers (Greptile finding on this PR). The marker must still START in
the first 500 chars, but its value is now read past the cut. The regex is
case-insensitive instead of lowercasing the slice.
Boundary case added to the existing invariant test; red on the previous
head.
_detect_tool_failure and its guardrail mirror classify_tool_failure fell back
to a bare substring test: any quoted "error" or "failed" in the first 500
chars marked the call failed. Successful payloads carry those keys with empty
values (web_extract returns "error": null per URL; batch results carry
"failed": 0), so every successful web_extract showed as failed in the CLI and
counted toward the guardrail's repeated-failure streak.
The shared has_failure_marker (agent/tool_result_classification.py) ignores the
key when its value is null/false/0/""/[]/{}; a non-empty value, a "failed"
status string, or a body starting with Error still flags. Both classifiers use
it, so the CLI tag and the guardrail stay in agreement.
The salvaged commit adds the `guardrail_refusal` marker to the read-dedup block
and exempts it in `classify_tool_failure`. That classifier is only the fallback:
the executor (`agent/tool_executor.py::_commit_tool_result`) passes
`failed=_detect_tool_failure(...)` from `agent/display.py` into
`after_call`, so on the real path the refusal was still counted and the
escalation to `repeated_exact_failure_block` still fired (live probe: block at
call 8 of an identical read after 5 refusals, on the salvaged head as on main).
- `agent/tool_result_classification.py`: `GUARDRAIL_REFUSAL_KEY` +
`is_guardrail_refusal()` so the marker has one definition and both
classifiers share the predicate.
- `agent/display.py::_detect_tool_failure`: exempt refusals (the live seam).
- `tools/file_tools.py`: the two sibling loop refusals -- the consecutive-read
BLOCK in `read_file_tool` and the repeated-search BLOCK in `search_tool` --
carry the same marker; they are emitted via `tool_error` too and escalated
the same way.
- Tests trimmed to two invariants covering all three refusals on both
classifiers, plus the negative (a genuine error still counts; a non-boolean
marker is ignored).
Approval-denied write blocks (`file_tools_write_guards`) deliberately keep
counting: a user's denial retried unchanged is exactly the loop the streak
exists to stop.