fix(runtime): enforce ToolDescriptor.id == runtime tool name at compose time - #5
Open
AsherDLL wants to merge 1 commit into
Open
fix(runtime): enforce ToolDescriptor.id == runtime tool name at compose time#5AsherDLL wants to merge 1 commit into
AsherDLL wants to merge 1 commit into
Conversation
…iptor id The compactor binds an OutputPolicy by runtime tool name (context/compactor.py) and the metrics callback records a ToolEvent under it (callbacks/metrics.py), while the catalog keys both by descriptor id. Nothing enforced that the two agree, so a mismatch silently applied the default policy -- letting unbounded tool output into the context window -- and attributed the event to the wrong id. Enforce it in _resolve_tool, the single point where the descriptor and the resolved tool are both known; catalog freeze cannot do this because 27 of the 29 registered tools are factory-built and have no name until compose time. Toolsets are exempt: they supply many names, not one. All 29 currently registered tools already satisfy the rule (verified by resolving each against the real RE catalog), so this changes no behavior today and turns a documented convention into an enforced invariant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Two consumers key off the runtime tool name while the catalog keys off the descriptor id, and nothing enforced that they agree:
runtime/context/compactor.py— looks up theOutputPolicybytool.nameruntime/callbacks/metrics.py— recordsToolEvent(tool_id=getattr(tool, "name", ...))On a mismatch both fail silently: the compactor falls back to the default policy (so a tool's configured output cap stops applying, letting unbounded output into the context window) and the event is recorded under the wrong id.
AGENTS.mdalready documented the rule; only the docs enforced it.The fix
One guard in
_resolve_tool— the single point where the descriptor and the resolved tool are both known — raisingInvalidToolDescriptorError. Both consumers become correct by construction.Catalog freeze can't do this: 27 of the 29 registered tools are factory-built and have no name until compose time. Toolsets are exempt (they supply many names, not one).
Risk
None today. I resolved all 29 tools against the real RE catalog and every one already satisfies
id == name, so no behavior changes — this only converts a convention into an enforced invariant that fails loudly at startup instead of silently at runtime.Testing
Four tests covering each branch (match, concrete mismatch, factory mismatch, toolset exemption). Confirmed they fail with the guard removed. Full suite green: 2482 passed, 1 skipped;
ruff,ruff format --check,mypy --strictclean.Independent of #4 — no shared files; either can merge first.
🤖 Generated with Claude Code