Skip to content

feat(tooldefer): the proxy answers Claude Code's ToolSearch: one search tool per request (#898) - #900

Merged
amiddavid merged 8 commits into
mainfrom
feat/client-search-b
Nov 4, 2026
Merged

amiddavid merged 8 commits into
mainfrom
feat/client-search-b

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #898 (step 2, Claude Code only). Design: #898 comment. Matrix: docs/tool-search-matrix.md.

Behavior change (needs a human's yes)

  • Who: ultrahigh users on a Claude model, when the request has Claude Code's own ToolSearch. New threads only.
  • Old: the proxy adds tool_search_tool_bm25 next to ToolSearch. Two search tools.
  • New: no server-side search. The model loads through ToolSearch. The proxy adds tool_reference blocks for its own deferred tools to Claude Code's select: result. One search tool.
  • Unchanged: no ToolSearch in the request: the server-side search stays. A live thread keeps its mode.
  • Off: toolfilter: {defer: off} or ENABLE_TOOL_SEARCH=false. The mode also turns itself off (see Disable).

Data dependence change

  • The toolfilter row in docs/data-dependence.md changes (data dependence goes up a little, still no stored customer text).
  • The feature now reads the text of a ToolSearch result in two places: the "No matching deferred tools found" text, and the "not loaded" / "no such tool" / "does not exist" error.
  • It keeps none of that text.
  • The thread record keeps only the call ids and the tool names the proxy added.
  • Decided by: David Amid, approved 2026-11-04

Summary

  • Every ToolSearch call goes to Claude Code as today. On the next request, the proxy appends tool_reference blocks for its own deferred tools to the tool_result. Claude Code's own result stays.
  • No held stream, no in-band round, no injected turn.
  • Only the exact select:Name1,Name2 form is read. Every other query passes through.

Facts from live probes (benchmark gateway, nonce per request)

  1. Input: {"query","max_results"} (default 5), from 78 real captures.
  2. (b) The API expands the appended tool_reference. Plain client ToolSearch, one defer_loading tool, no server-side search: 200, and the model called the tool. A text-only result did not expand.
  3. (a) Unknown name: select:<unknown> gives the text No matching deferred tools found. In select:Known,Unknown the unknown name is dropped without a note.
  4. Grammar Claude Code accepts: select: in any case (Select:), names split on ,, each trimmed (select:A, B works), capped at max_results. The proxy accepts the same.
  5. Description hash: one hash (88033eceb421f1c2) over 109 captures.

Disable, never switch

The proxy marks the hash of ToolSearch's description as disabled through Gate (ClientDisabled, DisableClient: same shape, TTL 24 h and caps as Break). It never falls back to another search tool.

Reason Trigger
unknown_description the hash is not on the verified list (knownDescHashes). The thread defers nothing
non_select_query_for_our_tool a query names a deferred tool of the proxy in a form other than select:
break a call to a deferred tool whose own result is an error that says "not loaded", "no such tool" or "does not exist". A direct call that worked is a use (direct_calls), not a break. A tool that tool_choice kept loaded never breaks
  • Who is affected: the tenant, for that hash, for 24 h.
  • What one break costs: the live thread stops deferring. tools changes once: one cache rewrite. New threads defer nothing until the mark expires.
  • How to clear the mark: there is no reset route. The mark ends after 24 h, and a restart of the proxy clears it.
  • New Claude Code version: run the probe, then add its hash to knownDescHashes.
  • Existing probe pattern: the old probe cannot mark a hash as passed (its key is the model and route). I added a second probe, with its own verdict key, for "the API accepts a proxy-written tool_reference for this model". The hash list covers the syntax.

For production monitoring

  • Metric: cg_tooldefer_client_disabled_total{reason="unknown_description"|"non_select_query_for_our_tool"|"break"}
  • /stats: tool_defer.client_search_disabled = {unknown_description, non_select_query_for_our_tool, break}
  • Log (warn): cg.tooldefer_client_search_disabled with reason, desc_hash (8 chars), session, thread. No query text.
  • Each counts once per tenant and hash per 24 h (a break counts each time).

What changed

  • tooldefer/toolsearch.go: AugmentSearches, selectNames, DescHash, UnloadedCall, client probe.
  • tooldefer/gate.go: disabled marks and counters. Record gets Client and Answers.
  • Apply: the mode choice, the disable paths. Rewrite adds no server-side search in the mode.
  • proxy/tooldefer.go, proxy/promexport.go: probe, log, /stats, metric.
  • Docs: docs/tool-search-matrix.md (new), one sentence in docs/reference/presets.md.

How it was tested

Box 2, fresh tar sync into an empty dir, foreground, -race: ./tooldefer/... ./apply/... ok; ./proxy/... ok (520 s).

Unit tests:

  • no server-side search with ToolSearch; it stays without it or with an unknown client probe
  • pure client query passes; select: of ours is appended; Select: A; mixed with the client's own (cap kept); error results untouched
  • keyword query passes; a non-select query naming our tool disables (live thread and new thread)
  • unknown description: nothing deferred, counted once
  • break: disables; a call after a good load does not
  • replay byte-identical on the next request and after a restart
  • live thread never changes mode; proxy end to end

Mutation check: reading the stored list is turned off. TestClientModeReplaysByteForByteAfterRestart fails. Restored.

Data dependence

See "Data dependence change" at the top. The toolfilter row in docs/data-dependence.md is extended. Storage: the thread record keeps each search call id and the tool names the proxy added. Nothing else is stored. Reading: the no-match text and the "not loaded" error text of a ToolSearch result, in the request only. Query text and result text are not kept.

Technical notes

  • Break detection: only a call to a deferred tool whose own result is a "not loaded" / "no such tool" / "does not exist" error. A direct call that worked is a use (direct_calls). A tool tool_choice kept loaded never breaks.
  • Ranking is not our concern now: the proxy never ranks. It only reads exact names.
  • Codex and the other paths are untouched.

Base

#897 has merged. This branch contains it (merged from main), and the matrix no longer says "after #897".

Open questions

  • Decided by the owner: a break is only a call whose own result is a "not loaded" error. A direct call that worked is a use.
  • Select: and spaces are accepted because Claude Code does. A change in that rule shows up as a miss, not as a disable.

🤖 Generated with Claude Code
EOF
python3 -I -c "
import json;print(json.dumps({'body':open('/tmp/client-search-b-body.md').read()}))" > /tmp/client-search-b-body.json
gh api -X PATCH repos/rossoctl/context-guru/pulls/900 --input /tmp/client-search-b-body.json --jq '.body[:80]'

…earch tool serves a request (#898)

On a Claude model with Claude Code's own ToolSearch, a new thread gets no
server-side search tool. The proxy replaces the result of a ToolSearch call
that touches a tool it deferred with tool_reference blocks, on the next
request. The answer is kept in the thread record by tool_use id and replayed
byte for byte. A second probe gates the mode. Without ToolSearch, the
server-side search stays.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
…sult; disable on a format change (#898)

On a Claude model with Claude Code's own ToolSearch, a new thread gets no
server-side search tool. Every ToolSearch call goes to Claude Code. On the
next request the proxy adds tool_reference blocks for its own deferred tools
to a select:A,B result, and replays the list byte for byte from the thread
record. A hash of the ToolSearch description gates the mode. An unknown hash,
a non-select query that names our tool, or a call to a tool no search
loaded disables the mode for that hash (cg_tooldefer_client_disabled_total).

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 4, 2026
Fill T1 to T4 with the metric, the /stats field and the log line from
PR #900 (open, not reviewed). Add how each reason counts, the disable
scope, today's known-good hash, and the log join T4 needs.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
Codex on gpt-5.5 declares its own tool_search. After #897 the proxy adds no
context_guru_tools to such a request and defers nothing on it. Our search is
only for a Responses client that declares no tool_search of its own.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 dec692db349c blocking

Verdict: blocking

Findings

  1. tooldefer/apply.go:253 — the ledger keeps counting a client-mode load as saved, and never counts its cost

    • What fails: a thread in client-search mode loads a deferred tool (the proxy writes a tool_reference into a ToolSearch result). From that request on, /stats and the dashboard net-saving panel report wrong dollars: DeferredTokens still counts the tool as saved, and LoadedTokens and WrongGuesses stay 0.
    • Proof: two halves.
      • The savings side weighs from the client's body: loaded := Loaded(r.Orig) (apply.go:253). But the client's next request carries Claude Code's own result, not our augmented one — we change only the bytes we send upstream. So Loaded(r.Orig) never sees a client-mode load, and weigh keeps the tool in DeferredTokens on every later request. The ledger's own model says this is wrong: ledger.go:67-69, "minus those of tools a search has already loaded in this transcript (those are paid inline again)". The API expands the reference on every request that carries it.
      • The cost side reads only server-side searches: deferLedger fills LoadedTokens and WrongGuesses from u.SearchLoaded and st.loaded (proxy/tooldefer.go:656-660), both parsed from server_tool_use / tool_search_tool_result blocks in the response. A client-mode response has none. o.Loads is used only for the history (noteSearchLoads, proxy/tooldefer.go:453-456), never for the ledger.
    • Fix: in client mode weigh from the augmented body (Loaded(out), or add o.Loads to the exclusion set), and pass o.Loads into deferLedger as the loaded names (loaded tokens, wrong guesses).
  2. tooldefer/toolsearch.go:190 — an errored search result still books the tools as used

    • What fails: Claude Code's ToolSearch returns an error or a shape the proxy does not know (for example the string "Error: boom"). The query was select:Workflow. The proxy writes no tool_reference (the default: continue at line 205), but it has already stored the answer and appended the names to a.Loads (lines 183-191). The host then calls noteSearchLoads, which records Workflow as used in the tool history. The model never saw the schema, yet the user's later sessions keep that tool loaded (never deferred again, 30-day retention).
    • Proof: trace AugmentSearches: rec.Answers[id] = names, a.Loads = append(a.Loads, names...), a.Answered++ all run before the result-shape switch; only the reference write is skipped by continue. The test TestClientModeAddsOnlyOurToolsToSelectQueries asserts the result text is untouched but does not check o.Loads, so the false booking passes unnoticed.
    • Fix: store the answer and book the loads only when the proxy actually writes a reference — that is, only for the noMatchText and all-refs-array shapes. For any other shape, leave the call unanswered (it will be re-tried on the next request, same pure function).
  3. docs/data-dependence.md:187 — the row was not updated for the new stored field

    • What fails: Record gains Answers (tool_use id → tool names, tooldefer/tooldefer.go:341), kept on disk under cg:tdf: for Claude Code threads. The toolfilter row describes the call-id record only "on GPT, GLM and Kimi" (#825). A reader who asks what deferral keeps for a Claude Code thread now gets an incomplete answer. CLAUDE.md makes this update mandatory for every PR that changes a feature's data dependence, and asks the row's "Decided by" to confirm it before merge.
    • Proof: the diff touches docs/reference/presets.md and adds docs/tool-search-matrix.md; docs/data-dependence.md is unchanged. The stored data changed: a new field, with call ids, on the Claude Code path the row does not cover. The feature also now reads tool_result text to decide behavior (the no-match text in AugmentSearches, "not loaded" / "no such tool" in UnloadedCall) — worth a plain-words note in the row.
    • Fix: extend the toolfilter row: the thread record now also keeps, for each ToolSearch call the proxy answered on a Claude Code thread, the call id and the tool names it added (#898). Have the row's "Decided by" confirm it on the PR.

Non-blocking

  • AddBacks now mixes two things: #825 add-backs (the tool returns to tools) and #898 client-mode loads (the tool stays deferred; a reference is written). The /stats text for add_backs says "tools a search added back", which no longer covers both (proxy/tooldefer.go:455, gate.go).
  • A direct call to a deferred tool, which the API accepts (see the known limits on Rebuild, tooldefer.go:417-419), counts as a break in client mode: it disables the mode for the tenant and hash for 24 h. The matrix documents this as the design, and it fails toward not deferring, but the server-side mode has no such false positive.
  • ListTokens counts the server names-list head (apply.go:267) while client mode sends ClientToolNamesList, a different text. A few tokens per request.
  • DisableClient bypasses the live-mark check for ReasonBreak (gate.go:432), so break counts once per breaking thread. The metric help text says "once per tenant and hash per 24 h". Several live threads breaking after one format change each add 1.
  • Past maxAnswers (256), answers are recomputed on every request and the loads re-booked each time (AddBacks, history Observe). Rare, but the counters inflate.
  • AddKnownDescHash writes the package-level knownDescHashes map with no lock. Fine while only tests call it, but the function is exported.

What I checked

  • The full diff of all three commits, line by line, and the code around each change: tooldefer/apply.go, rewrite.go, tooldefer.go, toolsearch.go, gate.go, probe.go, proxy/tooldefer.go, promexport.go.
  • The systems the change sits in: the ledger (tooldefer/ledger.go), the #825 in-band search (tooldefer/clientsearch.go), the prober, the store keys, and the data-dependence doc.
  • The fail-open paths: unknown description hash, non-select query, break, client_search_gone, AugmentSearches error shapes, the panic recover in Apply. Each sends the original request. The break path changes tools once, as documented.
  • Byte stability of the answered round within a thread and across a restart (replay from Record.Answers), and the re-decide path for a record lost mid-thread (a client thread has no hasSearchTurn, so it re-decides; loads in the transcript count as uses, so loaded tools stay loaded).
  • The probe: ClientProbeBody shape, its verdict, the route-suffixed probe key, and the beta handling in startProbe.
  • Tests added in tooldefer/toolsearch_test.go and proxy/tooldefer_test.go: coverage of the select-only rule, the three disable reasons, the replay, the live-thread stickiness, and the end-to-end path.
  • Docs: presets.md, the new tool-search-matrix.md (claims match the code), docs/design.md.
  • No Go builds or tests were run (not approved; Go is not on this machine).

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 dec692db349c blocking

Verdict: blocking

Findings

  1. tooldefer/toolsearch.go:286 — a legal call to a deferred tool reads as a break and disables client search for the whole tenant, for 24 h

    • What fails: the model calls a deferred tool with no tool_reference in the transcript, and the call is legal. Two ways this happens: (a) the model calls the tool directly — tooldefer.go:417 says the API accepts that ("a tool the model called directly while it was deferred, with no search (the API accepts that)"); (b) an earlier request of the same thread forced the tool with tool_choice, so rewrite kept it loaded for that request (tooldefer/rewrite.go:55), the model called it, and the next request defers it again. In both cases UnloadedCall sets broke on !loaded[n] alone, whatever the call's outcome.
    • Proof: trace for (b): request N carries tool_choice: {type: tool, name: Workflow} → rewrite calls withoutName(set, "Workflow") → Workflow goes out loaded → the model calls it → request N+1 defers Workflow again → UnloadedCall (apply.go:237) sees the tool_use with no load → ReasonBreak → Gate.DisableClient marks the description hash for the tenant, 24 h (apply.go:246, gate.go:218), and Save(..., Record{}) un-defers the thread, one cache rewrite. In server-side mode the same two events are harmless. Neither case has a test; TestClientModeBreakDisables covers only the true break.
    • Fix: count a break only when the call's own tool_result is an error that names the tool as not loaded (the second half of the doc's trigger), or when the call has no result yet and no load anywhere. A call with a successful result means the API accepted it: book it as a use, not a break. Also record the tools a tool_choice request kept loaded, so their calls never count as breaks.
  2. docs/tool-search-matrix.md:13 — the matrix states, as current behavior, a guard that is not in this PR or in its base

    • What fails: the Codex gpt-5.5 row says "The proxy adds no context_guru_tools. Codex's loads count as uses in the history", and line 16 says "the proxy checks the tools, not the model". No such check exists at this head: NativeSearch/NativeLoads live in commit f6b2a4f0 on the unmerged branch feat/codex-native-876 (#876, #897). I verified with git merge-base --is-ancestor: that commit is in neither the base (47de51a9) nor the head. At this head, ApplySearch → rewriteSearch (tooldefer/clientsearch.go:426) still adds context_guru_tools to a Codex request and removes deferred tools — the very behavior that branch's message says draws a 400 from OpenAI ("OpenAI refuses a second tool_search with a 400").
    • Proof: grep -rn '"tool_search' --include='*.go' over the tree finds no tools check outside the tool_search_tool_bm25 names; rewriteSearch skips only requests that already hold our own ClientSearchName.
    • Fix: mark both rows as pending #876/#897, the way the gpt-5.6 row says "Not built yet". Or merge that branch first. As written, an operator reads the matrix and believes Codex requests are left alone; the code at this head changes them.
  3. proxy/tooldefer.go:455 — client-search loads inflate add_backs, whose documented meaning is "tools added back to tools"

    • What fails: noteSearchLoads (proxy/tooldefer.go:504) does AddBacks.Add(len(names)). The new call site feeds it client-search Loads. A client-search load adds a tool_reference to a message; it adds no tool back to tools and causes no cache miss on tools. The /stats comment (proxy/tooldefer.go:744) still defines add_backs as "#825 ... tools it added back (one cache miss on tools each)". The counter now mixes two different events.
    • Proof: apply.go:251 sets o.Loads from AugmentSearches, which only edits messages (toolsearch.go:215); tools is untouched after rewrite.
    • Fix: count client-search loads in their own counter (or in wrong_guesses's input, as the comment says the ledger already does for loaded tools), and keep add_backs for the #825 path.

Non-blocking

  • Gate.DisableClient (gate.go:224) skips the once-per-live-mark check for ReasonBreak, so every break counts. The Prometheus help text (promexport.go:589) and the /stats comment say "Each counts once per tenant and hash per 24 h". Pick one.
  • docs/data-dependence.md's toolfilter row (line 187) was not updated for the new Answers field: tool names by tool_use id, kept in the thread record. Same data class (metadata), but the row lists the record's contents in detail and CLAUDE.md asks for it.
  • The cg.tooldefer_probe log line (proxy/tooldefer.go:583) is identical for the server probe and the client probe: both log the trimmed route. The two cannot be told apart in the log.
  • AugmentSearches books a.Loads (a use in the history) even when it could not write the answer — the result was an error or an unknown shape (toolsearch.go:204). The tool then counts as used though nothing loaded it.

What I checked

  • Read the full diff of all three commits and the whole of every changed file: tooldefer/apply.go, gate.go, probe.go, rewrite.go, tooldefer.go, toolsearch.go, both test files, proxy/tooldefer.go, proxy/tooldefer_test.go, promexport.go, both docs.
  • Traced the client-mode decision, the rewrite, the augmentation, the replay and the three disable paths line by line. Checked the fail-open paths: on Bad, break and panic the original body goes out.
  • Checked byte stability of the replayed answers, the max_results cap, the select: parsing, and the restart path against the unit tests.
  • Verified the Codex claim in the new doc against the tree and the git history (f6b2a4f0 not an ancestor of base or head).
  • Checked boundaries: the new logic lives in tooldefer, the host wiring in proxy, the probe goes through dispatch. No violation found.
  • Did not run builds or tests (not approved). Did not read the PR conversation or the other review, per round 1.

…898)

- A break is a deferred tool's own error that says it is not loaded. A direct
  call that worked is a use (direct_calls). A tool_choice tool never breaks.
- Client-mode loads leave DeferredTokens and count as loaded in the ledger.
- An errored or unknown result books nothing.
- client_loads is its own counter; add_backs stays for the #825 path.
- The list weight in client mode is the client list. Probe logs say server or client.
- Matrix rows marked "after #897"; data-dependence toolfilter row extended.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes are in e7302b79. One reply per finding.

Reviewer 1

  1. Break rule: fixed. A break is now only a deferred tool's own error result that says "not loaded", "no such tool" or "does not exist". A direct call that worked is a use, counted in direct_calls. A tool tool_choice forced never breaks. Tests: the true break, a direct call, a call after tool_choice, a good load.
  2. Matrix: both rows now say "after fix(tooldefer): never add our search to a Responses request that has its own (#876) #897". Merge fix(tooldefer): never add our search to a Responses request that has its own (#876) #897 first.
  3. add_backs: kept for the feat(toolfilter): our own tool search for providers without defer_loading (GPT, GLM, Kimi) #825 path only. Client-mode loads count in client_loads. The /stats comment is updated.

Reviewer 2

  1. Ledger: fixed. Client-mode loads (the references in the augmented body) leave DeferredTokens. o.Loads go into deferLedger as loaded names. Test: TestClientModeWeighsTheLoad (deferred tokens drop).
  2. Error result: fixed. The answer is stored and booked only when the proxy really writes a reference. Test: TestClientModeErrorResultBooksNothing checks Loads, Answered, the result bytes, and that the call can be answered later.
  3. Data dependence: the toolfilter row is extended, in plain words, including the two places where the feature reads result text. The row's "Decided by" must confirm.
  • Non-blocking: ListTokens in client mode now counts the client list. add_backs and the counting rule are covered above.
  • Not changed: past maxAnswers (256) the answers are recomputed and loads re-booked each time. This is rare. AddKnownDescHash has no lock. It is for tests only.

non_select_query_for_our_tool and the live thread. It stops deferring on the live thread, like break. The record is set to "nothing", tools changes once, and the thread pays one cache rewrite. unknown_description is decided at thread start and costs no rewrite.

Tests (box 2, -race): ./tooldefer/... ./apply/... ok; ./proxy/... ok (515 s); gofmt and vet clean. Mutation: a direct call counted as a break makes TestClientModeBreakRule fail. Restored.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Nov 4, 2026
Rewrite K1 to K6 for the per-wait ping plan (#867) with a v0.6.6
baseline, add K7 (no sweep question in a tool wait) and K8 (no ping
when done), close G1 with wake_cause. Add breaches B5 to B7. Update T4
and the #900 signals. Add the expand-rate section E1 to E3 and gap G9
(no per-component expand count).

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Head 937a0724 merges origin/main (with #897, dd3cfa6f) into the branch. Nothing else changed in the code.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 937a0724a748 approve

Verdict: approve

Findings

None. All six round-1 findings (mine and reviewer 1's) are fixed. The fixes are correct; I found no new defect in them. Details under "What I checked".

Round-1 findings, resolved

Mine:

  1. Ledger blind to client-mode loads — fixed. The savings side now merges Loaded(out) into the loaded set in client mode (apply.go:264-270), so a tool the references load leaves DeferredTokens on the request that writes them and on every replay. The cost side appends di.outcome.Loads to the ledger's loaded names (proxy/tooldefer.go:684), so LoadedTokens and WrongGuesses see the load once, at the request that writes it — the same once-only semantics as a server-side search. TestClientModeWeighsTheLoad covers the weight drop and the client list.
  2. Errored search result booked a use — fixed. AugmentSearches now checks the result shape first and continues on an error or unknown shape before anything is stored or booked (toolsearch.go:178-191). The answer is stored and a.Loads booked only when a reference is really written, and only for the names actually added (toolsearch.go:206-218). TestClientModeErrorResultBooksNothing checks Loads, Answered, the bytes, and that the call stays answerable later. I also re-checked the replay path: the stored set is add, and the replay writes the same references, so the bytes stay stable.
  3. data-dependence row — fixed. The toolfilter row now names the #898 record (each search call id and the names the proxy added) and the two places where the feature reads result text, in plain words (docs/data-dependence.md:187). The row's deferral decider (David Amid, #485) is the PR author, so the confirmation is the author's own commit; if the team wants it explicit, one line on the PR closes it.

Reviewer 1's (I checked each myself):

  1. Break rule — fixed, and I verified the new rule end to end. ReadCalls (toolsearch.go:292-320) sets broke only when a deferred tool's own error result says "not loaded", "no such tool" or "does not exist", and removes that call from the direct set. A call no search loaded that worked is returned as direct and booked as a use (direct_calls, apply.go:241-250, proxy/tooldefer.go:458-461). A tool tool_choice forces suppresses the break for that request (forcedAny, apply.go:246, 294-299); the next unforced request still fires it, so nothing is lost. TestClientModeBreakRule covers the true break, the direct call, the forced call and the good load.
  2. Matrix rows stated unmerged behavior — fixed by the merge. #897 (dd3cfa6f) is now in main and in this branch (527fdf59). NativeSearch/NativeLoads are in the tree, ApplySearch returns native_search and defers nothing, and the matrix rows match the code. I checked the branch footprint against the new base: 13 files, all this PR's; no #897 change is reverted, and the presets.md conflict keeps both the #898 and the #876 sentences.
  3. add_backs mixing — fixed. Client-mode loads go to noteClientLoads and the new client_loads counter; add_backs stays for the #825 path (proxy/tooldefer.go:455-461, 518-524; gate.go). The /stats comment and the matrix name the new fields.

Declined non-blocking items, with reasons I accept:

  • Past maxAnswers, re-booking per request. The recompute is a pure function of the transcript, the history Observe is idempotent per session; only the client_loads counter can inflate, past 256 answered searches in one thread. Rare, stats-only. Accepted.
  • AddKnownDescHash without a lock. Test-only writer, read-only in production. Accepted.

Non-blocking

  • direct_calls counts per request that carries the call, not once per call (the code comment at proxy/tooldefer.go:459 says so; the /stats text does not). A thread with one direct call adds 1 per request. Say "per request" in the /stats comment, or dedupe per thread, as client_loads does.
  • The data-dependence row names two error phrases ("not loaded", "does not exist"); the code matches three (no such tool too, toolsearch.go:308). One word in the row.
  • ListTokens in client mode now counts the client list (apply.go:285-287). The first tokens.Count(NamesList(names)) call is dead work there; harmless.

What I checked

  • Last review: round 1, dec692d, 2026-11-04T17:20:08Z
  • New commits read: 4 — dd3cfa6f feat(tooldefer): keep a client's own tool_search on Responses (#897, arrived via the merge), e7302b79 fix(tooldefer): round 1 of #900, 527fdf59 merge origin/main, 937a0724 docs: resolve the presets.md merge conflict
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files; the inline file is empty)
  • New items since my last review, and what I did about each:
    • Reviewer 1's round-1 review (17:22): read in full; verified each of their three findings against the fix commit myself (traces above), not just the author's reply.
    • Author comment (17:37, fix summary): checked every claim against the code — break rule, ledger, counters, docs, probe log kind, tests.
    • Author comment (17:48, merge note): verified the merge — footprint vs the new base is 13 files, all this PR's; the presets.md conflict keeps both features' sentences; the matrix no longer says "after #897" and its rows match the merged code.
  • The fix commit line by line: ReadCalls (break vs direct, the delete on break, the dedup by tool), forcedAny, the AugmentSearches restructure (shape check first, store-and-book only on a real write, the known replay path, byte stability of the replayed round), the weigh fix (Loaded(out) merge), the client list weight, noteClientLoads/DirectCalls booking, the ledger append, the /stats and Prometheus text.
  • The #897 code that arrived with the merge (NativeSearch, NativeLoads, the native_search branch, the native-loads history booking, both test files): read as new code; no defect found.
  • Fail-open paths re-checked after the restructure: Bad, break, error shape, and the sjson error path each return the un-augmented body; the break path still changes tools once, as documented.
  • No Go builds or tests were run (not approved; Go is not on this machine). The author's box-2 -race runs and the mutation check are reported in the PR comments; I read them but did not re-run them.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.317 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 937a0724a748 approve

Verdict: approve

No new blocking finding. All 6 findings from round 1 (3 mine, 3 reviewer 2's) are fixed and verified in the code.

Earlier findings

Mine, round 1

  1. Break false positive (toolsearch.go:286) — fixed in e7302b79. Verified:
    • ReadCalls (toolsearch.go:292) sets broke only when the call's own tool_result has is_error and its text says "not loaded", "no such tool" or "does not exist".
    • A worked direct call goes to o.Direct and the direct_calls counter, not to the break.
    • forcedAny (apply.go:296) keeps a tool_choice-forced tool from breaking.
    • Tests cover the true break, the direct call, the call after tool_choice, and the good load (TestClientModeBreakRule).
  2. Matrix rows ahead of unmerged code (docs/tool-search-matrix.md:13) — fixed. The base is now dd3cfa6f, which holds #897. NativeSearch and NativeLoads are in the tree (tooldefer/clientsearch.go:712, 729). The rows no longer say "after #897". The claims match the code.
  3. add_backs conflation (proxy/tooldefer.go:455) — fixed. Client-mode loads count in the new client_loads counter (noteClientLoads). add_backs stays with the #825 path. The /stats comment and the Prometheus help text state the split.

Reviewer 2, round 1 (verified on my own, not repeated as findings)

  1. Ledger — fixed. weigh merges Loaded(out) when rec.Client (apply.go:264-270), so a client-mode load leaves DeferredTokens. deferLedger appends di.outcome.Loads as loaded names. ListTokens counts ClientToolNamesList in client mode (apply.go:285-287). Test: TestClientModeWeighsTheLoad.
  2. Errored result books tools — fixed. AugmentSearches checks the result shape first (toolsearch.go:181-191): only the no-match text or an all-refs array is extended; any other shape continues with nothing stored or booked. The answer is kept only when a reference is really written (toolsearch.go:206-218). Test: TestClientModeErrorResultBooksNothing.
  3. Data-dependence row — fixed. The toolfilter row now names the answers record and the two places the feature reads result text, in plain words.

Author's two "not changed" calls — accepted. Both are test-only concerns (maxAnswers recompute past 256; AddKnownDescHash without a lock, exported for tests).

Non-blocking

  • forcedAny reads only this request's tool_choice. A break on one tool in the same request that forces another deferred tool goes unseen. The next request without the force catches it. Detection is delayed one turn at most.
  • The data-dependence row names the error texts "not loaded" or "does not exist". ReadCalls also matches "no such tool" (toolsearch.go:308). One phrase missing in the doc.
  • applyClientSearch re-books NativeLoads on every request that carries tool_search_output items. Booking is idempotent, so only the history write repeats.

What I checked

  • Last review: round 1, dec692db349c22b26ccf6a6038b8cd5d55a69737, 2026-11-04T17:22:04Z.
  • New commits read: 4 — dd3cfa6f feat(tooldefer): keep a client's own tool_search on Responses and defer nothing there (#876) (#897); e7302b79 fix(tooldefer): round 1 of #900: break rule, ledger, counters, docs (#898); 527fdf59 merge origin/main into feat/client-search-b; 937a0724 docs: resolve the presets.md merge conflict.
  • Read in full: 2 reviews, 2 comments, 0 inline comments.
  • New items since my last review: the 4 commits above, the author's two replies, and the merge of #897 into the base. For each I read the full diff dec692db..HEAD (640 lines) and the final state of the changed files; for each round-1 finding I traced the fix in the code; for the merge I checked that presets.md keeps both the #898 row text and #897's sentence, and that no #897 file was reverted (git diff --stat dd3cfa6f..HEAD: 13 files, all from this PR).
  • The new code in e7302b79 I reviewed as a first review: ReadCalls, forcedAny, the AugmentSearches rework, the ledger merge, the new counters and their help texts, and the tests. No new blocking defect.
  • No Go builds or tests were run (not approved; Go is not on this machine). The author reports them green on box 2 with -race.

mkdocs build --strict fails when a page is not in nav.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Head 2166e85d only adds docs/tool-search-matrix.md to the nav of mkdocs.yml (under Components, after "Choose a preset"). It fixes the Docs job (mkdocs build --strict). No code changes.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Head de431b74 merges origin/main after the #768 revert (38c00e13). No other change.

  • docs/data-dependence.md: checked by hand. Only the toolfilter row differs from main. Every other row is main's.
  • git diff --stat origin/main: 14 files, all from this PR (13 before, plus mkdocs.yml). No other file differs.
  • Box 2, -race, fresh sync: ./tooldefer/... ./apply/... ok; ./proxy/... ok (511 s); gofmt and vet clean.
  • ./dash/... (the merge touched dash/): one test failed in the full run, TestToolReportHidesTheStaleServerToolRows, with database is locked (SQLITE_BUSY). Run alone with -count=3, it passes on this branch and on an unmodified origin/main. This PR does not touch dash/. I read it as a load flake on the shared box, and did not rerun the full ./dash/....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant