Repository navigation
Cover tool descriptions and parameter schemas in the eval-contamination guard (closes #1932) - #1952
Conversation
…on guard (closes #1932) `guidance_is_not_contaminated_by_eval_prompts` guards model-facing guidance against absorbing eval-scenario text, but `guidance_corpus()` hand-listed the prose constants and seeded-node markdown only. Tool descriptions and their parameter-schema descriptions were absent, so text in that channel was unguarded. That channel is exactly where guidance is being moved: ADR-064 rule 1 assigns argument shape to tool schemas on the strength of measured 100% compliance, so the doctrine actively pushes instructional text into the one place the guard could not see. A worked example built on an eval scenario could be planted in a tool description with nothing failing. Extend the corpus from `all_tool_definitions()`, so a tool added later is covered automatically — the same property the fixture-side enumeration already has, and the reason its doc comment records a hand-maintained list as the anti-goal. Descriptions are collected by walking the whole `parameters_schema` value rather than reading only top-level `properties.*.description`: they also sit on nested object properties and array `items` (update_schema's `add_fields.items.properties.type`, for one), and a fixed-depth read would recreate the same structural hole this enumeration exists to close. Not a live contamination fix — the extended guard passes against the current fixtures, confirming the gap was structural. Verified it genuinely fires by temporarily planting a real fixture prompt into `search_semantic`'s query description; the guard failed with the tool channel and shared phrase named. Tests: corpus coverage asserted against real registry text (so a refactor that stops reaching the registry fails), the schema walk pinned against nesting shapes including ones the registry does not use yet, and a detector test mirroring the existing planted-example pin for the tool channel. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FELy7rhqnKbDmmG9fuHALT
Pragmatic Code Review — PR #1952Review Type: Initial Review SummaryThis is a net positive and lands the structural fix #1932 asked for. I independently verified the implementer's claims rather than taking them at face value, including re-running the plant/revert experiment and running a differential against
That is the definitive answer to "does this add real protection, or is it self-satisfying?" — it is real. The guard genuinely could not see this channel before and can now. The recursive walk (deviating from the issue's proposed top-level-only read) is the right call and I'd have flagged the issue's narrower version as a defect: There is one substantive gap worth addressing (a second model-facing tool registry is still unguarded), and some smaller polish. None of it blocks merge on its own, but the gap is the same class of miss as #1932 itself. Requirements Check (issue #1932)
Independent VerificationClaim 2 — recursion is necessary, not gold-plating: CONFIRMED. Claim 3 — guard passes on current fixtures: CONFIRMED. 14/14 green in 0.06s. Claim 4 — the guard genuinely fires: CONFIRMED, and I strengthened the evidence. I then ran the same plant against Brittleness measurement (the key flakiness signal).
Conclusion on false-positive risk: acceptable. The new channel does not raise the observed ceiling above what the pre-existing corpus already produced — both max out at 3. The margin is one word, but that margin was already one word before this PR; adding 93 entries did not consume it. This is not a change that turns the guard into a flaky tripwire. Worth noting the margin is thin in absolute terms, but that is a property of the pre-existing threshold, not a regression this PR introduces.
Test quality: non-tautological — verified by simulated regression. I removed the Findings🟡 Important📁
This matters more than a generic "you missed a registry", because
against fixture scenarios The issue text said Suggested fix, mirroring the existing loop: for def in crate::local_agent::routing::stage1_tool_definitions() {
if !def.description.is_empty() {
corpus.push(("routing::stage1_tool_definitions description", def.description));
}
collect_schema_descriptions(
&def.parameters_schema,
"routing::stage1_tool_definitions parameters_schema",
&mut corpus,
);
}I measured this addition: max shared run against the fixtures is 2, so it passes today with margin to spare and adds no flakiness. If you'd rather keep this PR scoped to the issue, that's defensible — but please open the follow-up rather than dropping it. Principle: completeness of a derived enumeration. A guard whose value proposition is "derived, so nothing is missed by default" is undermined by a second source it doesn't derive from — this is the same failure mode the guard's own doc comment calls out about hand-maintained lists. 📁
Principle: comments should record the "why" behind a non-obvious choice between two similar APIs. 🟢 Suggestions📁 .parameters_schema["properties"]["add_fields"]["items"]["properties"]["type"]["description"]Six chained index operations plus two That said, I don't think this should change. The failure is loud, the message is nearby, and asserting against real registry text rather than a constructed value is what makes this test meaningful ( Principle: tests coupled to fixture internals should fail with a message that points at the real cause. 📁 The failure I reproduced reads Principle: error messages should minimize the distance from failure to root cause; the value scales with corpus size, and the corpus just grew 4x. Nit: 📁 When Nit: 📁 Observation (pre-existing, not introduced by this PR)
Verification PerformedRecommendationAPPROVE — with the The change does exactly what #1932 asked, the deviation from the issue's proposal is a correct engineering judgment rather than scope creep, the tests are meaningful and I proved they fail on regression, and the differential-against-main experiment shows the protection is real rather than self-satisfying. The false-positive analysis says this won't become a flaky tripwire that someone later weakens — the new channel doesn't push the observed shared-run ceiling above where the pre-existing corpus already sat. The one thing I'd genuinely like to see resolved is Stage 1. Not because it's contaminated today (it isn't — run of 2), but because shipping "the corpus is now derived from the registry" while a second model-facing registry is derived from nothing invites the exact same issue to be filed again in a month. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
One tracked item: stage1_tool_definitions() (routing.rs:128) is a second model-facing tool registry still absent from guidance_corpus(). Not contaminated today (max shared run 2), but it is the same structural gap #1932 describes. Address here or as an immediate follow-up.
…tool in violations
Addresses the 🟡 finding from the PR review.
stage1_tool_definitions() (routing.rs) is a second model-facing tool
registry — agent_loop.rs hands it straight to the model as that turn's tool
surface — and it was enumerated nowhere. Shipping "the corpus is derived from
the registry" while a second registry is derived from nothing would leave the
same structural hole one registry over, and invite this issue to be refiled.
This is not hypothetical drafting risk: route_query's query description
already carries a worked example built on eval-scenario material
('update the equipment record worth 2400 to returned', against the fixture
prompts "The 2400 one came back — set it to returned" and "...replacement
cost 2400"). It measures a shared run of only 2 so it does not fail today,
but it is exactly the pattern the guard exists to catch, previously in a
channel nothing watched.
Both registries now flow through one loop, so they cannot drift and a third
registry is a one-line addition. Verified the new coverage genuinely fires by
planting the real fixture prompt into route_query's description: the guard
failed naming the registry, tool, and channel. Reverted after.
Measured the flakiness cost independently rather than assuming it: across
134 corpus entries x 33 fixture prompts the max shared run is 3 against
MAX_SHARED_RUN = 4, and Stage 1's own worst case is 2 — the pre-existing
corpus already sat at 3, so this consumes no margin.
Also from the review:
- Violation labels now name the specific tool, not just the registry
("routing::stage1_tool_definitions route_query parameters_schema" rather
than the registry alone). With the corpus 4x larger, this removes a
grep-the-shared-phrase step from every future diagnosis. Costs widening
the label to String, which is contained to this test helper.
- Recorded why all_tool_definitions() is deliberately preferred over
model_facing_tool_definitions(): search_skills is withheld from the local
loop but stays model-facing to external MCP agents, and over-inclusion in
a guard costs nothing.
- Coverage test now asserts both registries and fails if only the main one
is checked.
Declined, per the reviewer's own guidance on both: swapping the nested
assertion's anchor to enum_values (the reviewer recommended keeping the
current one — asserting against real registry text is what makes it
meaningful), and the walker's harmless double-visit of description values
(the current shape correctly handles a description key holding an object).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FELy7rhqnKbDmmG9fuHALT
Review Addressed — commit
|
Pragmatic Code Review — PR #1952 (Re-Review)Review Type: Re-Review Previous Review Summary
5 recommendations → 3 addressed, 2 declined on my explicit guidance, 0 outstanding. No new issues found. Top Risk Check: Did the restructure drop pre-existing coverage?This was the stated top risk, and it's the right one to worry about — the loop was restructured and the label type threaded through every call site. I verified it empirically rather than by reading the diff. I instrumented Per-channel histogram, before → after:
Zero coverage lost. Every pre-existing channel is present at identical cardinality, and the 93 main-registry entries survived the restructure exactly. The delta is purely additive: the 3 Stage 1 tool descriptions plus 4 of their schema descriptions. Independent VerificationClaim: "both registries flow through a single loop so they can't drift" — CONFIRMED and complete. Claim: "verified it fires" — CONFIRMED, reproduced independently with a different plant site. This confirms two things at once: the guard reaches Stage 1, and the new label genuinely resolves to registry + tool + channel. Plant reverted; Claim: "134 × 33, max shared run 3; Stage 1 worst case 2" — CONFIRMED exactly. Stage 1's ceiling is 2 — it consumes none of the margin. The pre-existing corpus already sat at 3, and adding a 7th channel did not move the ceiling. Note the implementer reported Stage 1's worst phrase as Coverage test is non-tautological — verified by simulated regression. It fails at the per-tool assertion ( Hygiene: Requirements Check (issue #1932)
Code Review Findings🟢 Suggestions📁 assert!(
tools_checked > crate::local_agent::tools::all_tool_definitions().len(),
"both tool registries must be checked — only the main one was..."
);You asked whether this is fragile or tautological. It is neither, but it is also not the assertion doing the real work. Assessment:
I'd keep it. It's three lines, costs nothing, and defends a real if unlikely shape. Just noting that the per-tool loop is the load-bearing assertion, so nobody later mistakes the count check for the primary guarantee and "simplifies" the wrong one away. Principle: layered assertions are fine, but their relative strength should be legible — the strongest one should be the one a reader reaches for. 📁 You asked specifically about allocation and awkwardness. Assessment: no unnecessary allocation, mild syntactic cost, right trade.
The mixed inline- Principle: in test-support code, prefer clarity over allocation-avoidance; the widening buys diagnosis quality at a cost that never reaches a hot path. 📁 Worth calling out positively since it was finding #2: the added note explains both non-obvious choices (why two registries, why the unfiltered set) and explains them as why, not what. The "guarding only one registry would leave the very hole this enumeration exists to close, one registry over" line is exactly the framing that stops a future reader from re-litigating the decision. The doc comment on the coverage test was updated in step rather than left stale — an easy thing to miss in a rename-heavy diff. Verification PerformedOn the fmt drift: I confirmed it is not attributable to this PR — RecommendationAPPROVE The delta does what it claims and I verified the risky part empirically rather than by inspection. The headline result: the restructure dropped zero pre-existing coverage — all 127 prior entries survive byte-identical, and the change is purely the +7 Stage 1 additions. Three things raise my confidence above the initial review:
Remaining findings are 🟢 observations about assertion layering and Rust verbosity. Nothing blocking, nothing requiring another pass. No re-review needed. |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Summary
guidance_is_not_contaminated_by_eval_promptsguards model-facing guidance against absorbing eval-scenario text, butguidance_corpus()hand-listed only the prose constants and seeded-node markdown. Tool descriptions and their parameter-schema descriptions were absent, so text in that channel was unguarded.That channel is exactly where guidance is being moved: ADR-064 rule 1 assigns argument shape to tool schemas on the strength of measured 100% compliance, so the doctrine actively pushes instructional text into the one place the guard could not see. A worked example built on an eval scenario could be planted in a tool description with nothing failing.
Changes
guidance_corpus()now enumeratesall_tool_definitions(), adding each tool'sdescriptionand everydescriptionstring in itsparameters_schema. Deriving from the registry keeps tools added later covered automatically — the same property the fixture-side enumeration already has, and the reason its doc comment records a hand-maintained list as the anti-goal.properties.*.description. This goes beyond the issue's proposal deliberately: descriptions also sit on nested object properties and arrayitems(update_schema'sadd_fields.items.properties.type, for one), and a fixed-depth read would recreate the same structural hole this enumeration exists to close.Verification
The extended guard passes against the current fixtures, confirming the issue's read that the gap was structural rather than a live contamination.
Since a guard that passes proves nothing on its own, I checked it genuinely fires: temporarily planting the real fixture prompt
"Do we have anything worth 90000 sitting out?"intosearch_semantic'squerydescription failed the guard with the tool channel and the shared phrase both named. The plant was reverted.New tests:
guidance_corpus_covers_tool_descriptions_and_parameter_schemas— asserts against real registry text, so a refactor that stops reachingall_tool_definitions()fails here rather than passing quietly.schema_description_walk_reaches_arbitrary_nesting— pins the walk against nested properties, array items, and schema arrays, including shapes the registry does not use yet.contamination_guard_detects_a_planted_example_in_a_tool_schema— mirrors the existing planted-example pin for the newly covered channel.Testing
bun run test:all— frontend 172 files / 4112 tests passed (matches baseline exactly), browser 2/24 passed, no Rust failurescargo clippy -p nodespace-agent --all-targets -- -D warnings— cleanNote
quality:fixreformatted seven unrelated files workspace-wide; those were reverted to keep this PR scoped. A pre-existingcargo fmtdrift inpackages/agent/tests/golden_scenario6_sequence.rsis present on cleanmainindependent of this change and was left alone.Closes #1932
🤖 Generated with Claude Code
https://claude.ai/code/session_01FELy7rhqnKbDmmG9fuHALT