perf(hunter): cacheable message order; adaptive step budget in the sink verifier

Token efficiency, measured on 180 verified pgAdmin candidates: stage 2 costs
$0.0139 per candidate, 90% of the spend, because the conversation is re-sent on
every turn and grows with each tool result.

- Context files now precede the question in the hunter's first message. DeepSeek
  bills a cached prefix at 1/30 of a fresh one, by prefix; with the question first,
  every candidate asked about the same file (about 5 per file) broke the prefix on
  its first line and paid for the file again. A test pins the order.
- The verifier runs each candidate at 3 steps and repeats it once at 6 only when
  the hunt spent every step on tool calls without a verdict. On the seven declared
  v2 sites, 3 steps found 5 and 8 steps found 6; most candidates conclude in 3.
- Per-candidate token usage (prompt, cached, completion, calls) and escalation
  are recorded, and each case reports its cache share, so the next efficiency
  decision is made on numbers.

Validation on the 180 pgAdmin candidates plus the 22 known sites (about $1)
waits for account credit: DeepSeek returns 402 at the moment.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EmM1j46qgKMh3zqD1QMwEo
This commit is contained in:
Marius Ciepluch
2026-09-29 09:52:23 +02:00
co-authored by Claude Fable 5.1
parent 66fa08cdd0
commit 041d87199a
3 changed files with 68 additions and 11 deletions
+5 -1
View File
@@ -421,14 +421,18 @@ def _tool_schemas(names: Sequence[str] | None) -> list[dict[str, object]]:
def _user_message(root: Path, hotspots: Sequence[Hotspot], user_prompt: str | None, context_files: Sequence[str], max_chars: int) -> str:
# Context files FIRST, the question LAST. DeepSeek bills a cached prefix at 1/30 of a fresh one, and the cache
# is by prefix: with the question first, every candidate in the same file broke the prefix at its first
# line and the file was paid for again. The file is the stable part across the questions asked about it.
body = user_prompt if user_prompt is not None else _hotspot_prompt(hotspots)
parts = [body]
parts = []
for relative in context_files:
try:
text = read_file(root, relative, max_chars=max_chars)
except (PathEscapesRepo, OSError):
continue
parts.append(f"--- {relative}\n{text}")
parts.append(body)
return "\n\n".join(parts)