Make the virtual-concept re-entrancy rule enforceable - #403
Merged
Conversation
The guardrails shipped with JVNAUTOSCI-2650 did not hold up to inspection. The rule lived in a comment inside McpToolConceptProvider.owns, the one implementation that already followed it. The Protocol's owns() had no docstring at all, the module's resolution rules omitted it, and the regression test monkeypatched that provider specifically, so a third provider was uncovered. The guard itself was silent: it answered "not virtual", which can present as a missing concept, and logged nothing. State the rule where an implementer reads it, on the Protocol method and in the module docstring. Count and log guard trips so a reintroduced cycle leaves a trace instead of quietly changing answers, and expose guard_trip_count for diagnostics. Add a provider-agnostic test. It is structural rather than dynamic: the cycle only closes when the metadata load finds concepts to run access checks on, so it depends on database state. A first, dynamic version of this test passed happily with the bug deliberately reintroduced, and still passed after being changed to clear the caches first. Tripwires on get_canonical_tool_registry, get_tool_metadata, _load_from_vontology and can_access_concept encode the rule directly, and were verified to fail against a reintroduced owns() that consults the contract registry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Follow-up to #402 (JVNAUTOSCI-2650), prompted by the question "where is the hazard warning, and will it actually prevent future occurrences?" — the honest answer was no.
What was wrong with the guardrails
The rule lived in a comment inside
McpToolConceptProvider.owns, the one implementation that already followed it. Someone writing a third provider would more likely copyCodeConceptProvider, which is clean and says nothing.VirtualConceptProvider.ownshad no docstring at all — bare....test_owns_never_builds_the_contract_registrymonkeypatchesMcpToolConceptProvider._contractsspecifically, so a new provider was uncovered.Changes
State the rule where an implementer reads it: on the Protocol method and in the module docstring, including why the guard bounds the damage without making such a provider correct.
Count and log guard trips, and expose
guard_trip_count(), so a reintroduced cycle leaves a trace.Add a provider-agnostic test covering every registered provider.
Why that test is structural, not dynamic
This is the part worth reviewing. The cycle only closes when the metadata load finds concepts to run access checks on, so it depends on database state and does not reproduce in a unit test.
I verified this the hard way, by reintroducing the bug and watching the new test pass:
owns()calling it was harmless).get_canonical_tool_registry,get_tool_metadata,_load_from_vontologyandcan_access_concept, and asserts no registered provider'sowns()reaches any of them.Version 3 fails against a reintroduced
owns()that consults the contract registry, naming the offending provider and the exact forbidden call:Providers use call-time imports, so patching the module attribute catches them wherever they import from.
29 tests passing in the suite; 64 across the touched suites.
🤖 Generated with Claude Code