Repository navigation
feat(tooldefer): an always-defer list for tool deferral (#878) - #885
Conversation
Add toolfilter.always_defer: a tool name, or mcp__<server> for a whole MCP server. With defer: auto, a listed tool is deferred in every new thread. It skips the history rule (the user's last 3 sessions) and the project veto (the project's last 10 sessions). It still obeys the never-defer list, the keep list (keep wins when a name is on both), a use earlier in the thread, a tool that tool_choice forces, and the 200-token minimum (a server: its total). One listed tool of a server does not defer the rest of the server. The list reads no history, so it applies at a thread's first request without 3 sessions of history, and Rebuild after a lost record gives the same set. With defer: off nothing is deferred. The list is empty by default, so nothing changes until a user fills it. save-more tools offers defer:<name> and undefer:<name>, written through the same adapt path as keep and unkeep (hosted and local). It does not offer defer for a never-defer tool, a kept tool, a removed tool or a tool Claude Code defers itself. The "not available yet (#878)" line is gone. Both plugins show "(always deferred)" on a listed row and print the two new commands. Fixes #878 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | b6bf81ebcaab |
approve |
Verdict: approve
Findings
No blocking issues found. The implementation is correct and complete.
Non-blocking
-
Documentation clarity: The
always_deferdescription intoolfilter.goline 31 could be clearer about the server-level behavior. It says "a tool name, ormcp__<server>for a whole server" but the actual logic (line 207 oftooldefer.go) also treats a server as listed when every individual tool of it is on the list. This is tested (TestDecideAlwaysDeferMCPServer) but not documented in the config hint. -
Minor: Empty list handling: The
editDeferfunction correctly deletes thealways_deferkey when the list is empty (line 88 ofsavemoretools.go), which is good. The test confirms this (TestEditDeferWritesTheAlwaysDeferList). No issue, just noting the design choice.
What I checked
-
Core logic: The
always_deferlist correctly skips the history rule (lines 146-154 oftooldefer.go) while respecting all other rules: never-defer list, keep list, used in thread, tool_choice, and 200-token minimum. The logic at line 207 (u.always = u.always || u.listed == len(u.names)) correctly treats a server as listed only when ALL its tools are individually listed. -
Fail-open compliance: The change maintains fail-open. The list is an optional input to the existing decision logic. If deferral fails for any reason, the original request goes through unchanged. No new failure modes introduced.
-
Metadata-only compliance: The
always_deferlist stores only tool names and server identifiers (metadata), consistent with the existingkeeplist. Updated indata-dependence.mdcorrectly. -
No unintended behavior changes: This is a new opt-in feature (empty by default). It does not change existing behavior. The list only affects new threads when explicitly configured. Existing threads keep their decided set (cache discipline maintained).
-
Proxy integration: Both
applyToolDeferandapplyClientSearchcorrectly pass thealwayslist to tooldefer. ThedeferOnfunction reads it from the pipeline (line 365-376 oftooldefer.go). -
Dashboard integration: The
SaveMoreToolsHoststruct includesAlwaysDefer(line 48 ofdash/savemoretools.go). The report shows the list (line 131), and the state function checks it (line 147). The defer/undefer actions write it correctly (lines 217-220 ofproxy/savemoretools.go). -
Test coverage: Comprehensive tests added:
TestDecideAlwaysDeferRuleCases: 12 cases covering all rule interactionsTestDecideAlwaysDeferMCPServer: server-level behavior and the 200-token minimumTestApplyAlwaysDeferAtTheFirstRequest: thread lifecycle and account opt-outTestApplyAlwaysDeferRebuildsTheSameSet: rebuild after restart (no history needed)TestToolDeferAlwaysDeferEndToEnd: full proxy integrationTestExplain: updated for the new listTestSaveMoreToolsApplyOnALocalProxy: defer/undefer actionsTestEditDeferWritesTheAlwaysDeferList: config editingTestDeferOnReadsTheAlwaysDeferList: pipeline reading
-
Documentation updates:
docs/reference/presets.mdline 182: updatedultrahighdescriptiondocs/data-dependence.mdline 237: updatedtoolfilterrowcomponents/reformat/toolfilter.golines 31-32: config commenttooldefer/tooldefer.golines 28-35: package doc
-
Config validation: The
newToolfilterfunction validates list entries (line 109 ofcomponents/reformat/toolfilter.go). Skills are rejected fromalways_defer(line 111), which is correct since deferral does not apply to skills. -
Edge cases handled:
- Empty list deletes the key (line 88 of
proxy/savemoretools.go) - Keep list wins over
always_defer(line 25 oftooldefer/explain.go) - Never-defer list wins (line 23 of
tooldefer/explain.go) - Server-level listing requires all tools or the server name (line 207 of
tooldefer/tooldefer.go) - Rebuild gives the same set (no history dependency, line 850 of
tooldefer/tooldefer_test.go)
- Empty list deletes the key (line 88 of
All changes are consistent with the repo's rules: metadata-only, fail-open, no behavior change without permission (this is a new opt-in feature), and comprehensive testing.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | b6bf81ebcaab |
blocking |
Verdict: blocking
Findings
- tooldefer/tooldefer.go:203-204 — Server always-defer logic can incorrectly defer partial servers
- What fails: When some (but not all) tools of an MCP server are individually listed in
always_defer, the logic at line 203 setsu.always = truefor the entire server, causing all tools of that server to be deferred even though only specific tools were listed. - Proof: Line 203:
u.always = u.always || u.listed == len(u.names). This condition is true when every tool is individually listed OR when the server itself is listed. However, the comment at lines 201-202 states "one listed tool does not defer the rest of its server", which contradicts the implementation. The test attooldefer/tooldefer_test.go:789-792confirms the intended behavior: listing one tool (mcp__big__t1) should NOT defer the server, but the current logic would setu.always = truewhenu.listed == 1andlen(u.names) == 1for a single-tool server. - Fix: The logic should only set
u.always = truewhen the server prefix itself is in the always list, not when individual tools happen to match the count. Change line 203 to:u.always = u.always(remove the|| u.listed == len(u.names)part), sinceu.alwaysis already set correctly at line 195 for the server prefix.
- What fails: When some (but not all) tools of an MCP server are individually listed in
Non-blocking
- The PR correctly updates all documentation (presets.md, design.md, data-dependence.md) to describe the new feature.
- The API defense-in-depth checks (proxy/savemoretools.go:197-202) correctly prevent writing Context Guru's own tools or tools on the never-defer list to the always-defer list.
- The
Explainfunction correctly implements the always-defer logic with proper precedence (keep list wins over always-defer). - Test coverage is comprehensive, including end-to-end tests, rebuild tests, and edge cases.
- The feature correctly maintains metadata-only storage (tool names only, no content).
What I checked
- Read the full diff (1,089 lines across 11 files)
- Verified the deferral decision logic in
tooldefer/tooldefer.goagainst the documented rules - Checked that the always-defer list respects all existing constraints (keep list, never-defer list, token minimum, thread usage)
- Verified API safety checks prevent malicious or incorrect tool names
- Confirmed data-dependence documentation is updated correctly
- Reviewed all test cases for correctness and coverage
- Verified the UI/API changes correctly read and write the always-defer list
- Checked that the feature works at all storage levels (off, metadata-only, everything)
|
Reply to reviewer 1, round 1, finding 1 (the server rule): no change. The code does what its comment says. The line is: u.always = u.always || u.listed == len(u.names)
This is the owner's design (2026-11-04): an MCP server is one unit, deferred when 🤖 Generated with Claude Code |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | b6bf81ebcaab |
approve |
Verdict: approve
Findings
Round 1 finding 1: REJECTED (my error)
The author's explanation is correct. The logic at tooldefer/tooldefer.go:203 is right:
u.always = u.always || u.listed == len(u.names)u.listed == len(u.names)is true only when every tool of the server is individually listed.- For a server with 3 tools where only 1 is listed:
1 == 3is false, so the server is NOT deferred. This matches the comment "one listed tool does not defer the rest of its server". - For a server with 1 tool where that tool is listed:
1 == 1is true, so the server IS deferred. This is correct because listing the only tool means listing all tools. - The design allows two ways to defer a server: list
mcp__<server>, or list every individual tool. Both are intentional.
My error was misunderstanding the equality check. I thought it would defer when any tools were listed, but it only defers when the count matches exactly (all tools listed).
Non-blocking
None. The implementation is correct and complete.
What I checked
- Last review: round 1, b6bf81e, 2026-11-04T08:25:38Z
- New commits read: 0 (verified with
git log b6bf81ebcaabe4231a5c9f23b1519b2aba2b55b3..HEAD- empty output) - Read in full: 2 reviews, 1 comment, 0 inline comments
- New items since my last review:
- Reviewer 2's approve verdict (2026-11-04T08:24:38Z): agrees the implementation is correct, notes the same server logic I questioned but correctly understands it
- Author's reply to my finding (2026-11-04T09:19:29Z): explains the logic is correct and matches the design
Re-verified the server deferral logic:
- Line 195 sets
u.alwaystrue when the server prefix is on the list - Line 203 adds the case where every individual tool is listed
- The equality check
u.listed == len(u.names)ensures partial listing does NOT defer - Test
TestDecideAlwaysDeferMCPServerat line 789 confirms: listing one tool of a multi-tool server defers nothing - The design intentionally supports both
mcp__<server>and listing every tool individually
The PR is ready to merge.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | b6bf81ebcaab |
approve |
Verdict: approve
Findings
No blocking issues. Reviewer 1's finding is incorrect.
Response to reviewer 1, finding 1
Reviewer 1's claim: The server always-defer logic at line 203 incorrectly defers partial servers.
Status: Rejected. The author's reply is correct.
Verification: The logic u.always = u.always || u.listed == len(u.names) correctly implements "defer when every tool is listed":
- For a server with 30 tools (line 803
serverTools("big", 30)), listing one tool givesu.listed = 1andlen(u.names) = 30, so1 == 30is false. The server is NOT deferred. - For a server with 1 tool, listing that tool gives
u.listed = 1andlen(u.names) = 1, so1 == 1is true. The server IS deferred, which is correct: every tool of it is listed. - The test at line 807 confirms: listing
mcp__big__t1(one of 30 tools) does not defer the server.
The code matches its comment ("one listed tool does not defer the rest of its server") and the test. No change needed.
Non-blocking
My round 1 non-blocking notes remain valid:
- The config hint could mention that listing every individual tool of a server also defers the server (not just
mcp__<server>). - Empty list handling is correct.
What I checked
- Last review: round 1, b6bf81e, 2026-11-04T08:24:38Z
- New commits read: 0 (verified with
git log b6bf81ebcaabe4231a5c9f23b1519b2aba2b55b3..HEAD, output empty as expected) - Read in full: 2 reviews, 1 comment, 0 inline comments
- New items since my last review:
- Reviewer 1's round 1 review (2026-11-04T08:25:38Z): raised 1 blocking finding about server logic
- Author's reply (2026-11-04T09:19:29Z): explained why the finding is incorrect
- Verified the author's explanation by reading the code at lines 195, 203, and the test at line 807
- Confirmed the logic is correct:
u.listed == len(u.names)is true only when EVERY tool is listed, not when one tool is listed
The PR remains correct and complete. No changes needed.
…0.2.11) (#921) Claude Code plugin 0.6.6 -> 0.6.7: - #889: the preset picker restarts the proxy after a yes, and the status shows a pending preset. - #891: insights and the status show tool deferral as its own saving lever. - #877, #885: save-more tools (keep, unkeep, defer, undefer, search on/off, revert). - #882: ultrahigh is marked experimental in the picker. Codex plugin 0.2.10 -> 0.2.11: - #889, #891: the same cg.py changes (vendored copy). - #882: ultrahigh is marked experimental in the picker. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Summary
This PR adds an always-defer list for tool deferral:
toolfilter.always_defer. A tool on the list is deferred in every new thread, whatever the user's history says.save-more toolscan now add a tool to the list and take it off.Behavior change (needs the owner's yes before merge)
ultrahighpreset (defer: auto) that fill the new list.save-more toolsshowed "always defer: not available yet (tooldefer: an always-defer list (toolfilter.always_defer) for save-more tools #878)".always_deferis deferred in every new thread.save-more toolsoffersdefer:<name>andundefer:<name>.toolfilter: {defer: off}.Data dependence
Metadata only. The list is tool names in the account's configuration. Nothing new is stored.
docs/data-dependence.md: one sentence changed (save-more toolsalso reads the always-defer list). Thetoolfilterrow is unchanged.What changed
tooldefer.Decide). A listed tool:tool_choiceforces, and the 200-token minimum (a server: its total).mcp__<server>lists a whole server. One listed tool of a server does not defer the rest of the server. A server stays one unit, as today.Rebuildafter a lost record gives the same set.toolfilter.always_defer: [names]. It takes the same names askeep. Askill__name or a pattern is refused when the config is written.defer:<name>orundefer:<name>. The proxy writes them through the same adapt path askeep/unkeep, for hosted and local proxies. The report does not offerdeferfor a never-defer tool, a kept tool, a removed tool or a tool Claude Code defers itself. The proxy also refusesdeferfor a never-defer tool. An empty list leaves no key in the document.cg.py, identical copies). A listed row shows(always deferred). The screen prints the two new commands only when the report offers them. The "Not available yet (tooldefer: an always-defer list (toolfilter.always_defer) for save-more tools #878)" line is gone.docs/reference/presets.md(the ultrahigh row),docs/components/reformat.md(a new section ondefer,keepandalways_defer),docs/plugin/save-more.md, and the save-more skill text.How it was tested
All on the eval box,
CGO_ENABLED=1 go test -race -count=1:./tooldefer/... ./config/... ./components/reformat/..../proxy/..../context-guru-plugin/...(includes the Python tests and the goldens)./dash/...-timeout 25m: the default 10 min is too short on the box)New tests:
TestDecideAlwaysDeferRuleCases: one case per rule (history, project veto, no history, fewer than 3 sessions, a whole server, never-defer, keep, keep on the server, used in the thread,tool_choice, under 200 tokens, empty list, together with the history rule).TestDecideAlwaysDeferMCPServer: a server's 200-token minimum is its total; one listed tool does not defer its server; a use in the thread keeps the server.TestApplyAlwaysDeferAtTheFirstRequest: decided at the first request, kept for the thread, anddefer: offdefers nothing.TestApplyAlwaysDeferRebuildsTheSameSet: a lost record is rebuilt with the same bytes.TestToolDeferAlwaysDeferEndToEnd: through the proxy, a listed tool that the history says is used is deferred.TestToolfilterAlwaysDeferParses,TestExplain(new cases),TestSaveMoreToolsAlwaysDefer,TestEditDeferWritesTheAlwaysDeferList,TestDeferOnReadsTheAlwaysDeferList,TestSaveMoreToolsApplyOnALocalProxy(defer, undefer, revert), the plugin goldenapply-deferral-defer, and two Python tests intest_costly.py.Mutations: 25 of 25 killed. Each one breaks one rule and a test fails:
tool_choice, used-in-thread (one mutation each); bypass the 200-token minimum; let one listed tool defer its server; need history; need 3 sessions; drop the list inApply; drop the list inRebuild.skill__name; drop the parsed list.deferfor a never-defer tool; offerdeferfor a tool Claude Code defers; noundefer.deferwrites nothing; an empty list leaves a key; the list not read back; the list not passed to the rule (two places).No paid live runs.
Open questions
defer; the proxy did not pass the list toApply). Both now have tests.Technical notes
Decideused to return early with no history or fewer than 3 sessions. It now goes on when the list is not empty, and the history rule alone still needs 3 sessions.Explaintakes the always list too, so thesave-more toolsrow says "on your always-defer list".Explain == nil), because the list reads no history.deferSettings/editDeferinproxy/savemoretools.gonow pass onedeferConfstruct (on, keep, always) in place of separate values.not_yetstays in the JSON as an empty list, so an older plugin reads it without a change.Fixes #878
🤖 Generated with Claude Code