fix(hunter): bound every tool result; show the provider's reason for an HTTP error

FUXA failed every hunt with HTTP 400, and neither run could say why. The client
discarded the response body. With the body shown, the reason was "This model's
maximum context length...": FUXA ships minified bundles whose single lines run to
megabytes, and grep_repo returned a matched line whole.

- grep_repo and find_refs quote a matched line (240 characters), never the whole
  line.
- Every tool result is capped at 16 x max_chars, with a truncation marker.
- OpenRouterChatClient errors carry the provider's response body (first 500
  characters). That would also have exposed the rejected model id in one call
  instead of eighteen days.

After the fix, FUXA candidates verify normally at $0.004-0.013 each. A test covers
the megabyte-line case.

verify_sinks.py: skip futures cancelled at the spend ceiling instead of reading
them (the run crashed with CancelledError).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
Marius Ciepluch
2026-09-28 20:15:14 +02:00
co-authored by Claude Opus 5.5
parent 3ffb8b4c54
commit 8794884a64
5 changed files with 32 additions and 4 deletions
+10 -1
View File
@@ -114,7 +114,16 @@ class OpenRouterChatClient:
try:
return call_with_retry(_do, attempts=self.max_attempts, base_delay=self.retry_base_delay)
except (urllib.error.URLError, TimeoutError, http.client.HTTPException, json.JSONDecodeError) as exc:
raise OpenRouterError(f"OpenRouter chat request failed: {type(exc).__name__}: {exc}") from exc
# The provider's own reason is in the body. Without it a 400 said nothing: DeepSeek's "the supported
# model names are ..." cost eighteen days of silently failed calls, and a case whose every request was
# rejected could not be diagnosed at all.
detail = ""
if isinstance(exc, urllib.error.HTTPError):
try:
detail = " -- " + exc.read().decode("utf-8", errors="replace")[:500]
except Exception: # noqa: BLE001 -- a body we cannot read is still an error with a status
detail = ""
raise OpenRouterError(f"OpenRouter chat request failed: {type(exc).__name__}: {exc}{detail}") from exc
def complete_json(self, *, model: str, messages: list[dict[str, str]], timeout_seconds: int = 60) -> object:
message = self.complete_chat(model=model, messages=messages, timeout_seconds=timeout_seconds)