Repository navigation
Description
Overview
Measurement (originally #1817, re-measured at higher power in #1834) found that enriching the per-turn context block with one-hop related schemas — schemas reachable via a relationship from a directly-retrieved schema, even when the related schema never matched the user's message itself — measurably improves node-type selection on queries that name no type at all. Example: retrieving customer alone currently gives the model no way to know invoice exists; the model has no reachable path to the right node_type for "What does Acme Corp still owe me?" because nothing in the message names an invoice.
This issue implements that enrichment in production.
Evidence
| run | baseline | + one-hop related | n | delta |
|---|---|---|---|---|
| #1817 | 0% (0/9) | 33% (3/9) | 9 | — |
| #1834 | 0% (0/36) | 27.8% (10/36) | 36 | +27.8pp |
#1834 re-ran against a pre-registered decision rule (n>=30, signal if delta >= 20pp) and a wider, multi-hub schema corpus (6 distinct retrieved-schema hubs, up from 1), so the result isn't an artifact of one corpus shape.
Token cost: +25 average prompt tokens (463 -> 488, about +5%) in the measurement harness. This is much smaller than the raw context-block character count implied (block itself roughly doubled, 83 -> 168 chars) because the block is a small fraction of the full assembled prompt once system identity and tool schemas are included.
Architecture Impact
No ADR is reversed. ADR-064 defines the "context block" as channel 4 of the local agent's instruction channels and assigns it per-turn schema relevance — this issue adds content within that channel's existing scope, not a new channel.
ADR-064 does record a directly relevant caution worth weighing here: its "volume harms" evidence found the full resident prompt scored 50% vs. 73% for a much smaller identity-only prompt on cases targeting the prompt's own rules, with dilution as the mechanism. That measurement was about resident prose (channel 1), not the context block (channel 4), and the measured token increase here is modest (~5%) rather than the prompt-size-order-of-magnitude difference ADR-064 measured — but it's the applicable lesson for why this was measured before being implemented rather than shipped on intuition, and why this issue's acceptance criteria include a check that this change doesn't regress accuracy on scenarios the context block already handles correctly today.
Proposed Solution
Add one-hop related-schema traversal to packages/core/src/ops/context_ops.rs:150 (format_for_prompt), which currently emits only the directly-retrieved schemas' field names.
Scope, matching what was actually measured:
- Related schemas are rendered name-only — schema id and display name, no field names, no field types, no relationship labels. The measurement harness's
render_with_relatedrenders related schemas this way specifically (contrast with the directly-retrieved schemas, which keep their existing field-names rendering). Field types and relationship-name enrichment were separately measured in Measure whether context-block enrichment (types, relationships, related schemas) helps #1817 and found null/harmful — they are explicitly out of scope for this issue. - No recursive expansion. Only schemas one hop from a directly-retrieved schema are surfaced; a schema reachable only via a related schema (two hops) is not included.
- Traversal is bidirectional: a schema that declares a relationship to a target makes that target reachable (outgoing), and a schema that is only ever the target of another schema's relationship must also reach back to the declaring schema(s) (incoming). This is required, not optional — a hub-shaped schema like
customerhas no outgoing relationships of its own, only incoming ones frominvoice/freelance_gig/etc. A one-directional (outgoing-only) traversal misses this case entirely and was the exact bug the measurement harness's validation gate caught before any scored generation ran (debug_assert_arms_differinnodespace-nlp-experiment/src/context_enrichment_related.rs). - Data source:
SchemaNode::relationships(packages/nodespace-types/src/schema.rs) already carries this — no new storage or schema changes needed, this is a rendering change only.
Acceptance Criteria
-
format_for_promptincontext_ops.rsrenders aRELATED (via relationship, not directly matched):section (or equivalent) listing one-hop schemas reachable from the directly-retrieved set, name-only - Traversal is bidirectional (outgoing relationship declarations AND incoming relationship declarations both make a schema reachable)
- No recursive expansion beyond one hop
- A schema already in the directly-retrieved set is never duplicated into the related section
- Unit test covering the bidirectional-reachability case specifically (a schema with only incoming relationships must still surface schemas that point to it)
- Unit test confirming a schema with no relationships at all renders no related section (no-op case, avoids an empty/misleading block)
- Regression check: existing scenarios where baseline (pre-change) node-type selection was already correct do not regress after this change — the concern ADR-064's volume-harms evidence raises
- Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Reference Files
- context_ops.rs:
packages/core/src/ops/context_ops.rs:150—format_for_prompt, currently field-names-only for directly-retrieved schemas; add the related-schema pass here - schema.rs:
packages/nodespace-types/src/schema.rs—SchemaNode::relationships, the existing data source to traverse - Reference rendering:
render_with_relatedin the disposable measurement harness (nodespace-nlp-experiment/src/context_enrichment_related.rs, not part of this repo) implements the same bidirectional one-hop traversal and rendering shape this issue asks for — useful as a worked reference for the traversal logic, not as code to import
Related Issues
- Re-measure one-hop related-schema enrichment at higher power (0%->33% at n=9 in #1817) #1834 (measurement that produced this issue)
- Measure whether context-block enrichment (types, relationships, related schemas) helps #1817 (original three-axis measurement)
Activity
malibio commentedon Jul 31, 2026
Frontend baseline: 171 test files passed, 4112 tests passed (45.74s).