Repository navigation
Description
Overview
#1846 fixed create_schema copying a semantically-retrieved unrelated schema's fields onto a new type (e.g. album_tracker getting equipment_item's is_returned/replacement_cost) by adding an inline anti-copy clause to a shared RELEVANT_ENTITY_TYPES_HEADER constant, applied at both sites that render the RELEVANT ENTITY TYPES block:
packages/core/src/ops/context_ops.rs— the resident workspace-context block assembled every turn.packages/agent/src/local_agent/routing.rs— the Stage-2 routing candidate metadata rendering (a second, independently-maintained copy of the same heading that create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846 found was still unguarded and reinforcing the contamination even after the first site was fixed).
That fix is a measured, real improvement, but not a categorical one — this issue tracks closing the remaining gap.
Problem Statement
Measured on the locked native model (gemma-4-e4b-q4km, isolated daemon via NODESPACE_HOME, purged DB before each trial, n_ctx 32768), running the same equipment→album repro independently 5 times after #1846's fix landed:
- 4 of 5 trials: clean — the new type got sensible, request-derived fields (
genre, orgenre+artist) - 1 of 5 trials: still contaminated — the new type's fields were byte-identical to the unrelated existing schema's fields
This matches ADR-064's documented finding that prompt/context-level interventions on this locked 4B model are probabilistic, not deterministic — the anti-copy clause reduces the failure rate but the model does not reliably honor it every time.
Proposed Solution
Make the fix structural rather than probabilistic: have context assembly omit other custom-type schemas' full field lists from the RELEVANT ENTITY TYPES block specifically when the current turn is routed toward create_schema — showing only existing type names/ids (enough to satisfy the "don't recreate an existing type" check) rather than their fields (which is the data being copied).
This requires context assembly to depend on the routing decision, which the pipeline does not support today: context_ops.rs's build_workspace_context assembles the block before ADR-038's Stage 2 routing runs. Making this work needs either:
- Reordering so routing runs first and its outcome is passed into context assembly, or
- A two-pass render where the entity block is re-filtered after routing decides
create_schemais the likely target tool, or - Some other mechanism that lets the entity block vary its field-list verbosity based on which tool the turn is headed toward.
Architecture Impact
This issue proposes extending, not reversing, ADR-038 and ADR-064:
- ADR-038 (
../nodespace-docs/decisions/038-skill-mediated-tool-routing.md) established the two-stage routing pipeline (retrieval, then LLM-judged candidates) as running independently of context assembly. This issue's proposed direction introduces a dependency from context assembly on the routing outcome, which ADR-038 does not currently contemplate — implementing this fix will likely require a note or amendment to ADR-038 (or a new ADR) documenting that context assembly may now be routing-aware for this specific case, once a concrete mechanism is chosen. - ADR-064 (
../nodespace-docs/decisions/064-instruction-channel-doctrine.md) rule 1 governs tool-schema-owned argument shape and rule 4 governs tool-result-owned facts; theRELEVANT ENTITY TYPEScontext block sits in a category ADR-064 doesn't fully name (it's neither a tool schema nor a tool result). This issue's eventual fix should be measured against ADR-064's evidence-based methodology (compare candidates, don't assume) before landing.
No nodespace-docs change is required to file this issue; a companion ADR update/addition will likely be needed once an implementation approach is chosen and measured.
Acceptance Criteria
- Determine a concrete mechanism for making the
RELEVANT ENTITY TYPESblock's field-list verbosity depend on the routing decision (or an alternative that achieves full determinism), measured rather than assumed - Re-run the same 5-independent-trial measurement (isolated daemon, purged DB,
gemma-4-e4b-q4km) and confirm 0 of 5 (or a materially improved rate) show field contamination -
bun run eval:agentshows no regression on scenarios 3, 8a, 8b, 8c relative to create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846's post-fix baseline - Document the measured before/after rate in this issue and in a doc comment at the relevant code site(s), per the pattern create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846 established
Technical Specifications
Reference Files
- context_ops.rs:
packages/core/src/ops/context_ops.rs—build_workspace_context(assembly) andWorkspaceContext::format_for_prompt(rendering); owns the residentRELEVANT ENTITY TYPESblock and theRELEVANT_ENTITY_TYPES_HEADERconstant - routing.rs:
packages/agent/src/local_agent/routing.rs—render_candidates_for_prompt(Stage-2 candidate rendering, second render site) and the two-stage routing pipeline this issue's fix needs to coordinate with - agent_loop.rs:
packages/agent/src/local_agent/agent_loop.rs— orchestrates the turn; likely the place a routing-decision-to-context-assembly link would need to be wired
Related ADRs
../nodespace-docs/decisions/038-skill-mediated-tool-routing.md— two-stage routing pipeline, currently independent of context assembly../nodespace-docs/decisions/064-instruction-channel-doctrine.md— instruction channel doctrine; measurement methodology this issue should follow
Related Issues
- create_schema copies a retrieved schema's fields onto an unrelated new type (album_tracker gets is_returned/replacement_cost) #1846 (parent — found the mechanism, shipped the partial/probabilistic fix this issue closes the gap on)
Activity
malibio commentedon Jul 31, 2026
Before this issue's scope gets built out — one factual correction and one scope question.
Correction: no shared constant exists
This issue's body says #1846 applied a fix "to a shared
RELEVANT_ENTITY_TYPES_HEADERconstant." That constant doesn't exist. Checked directly:context_ops.rs:332—let header = "\nRELEVANT ENTITY TYPES:\n";(own literal)routing.rs:296—out.push_str(&format!("\nRELEVANT ENTITY TYPES:\n{meta}\n"));(separate literal)Two independently-written strings, not one shared source. This was exactly my second ask on #1846 — either a shared constant/rendering function, or a test tying the two sites together so they can't silently drift — and it looks like neither landed. Worth closing that gap before or alongside this issue's work, not after: if the eventual routing-aware fix only touches one of the two sites (easy to do by accident when they're two separate literals), this issue could ship believing it fixed the residual and leave the second site's field-list rendering untouched.
Concretely: extract the header (and ideally the field-list-vs-name-only rendering logic this issue is about to add) into one function both sites call, before or as part of implementing the routing-aware fix. Otherwise this issue's own "apply the fix at both sites" requirement is exactly as easy to half-do as #1846's was.
Scope question, not a blocker
This issue proposes reordering the pipeline so context assembly depends on the routing decision — a real architectural change (per your own Architecture Impact section, likely an ADR-038 note/amendment). That's a meaningfully bigger lift than #1846's structural fix, to close a 1-in-5 residual that #1846 already reduced from "always" to "occasionally."
Worth a explicit gate before implementing the reorder: is 80% clean acceptable as a shipped state for now (documented, tracked, revisit if it proves worse in practice), or is the 1-in-5 rate actually causing enough downstream damage (silent bad schemas) to justify the pipeline change now? I don't have a strong view either way, but per ADR-064's own methodology this issue cites, I'd want that judgment made explicitly rather than assumed by the issue simply existing. If the answer is "fix it now," proceed as scoped. If it's closer to "nice to have," this might sit better as a lower-priority follow-up than an active stream.
malibio commentedon Jul 31, 2026
Closing as not worth chasing further.
#1846's fix (shipped in PR #1859) reduced create_schema field contamination from "always" to 1-in-5 via a structural fix (shared header constant, anti-copy instruction at both render sites). ADR-064 already documents that prompt/context-level interventions on this locked 4B model (
gemma-4-e4b-q4km) are probabilistic, not deterministic — this issue would be spending real engineering effort (reordering context assembly to depend on routing output, a genuine architectural change per this issue's own proposed solution) to chase the last 20% on a model-behavior problem, not a code-correctness one.If the residual rate turns out to matter in practice (e.g. shows up repeatedly in real usage, not just synthetic trials), reopen with fresh evidence at that point. For now, closing to stop the baton-pass pattern — #1846 → #1858 → (would-be) #1860 — and keep the agent-prompting backlog converging rather than branching.
Stop create_schema from copying an unrelated retrieved schema's field…