Repository navigation
feat(toolfilter): auto mode with a session-fixed set and a restore tool (#434) - #449
OsherElhadad wants to merge 3 commits into
Conversation
|
Reviewer: CHANGES REQUESTED (one blocking defect). Full go test ./... passes on this branch (32 packages ok, no failures); CI build-test pending when I finished. Verified OK:
BLOCKING: the stored record is per SESSION but a session carries several threads with different tool lists (subagents). Once the main thread has decided, a subagent's first request goes through the fixed-set branch, which (a) appends a stub listing every tool the MAIN thread hid, including tools this subagent was never given, and (b) on a restore, RestoreTools rebuilds the whole tools array from the main thread's snapshot (rec.Tools). Repro (apply test helpers): main body decides and hides mcp__a__one, mcp__a__two, Artifact; a subagent request with tools [Read, Artifact] then gets tools=Read,context_guru_tools with a stub naming mcp__a__one and mcp__a__two; calling the stub for mcp__a__one returns tools=Bash,Read,mcp__a__one,context_guru_tools, i.e. the subagent gains Bash and a hidden MCP tool that its allowlist excluded. Restricted subagent tool sets are a policy boundary, so the stub and any restore must be limited to names actually removed from THIS request's body, and RestoreTools must edit the request's own tools array (re-insert only the requested names, in their original relative position) instead of rebuilding from the snapshot. Add a test with a narrower subagent tool set (no extra tools declared, stub lists only its own removals, restore re-adds only those). Non-blocking:
|
|
Fixed in the latest push. The stub now carries an enum of the tools removed from that request's own body, and RestoreTools reads that enum and re-inserts only the requested names into the request's own tools array, after the nearest preceding tool of the stored snapshot that is present (original relative order). It never rebuilds from the main-thread snapshot, so a subagent cannot gain a tool its allowlist excluded. Added TestAutoSubagentThreadIsNeverWidened with your repro (narrower subagent tool set); it fails on the previous commit (stub leaked the main thread's hidden tools) and passes now. The three non-blocking notes are documented in docs/components/reformat.md and the file header. Full go test ./... passes. |
|
Reviewer: approved after re-review (default-off feature), with one non-blocking caveat. CI all pass; go test ./apply ./proxy ./dash ./components/... ./store green; gofmt clean. Attacks tried (apply-level, same helpers as the tests):
Caveat (non-blocking, please document or fix later): Restored is stored per SESSION. In the repro, after the subagent restored Artifact, the main thread's next (warm) request came out with Artifact declared again (Bash,Read,Artifact,context_guru_tools), i.e. a subagent's restore rewrites the main thread's prefix once. That contradicts 'a warm prefix is never changed' for multi-thread sessions and costs a full-prefix write on a potentially large main context. Track restores per thread (e.g. keyed by the request's tool-name set) or state the cross-thread cost in docs/components/reformat.md. Minor: the restored definition comes from the main thread's snapshot, not the subagent's own declaration of the same name. |
|
Fixed: removed/restored state is now per thread (keyed by the thread's own tool-name set; the session record only holds the name set the first thread decided on). A restore only touches the thread that asked, and uses that thread's own stored declaration. Added TestAutoSubagentRestoreLeavesMainThreadByteIdentical: after a subagent restores Artifact, the main thread's next warm request has byte-identical tools, and the subagent keeps its restore. Full go test ./... passes. |
|
Reviewer: re-approved after the per-thread change (label stays). CI all pass; go test ./apply ./proxy ./components/... ./store green; gofmt clean. Mutation check: with apply/toolauto.go from the previous commit, TestAutoSubagentRestoreLeavesMainThreadByteIdentical FAILS (main thread tools changed from Bash,Read,context_guru_tools to Bash,Read,Artifact,context_guru_tools); with the new code it passes. Probes (apply level):
Non-blocking: in that mid-session-change case the thread's earlier restores are not carried over (m3 came back without the previously restored Artifact), so the model must call the stub again for a tool it was already using. Inherit the restored names from the old key when the new key's tool set is a superset/subset of it, or note the behaviour in the docs. |
OsherElhadad
left a comment
There was a problem hiding this comment.
Review: REQUEST CHANGES at 95d0810. The code is fine; only the PR text needs changing. (Posted as a comment: GitHub does not let the author account request changes.)
Verified on a local merge with current main (clean merge):
auto_removeis off by default and Anthropic-only.- Removing the warm/cold gate fails TestAutoWarmUndecidedSessionUntouchedColdDecides.
- Discarding the stored per-session set, so it is recomputed every turn, fails TestAutoFirstTurnRemovesAndFixesSet, TestAutoRestoreIsOneRewriteThenStable and TestAutoSubagentThreadIsNeverWidened. So the set is fixed for the session, and a restore costs one rewrite and is then stable.
context_guru_*tools are never removed.gofmtandgo vetare clean. TheapplyAuto/Tool,proxyAuto/ToolFilter anddashAuto/Suggest tests pass, and CI is green. All 3 commits are signed off with no AI attribution.
Blocking, PR text only: the Live evidence section publishes controlled-run results: token counts, the cost percentages for both arms, and the restore penalty. Under the repo's publication rule those go to the private research repo. Replace them with a qualitative line, for example "Live check: hidden tools were removed at session start; when one was needed the model restored it through context_guru_tools and finished the task". No code change is needed.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-check: APPROVE at 95d0810. The PR body's Live evidence section is now qualitative, with no token counts or cost percentages. The remaining numbers are the product's own suggestion rule (sessions and days), which is fine. The code is unchanged since the earlier review. This approval covers 95d0810.
Adds `toolfilter.auto_remove` (default off, Anthropic dialect). Tools declared in >= 5 sessions over >= 7 days with no recorded call are removed at session start or the first proven-cold request; the set is stored and applied unchanged for the rest of the session so warm prefixes never change. A `context_guru_tools` stub lists the hidden tools. When the model calls it the proxy answers in band and re-declares them on that continuation (one prefix rewrite, byte-identical on the client's next request). Never removes context_guru_* tools, tools already called, tools named in the system prompt, or a forced tool_choice tool. Never-worse guard: removed tokens must be at least 2x the stub's tokens. Signed-off-by: Osher-Elhadad <[email protected]>
… own tool list A session can carry subagent threads with narrower tool lists. The stub now names, and RestoreTools re-inserts, only tools removed from that request's own tools (the stub carries an enum of them); a restricted thread is never widened. Documents the pending-call, prose/tool_choice and co-called-stub caveats. Signed-off-by: Osher-Elhadad <[email protected]>
A subagent's restore no longer re-declares the tool on the main thread's next warm request. Each thread (keyed by its own tool-name set) keeps its own declarations, removed set and restores; restore uses the requesting thread's own declaration. Signed-off-by: Osher-Elhadad <[email protected]>
95d0810 to
425c87c
Compare
Refs #434. Default off (
toolfilter.auto_remove: true), Anthropic dialect only.What
Trace.ColdCache). The removed set is stored (pinned store key) and applied unchanged for the rest of the session; a warm session is never touched.context_guru_*, tools already called in the transcript, tools named in the system prompt (existing prose gate), a forcedtool_choicetool; a non-autotool_choiceskips the decision.context_guru_toolsstub lists hidden names plus a clipped one-line description. A call is answered in band (same loop as expand); the tools are re-declared on that continuation in original positions with the stub re-rendered, and the client's next request reproduces the same bytes (one prefix rewrite per restore, no second one). A stub call co-called with a client tool reaches the client; the restore is then picked up from the transcript on the next request.Live check (controlled, small, one box, real
claude -pvia a separate proxy)context_guru_tools, the tool was re-declared, and it finished with the correct answer in every run. The restore costs one prefix rewrite; the comparison arm was warm, so any penalty seen is an upper bound.Tests: apply (first-turn removal, set fixed under changing history, warm untouched / cold decides, never-remove rules, guard, restore byte-stability), dash (eligibility query), proxy (in-band restore end to end).