Skip to content

Stop create_schema from copying an unrelated retrieved schema's fields onto a new type - #1859

Merged
malibio merged 2 commits into
mainfrom
issue-1846-schema-field-contamination
Jul 31, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-1846-schema-field-contamination

Conversation

@malibio

@malibio malibio commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • create_schema was copying a semantically-retrieved unrelated schema's fields onto a brand-new type (e.g. album_tracker getting equipment_item's is_returned/replacement_cost), because the RELEVANT ENTITY TYPES context block is the only field metadata the model sees on a creation turn and was being consumed as a copyable template.
  • A prose-only fix (a new Schema Creation skill rule) was measured against a live isolated daemon and had zero effect — the rule was confirmed seeded and present in the prompt, but the model still copied fields verbatim.
  • The effective fix puts the anti-copy instruction inline in the block's header itself, at both sites that render it: the resident workspace context (packages/core/src/ops/context_ops.rs) and Stage-2 routing's candidate metadata (packages/agent/src/local_agent/routing.rs) — the latter was a second, previously-unguarded copy of the same text that was reinforcing the contamination even after the first site alone was fixed. Both now share one RELEVANT_ENTITY_TYPES_HEADER constant so they can't drift apart again (with a test asserting the routing.rs site uses the exact constant).
  • Added minProperties: 1 to eval scenario 8c so it can no longer score green on an empty record.

Measured result (isolated daemon, purged DB, gemma-4-e4b-q4km, n_ctx 32768, 5 independent trials): 4 of 5 clean (sensible fields like genre/artist), 1 of 5 still contaminated. This is a real, measured reduction, not a categorical fix — consistent with ADR-064's finding that prompt/context-level interventions are probabilistic on this locked 4B model. Filed #1858 to track closing the remaining gap with a routing-aware context assembly (a larger architectural change, since context is assembled before Stage 2 routing runs today).

bun run eval:agent score (full 12-scenario matrix, post-fix, both render sites patched): 8/12 passed. Scenarios 8a/8b (schema creation) pass; scenario 8c (create_node for the first custom type) now calls create_node at all — a behavior change from pre-fix runs where it called no tool — but still fails minProperties (a distinct, pre-existing gap from #1841: properties aren't reliably persisted, not a #1846 regression). The 4 failing scenarios (4, 6, 8c, and one of 8d/8e depending on the run) are consistent across before/after runs and are not newly introduced by this PR — see the issue thread for the full before/after/after2/after3 run comparison.

Full investigation, both fix attempts, and the measurement methodology are documented on #1846.

Closes #1846

Test plan

  • cargo test -p nodespace-core --lib context_ops — 30 passed
  • cargo test -p nodespace-agent --lib routing — 32 passed (incl. new schema_metadata_section_uses_the_shared_header)
  • cargo test -p nodespace-agent --lib — 383 passed
  • cargo test -p nodespace-core --lib — 1061 passed
  • bun run test:all — full suite passed (frontend, Rust workspace, e2e, scripts)
  • bun run quality:fix — clean
  • Live measurement against isolated gemma-4-e4b-q4km daemon: 5 independent trials of the equipment→album repro (4/5 clean, 1/5 contaminated — documented in code comments and issue)
  • Pre-push gate (test:all + cargo build + e2e) passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01DkqjrfV1G6kugsEjvyU9wU

…s onto a new type (closes #1846)

The RELEVANT ENTITY TYPES context block was being consumed as a field
template: creating a new type while an unrelated schema was in context
(e.g. equipment_item) copied that schema's fields verbatim onto the new
type. A prose-only fix (a new Schema Creation skill rule) measured zero
effect against a live isolated daemon; putting the anti-copy instruction
inline in the block's header, at both render sites that show it (the
resident workspace context and Stage-2 routing's candidate metadata,
which was a second, previously-unguarded copy of the same text),
measured a real reduction from contaminated on every trial to clean on
4 of 5. Both sites now share one RELEVANT_ENTITY_TYPES_HEADER constant
so they can't drift apart again.

Added minProperties to eval scenario 8c so it can no longer score green
on an empty record. Filed #1858 to track closing the remaining
probabilistic gap with a routing-aware context assembly.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This is a well-executed, evidence-driven bug fix for #1846 (create_schema copying an unrelated retrieved schema's fields onto a brand-new type). The diff is atomic, all 7 files are in-scope, the dedup requested in the issue thread's prior review is genuinely implemented (not just claimed), and the PR is honest about scope: it explicitly reports a measured 4/5 improvement rather than a categorical fix, with a follow-up issue (#1858) filed for the remaining gap. I verified this independently rather than taking the PR body at its word — see below. Net positive; recommending APPROVE.

Verification performed (not just read)

  • cargo run -p nodespace-agent --bin gen_skill_md -- --check → "SKILL.md is up to date" — confirms SKILL.md is genuinely generated from skill_rules.rs/gen_skill_md.rs, not hand-edited out of sync.
  • grep -rn '"RELEVANT ENTITY TYPES' packages/ --include="*.rs" → exactly one literal definition site (context_ops.rs:114, the RELEVANT_ENTITY_TYPES_HEADER constant). Every other reference in routing.rs, skill_pipeline.rs, tools.rs, agent_guidance.rs either imports the constant or refers to the block by name in prose that already existed pre-PR. This is a real single-source-of-truth dedup, not two strings that happen to match today.
  • cargo test -p nodespace-core --lib context_ops → 30 passed; cargo test -p nodespace-agent --lib routing → 32 passed; cargo test -p nodespace-agent --lib → 383 passed; cargo test -p nodespace-core --lib → 1061 passed. All match the PR's stated test plan.
  • Read schema_metadata_section_uses_the_shared_header (routing.rs) — it asserts rendered.contains(RELEVANT_ENTITY_TYPES_HEADER) against a constant imported from context_ops.rs, not a copy-pasted literal. If a future edit reverted the routing.rs render call to a hardcoded string, this test would still compile (both sides import the same symbol today) but the production call site would need to literally use the constant for the assertion to pass — so a regression that swaps back to a local literal string at the render call itself is exactly what this catches. Not tautological.
  • Fetched issue create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846's prior review comment (the one requesting dedup) and the follow-up comment reporting it done — confirmed both requested action items were delivered: (1) the shared constant + drift test, and (2) both the doc-comment residual-rate note at the code site and the follow-up issue create_schema field contamination still occurs on ~1 in 5 turns after #1846's context-block fix #1858 (the review asked for both, not either/or, and both are present).
  • Confirmed nodespace-agent already depends on nodespace-core in Cargo.toml — importing RELEVANT_ENTITY_TYPES_HEADER from core into agent's routing.rs respects existing crate layering, not a new/inverted dependency.

Findings

Critical Issues

None.

Suggested Improvements

  • 📁 PR body / issue create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846 acceptance criteria — Criterion 4 is "Re-run bun run eval:agent and report the score." The PR body's test plan lists the 5-trial live measurement and various cargo test/bun run test:all runs, but doesn't restate a numeric matrix score (e.g. "N/12 scenarios passing"). Digging into the issue thread, the 5 trials were full eval:agent runs (per the issue comment: "1 of 5 trials (the full 12-scenario eval:agent suite run): still contaminated"), and scenario 8c's behavior shift was independently noted — so the substance of the criterion is satisfied, just not restated as a single score in the PR itself. Improvement: add one line to the PR body (or a closing issue comment) with the aggregate score from these runs, so a future reader of the PR alone (without cross-referencing the issue thread) can see the criterion was checked off with evidence, not just narratively.

  • 📁 packages/agent/src/skill_rules.rs:72-76 (FIELDS_FROM_REQUEST_ONLY) — This is the prose-only rule that the PR's own investigation measured to have zero effect on its own (per the issue and PR body). It's being kept in this PR anyway, layered under the structural header fix. That's a reasonable engineering call — it's cheap, doesn't conflict with anything, and might matter for other models/paths not covered by the live-daemon trials — but the PR should make explicit (a one-line comment at the rule definition, mirroring the honesty already shown in RELEVANT_ENTITY_TYPES_HEADER's doc comment) that this specific rule was the measured-ineffective prose attempt kept for defense-in-depth, not a component of the measured 4/5 result. As written, a future reader skimming skill_rules.rs in isolation (without the issue history) could reasonably assume this rule contributed to the fix, when the PR's own evidence says the opposite for this class of intervention. Low stakes since it's clearly disclosed in the PR body/issue at the aggregate level, but worth a nit-to-improvement-level doc comment for the specific rule given how much store this workstream (ADR-064) puts in not conflating measured vs. assumed effect.

Nitpicks

  • Nit: 📁 packages/core/src/ops/context_ops.rs:114 — The header string embeds the anti-copy clause as a parenthetical: "RELEVANT ENTITY TYPES (existing types — do not recreate; do not copy their fields onto a new type):". This is a dense, doubly-negated instruction packed into a heading. It reads fine and is clearly working (per the 4/5 measurement), but if a future iteration needs to add a third constraint to this heading, consider whether the header is the right place to keep growing versus factoring further instruction into the routing-aware fix tracked in create_schema field contamination still occurs on ~1 in 5 turns after #1846's context-block fix #1858. Not asking for a change now — the current form is measured and working.
  • Nit: 📁 scripts/eval/fixtures/agent-matrix.ts:346-349 — The comment explaining minProperties: 1 is a little dense (packs in both the mechanism rationale and a forward reference to create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846's schema limitation). Minor readability point only; the mechanism itself is correctly scoped to scenario 8c and consistent with its established use at scenario 6/7.

Acceptance Criteria — Issue #1846

  • ✅ Determine the mechanism, measured rather than assumed — Met. Root cause (the RELEVANT ENTITY TYPES block consumed as a copyable template, at two independent render sites) was isolated via a controlled repro (clean DB vs. equipment-schema-present, same chat vs. separate chat) documented in the issue, ruling out conversation history as the carrier.
  • ⚠️ A new type's fields derive from the user's request, not from retrieved schemas, with an unrelated schema present — Partially met, and explicitly disclosed as such (4/5 clean across 5 independent live trials, consistent with ADR-064's probabilistic-intervention finding on this locked model). This is the disclosed, deliberate scope for this PR; the remaining gap is tracked in create_schema field contamination still occurs on ~1 in 5 turns after #1846's context-block fix #1858 with a concrete proposed mechanism (routing-aware context assembly). Not a defect — a measured, honest partial fix is a legitimate outcome here and is not overclaimed anywhere I checked (PR body, commit message, and code doc comments all state "4 of 5," "not a categorical fix," and "probabilistic" consistently).
  • ✅ Add minProperties to agent-matrix 8c so it can no longer score green on an empty record — Met, verified in diff; correctly scoped to scenario 8c only, consistent with the existing mechanism already used at scenarios 6/7.
  • ⚠️ Re-run bun run eval:agent and report the score — Substantively met via the issue thread (the 5 trials were eval:agent runs; scenario 8c's behavior change was independently noted), but not restated as an aggregate score in the PR body itself. See Suggested Improvements above.

Recommendation

APPROVE.

This is a net-positive, well-scoped fix backed by real measurement discipline (live isolated daemon, purged DB, 5 independent trials, explicit before/after) rather than assumption — exactly the standard this workstream has been building toward per ADR-064. The requested dedup from prior review feedback is genuinely implemented with a non-tautological regression test, not merely claimed. The two items above are minor and don't block merge: the eval-score restatement is a documentation completeness nit, and the FIELDS_FROM_REQUEST_ONLY attribution note is a clarity improvement for future readers, not a functional concern.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review recommendation: APPROVE (self-approval blocked by GitHub — PR author and reviewing account are the same user). Full findings posted above.

…ve status

Per PR #1859 review feedback: this rule was measured on its own to have
zero effect on the #1846 contamination it targets, and is kept as
defense-in-depth rather than as part of the measured 4/5 structural
fix. Doc comment makes that explicit so a future reader of skill_rules.rs
in isolation doesn't credit it with the improvement RELEVANT_ENTITY_TYPES_HEADER
actually produced.

Also restated the aggregate bun run eval:agent score (8/12) directly in
the PR body, per the same review's request to check off issue #1846's
acceptance criterion 4 with an explicit number rather than only a
cross-reference to the issue thread.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review feedback

Addressed (2):

  • 🟢 Restated the aggregate bun run eval:agent score (8/12) directly in the PR body, so issue create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846's acceptance criterion 4 is checked off with an explicit number rather than only a cross-reference to the issue thread.
  • 🟢 Added a doc comment to FIELDS_FROM_REQUEST_ONLY (packages/agent/src/skill_rules.rs) making explicit that this specific rule was measured on its own to have zero effect, and is kept as defense-in-depth rather than as part of the measured 4/5 structural-fix result — so a future reader skimming skill_rules.rs in isolation doesn't credit it with the improvement RELEVANT_ENTITY_TYPES_HEADER actually produced.

Skipped (2, both nitpicks the reviewer explicitly flagged as non-blocking):

All tests re-verified after the changes: cargo test -p nodespace-agent --lib (383 passed), cargo test -p nodespace-core --lib (1061 passed), cargo fmt -p nodespace-agent -- --check (clean). Pushed through the full pre-push gate (test:all + cargo build + e2e suite) — all green.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Both addressed items were documentation/doc-comment additions (a PR body edit and an 9-line doc comment) with zero logic changes — no new functionality, no architectural changes, nothing that alters the behavior the prior review already verified. The two skipped items were nitpicks the reviewer itself marked as not blocking and not requiring action now. Ready for an independent human approval and merge.

@malibio
malibio merged commit c98169c into main Jul 31, 2026
2 checks passed
@malibio
malibio deleted the issue-1846-schema-field-contamination branch July 31, 2026 19:46
malibio added a commit that referenced this pull request Jul 31, 2026
… use (#1857) (#1861)

* Give resolve_query's sub-prompt the enum values it tells the model to use

The sub-prompt instructs the model to map "a status word to an enum/status
field", but rendered fields as `name (type)` — so an enum arrived as
`condition (enum)` with its legal values nowhere in sight. The model had to
invent one, and an invented value yields a filter matching nothing, which
reads exactly like a request that legitimately had no match.

This is the same no-referent shape as the guidance that told the model to
populate `properties` from field metadata the prompt never carried: the
instruction names something the prompt does not supply, and the failure is
silent.

Rendered through `EntityFieldDescriptor` rather than a local spelling, so
this is the third call site on one renderer instead of a fourth hand-written
one. `from_schema_field` becomes public to allow it. The notation now also
matches the entity block the model sees elsewhere in the same conversation.

The test asserts on the prompt text, not the tool's return value — the
return value is well-formed whether or not the model guessed. Verified by
mutation: against the old renderer the prompt shows `- condition (enum)` and
the test fails.

Eval: 6/12 with this change, and 6/12 on an unmodified build of the same
commit — identical failures scenario for scenario, so this is neutral on the
matrix. Note that baseline is down from the 10/12 measured before #1859
landed; scenario 6 (this change's target) fails in both arms for want of a
resolve_query call at all, so the fix cannot be scored by the matrix today.
Worth a look at whether #1859 regressed schema creation — 4, 8b and 8c all
fail on rejected schemas or unpersisted properties, which is that area.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163

* Address review: keep write-time obligations out of the filter sub-prompt

Reusing `render()` wholesale carried ", required" into `resolve_query`'s
prompt. Reproduced before fixing: a required field rendered as
`- replacement_cost: number, required`.

That is not cosmetic. `required` has exactly one definition in front of this
model — the node-creation guidance's "MUST be included in the properties
map" — which is an obligation on a *write*. This sub-call is a lone user
message with no system prompt and no tools, so the word arrives with no
definition at all, and a model applying the one it knows would filter on a
field the request never mentioned. That matches nothing, which is
indistinguishable from a genuinely empty result: the same silent failure
this PR set out to remove, reintroduced from the other side.

Split `render_shape` (name, type, enum values) from `render` (that plus
required-ness). The entity block keeps `render` — required-ness is exactly
what it should say when the model is about to create a node. Read and filter
prompts get `render_shape`. Both still share one renderer, so the
convergence this PR is about is intact.

Pinned by assertion rather than left to inspection: the fixture's number
field is now required, so the test proves the suffix is suppressed rather
than merely absent. Mutation-verified — restoring `.render()` fails it.

Also corrected a comment claiming this notation "matches the entity block the
model sees elsewhere in the same conversation." There is no same
conversation; this is an isolated sub-call. The maintenance argument for
convergence carries the change on its own.

Reviewer's other findings needed no code change: `pub` is correct
(`pub(crate)` cannot work across crates), the notation is coherent with the
surrounding prompt, and the CapturingEngine/FixedJsonEngine duplication is
worth consolidating at a third double, not a second.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01AvsJJC6NgtJuNz8fTYA163

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost)

1 participant