Skip to content

fix(runtime): enforce ToolDescriptor.id == runtime tool name at compose time - #5

Open
AsherDLL wants to merge 1 commit into
mainfrom
fix/enforce-tool-id-matches-name
Open

fix(runtime): enforce ToolDescriptor.id == runtime tool name at compose time#5
AsherDLL wants to merge 1 commit into
mainfrom
fix/enforce-tool-id-matches-name

Conversation

@AsherDLL

Copy link
Copy Markdown
Member

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 the OutputPolicy by tool.name
  • runtime/callbacks/metrics.py — records ToolEvent(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.md already 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 — raising InvalidToolDescriptorError. 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 --strict clean.

Independent of #4 — no shared files; either can merge first.

🤖 Generated with Claude Code

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant