Skip to content

create_node discards user-supplied schema field values: the guidance referenced a structure absent from the prompt (#1841) - #1847

Merged
malibio merged 5 commits into
mainfrom
issue-1841-create-node-properties
Jul 31, 2026
Merged

malibio merged 5 commits into
mainfrom
issue-1841-create-node-properties

Conversation

@malibio

@malibio malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Closes #1841

Problem

create_node persisted a bare shell — content and type only — discarding every schema field value the user supplied in the same message:

create_node [fields=0]
emitted:   {"content":"Laser Cutter Check Out Record","node_type":"equipment_item"}
persisted: { "equipment_item": { "_schema_version": 1 } }

Root cause — not what the issue proposed

The issue placed this at ADR-064 rule 5 (prose), on the basis that the call surface was fine, and named two candidate prose fixes. Reading the verbatim prompt via NODESPACE_PROMPT_DUMP showed a different cause.

The Node Creation guidance refers to schema_metadata six times — "Read the fields array from schema_metadata", "Required fields (required=true) MUST be included", "the field name exactly as it appears in schema_metadata fields[].name". All six occurrences in the prompt are the guidance mentioning the name. None is an actual payload. No schema_metadata object, no fields array, no required flag existed anywhere in the model's context.

What the model actually received was one line:

RELEVANT ENTITY TYPES:
- equipment_item: Equipment Item (is_returned, replacement_cost)

context_ops.rs mapped fields to names only, discarding field_type and required — both already present on SchemaField. Every field-population instruction was therefore unsatisfiable, and the model fell back to the two parameters it could ground (content, node_type) — exactly the two it emitted. That is rule 1 (context surface), not rule 5.

Also ruled out: the tool schema offers properties correctly typed, and the grammar from #1844 is derived from the tool schemas and constrains syntax, not which optional fields are chosen.

Changes

  1. context_ops.rs — the actual fix. Render each field's name, type, and required-ness, giving the guidance's instructions a referent.
  2. skill_pipeline.rs — repoint the guidance's five schema_metadata references at RELEVANT ENTITY TYPES, and state the consequence of omission explicitly.
  3. tools.rs — de-hedge the description (the issue's candidate 1): "Optionally pass 'properties'" → "Always pass 'properties' with every schema field value the user supplied."
  4. Corrected the stale context_ops.rs module doc claiming entity types are discovered via search_skills returning schema_metadata — the claim that made the phantom referent look correct.

Verification

Isolated daemon (NODESPACE_HOME, served_db_path confirmed), purged DB, rebuilt daemon, E4B, n_ctx 32768.

after:  create_node [fields=1]
emitted:   {"content":"laser cutter checked out on the 12th","node_type":"equipment_item","properties":{"replacement_cost":2400}}
persisted: { "equipment_item": { "_schema_version": 1, "replacement_cost": 2400 } }

Verified against the persisted node, not just the tool call.

bun run eval:agent: 9/12, up from the honest post-#1839 baseline of 8/12. Scenario 4 passes its minProperties assertion.

Attribution caveat: all three changes shipped together, so this repro does not isolate which carries the effect. The rendering change is primary on mechanism — rewording cannot fix an instruction whose referent does not exist — but that is reasoning, not measurement, and n=1 on a nondeterministic model.

AC3: 8d/8e are not downstream of 8c

The issue proposed one fix might clear 6, 8d and 8e. Measured, it does not — three separate causes:

  • 8c passes but still stores zero properties; its expectation is a bare toolOnce with no minProperties, so it scores green on this very bug
  • 8d claims "I have created a new Venue Tracker node" while calling zero tools — a hallucinated success
  • 8e asks for clarification — a routing/confidence failure
  • 6 asks for a node ID instead of calling resolve_query — resolve_query must return a resolved node, not query fragments #1637's handoff gap

8c cannot store the artist because album_tracker was created with is_returned/replacement_cost — a separate, pre-existing schema-contamination bug, filed as #1846. I tested explicitly whether this PR caused it (rendering types could plausibly make a retrieved schema a more copyable template): pre-fix bd29598f and post-fix produce identical contaminated fields, so it is not caused here.

Testing

  • bun run test:all — exit 0, 171 files / 4112 frontend tests, no new failures vs baseline
  • bun run quality:fix — clean, no unrelated reformatting
  • New format_for_prompt_marks_required_fields test covers the required-flag path; existing schema-block test updated to the new format
  • Pre-push gate (test:all + cargo build + e2e) passed

Note: packages/agent/tests/search_skills_latency.rs benches fail locally against llama3.1:8b needing a live Ollama — confirmed identical on pre-fix bd29598f, and not part of test:all.

🤖 Generated with Claude Code

…e_node can populate properties (#1841)

The node-creation guidance instructs the model to read fields[].name and to
treat required=true fields as mandatory in the properties map, but the entity
block rendered field NAMES only. The referent for those instructions did not
exist in the model's context, so it fell back to the two parameters it could
ground (content, node_type) and omitted properties entirely, persisting bare
shells.

- context_ops: render name, type, and required-ness per field
- skill_pipeline: point the guidance at RELEVANT ENTITY TYPES rather than the
  absent schema_metadata structure
- tools.rs: de-hedge create_node's properties description

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

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1847

Review Type: Initial Review (no prior reviews or comments on the PR)

Scope reviewed: origin/main...HEAD, commit 3902a742 — 3 files, +71/−16.


Summary

This is a net-positive change and a materially better diagnosis than the issue proposed. The issue asserted the cause was ADR-064 rule 5 (prose) and offered two prose candidates; the PR shows it was rule 1 (context surface) — the guidance conditioned properties population on schema_metadata / fields[].name / required=true, none of which existed in the model's prompt. I verified that independently and it holds. Correcting a wrong hypothesis with evidence, and writing the correction up as such rather than quietly shipping the fix, is the behavior you want.

The change is small, cohesive, sits at the right layer, uses data already on SchemaField, and both changed test modules pass locally.

I have one substantive finding (🟡): this PR fixes one of two RELEVANT ENTITY TYPES producers. The other, in routing.rs, is on the same live code path, renders into the same assembled prompt, and still emits the old name-only-plus-type format with a different separator — so the model can now receive the same block twice in two different notations, and the routing one still never renders required. That is a real gap in the fix, not a style point. Details below.


Requirements Check (issue #1841)

📝 Note (good practice): the separately-discovered schema-contamination bug was filed as #1846 rather than folded in, and a pre/post control on bd29598f was run to prove this PR didn't cause it. That control is exactly the right instinct — rendering types could plausibly have made a retrieved schema a more copyable template, and that was tested rather than assumed.


Code Review Findings

🟡 Important: a second RELEVANT ENTITY TYPES renderer is unfixed and can co-occur in the same prompt

📁 packages/agent/src/local_agent/routing.rs:295-296, 302-340
📁 packages/agent/src/local_agent/agent_loop.rs:616-627, 660-663

context_ops.rs is not the only producer of a RELEVANT ENTITY TYPES: block. routing.rs::render_schema_metadata emits one too:

out.push_str(&format!("\nRELEVANT ENTITY TYPES:\n{meta}\n"));
...
_ => Some(format!("{name} ({ty})")),
lines.push(format!("- {type_id}: {}", fields.join(", ")));

And in agent_loop.rs the two are concatenated into one system prompt:

let system_content = match &candidate_block {
    Some(block) => format!("{base_system_content}\n\n{block}"),

base_system_content carries the context_ops block (via workspace_context); candidate_block is the routing.rs one. This is the local path, not just openai-compat — render_candidates_for_prompt is called unconditionally at line 627 whenever session.routing_disabled is false, which is the normal E4B case.

Three concrete consequences:

  1. Two notations for the same concept in one prompt. After this PR the model may see - equipment_item: Equipment Item (is_returned: boolean; replacement_cost: number) from one producer and - equipment_item: is_returned (boolean), replacement_cost (number) from the other. Same header, same types, different punctuation and different name/type order.
  2. The routing renderer still never emits required. schema_metadata built in skill_ops.rs:186-205 copies only name, type, and enum_values — it drops required at construction. So the guidance's new "fields marked required MUST be included" instruction has a referent in one block and no referent in the other — a smaller instance of the exact bug this PR fixes.
  3. The routing renderer has something context_ops lacks: enum_values. context_ops renders field_type but never expands enum options from core_values/user_values, so a status: enum field arrives without its legal values.

Recommendation: not necessarily in this PR — the measured win is real and I would not block on it. But these two renderers should converge on one function and one format, and required should be carried into schema_metadata at skill_ops.rs:186. Worth a follow-up issue; if you'd rather keep this PR to the measured change, that's a defensible call, but the divergence should be recorded rather than left to be rediscovered.

Engineering principle: DRY applies to prompt surfaces as much as to code. Two independent renderers for one model-facing contract will drift, and prompt drift is invisible to the type system and only surfaces as nondeterministic model misbehavior — which is precisely the class of bug that cost this issue a full investigation cycle.

🟡 Important: tools.rs promises title_template "shown in ENTITY TYPES" — it isn't

📁 packages/agent/src/local_agent/tools.rs:498
📁 packages/core/src/ops/context_ops.rs:248-278

The (pre-existing, untouched) clause reads: "If the schema has a title_template (shown in ENTITY TYPES), include those template fields in 'properties'."

SchemaNode does carry title_template (schema_node.rs), and skill_ops.rs:213-215 puts it into schema_metadata — but context_ops.rs never renders it, and routing.rs::render_schema_metadata doesn't either. So this is the same class of defect the PR just fixed: an instruction pointing at a structure the model cannot see.

This is pre-existing and out of scope, so 🟡 not 🔴. But it's worth flagging now precisely because this PR establishes the pattern for finding it — and context_ops already has the value in hand, so rendering it is a one-line addition to the loop you're already editing.

🟢 Verified correct: required.unwrap_or(false)

📁 packages/core/src/ops/context_ops.rs:263

I checked this against the rest of the codebase as asked. It is consistent with the authoritative interpretation: crud.rs:1705 uses the identical field.required.unwrap_or(false) to decide whether to enforce a required field at write time. Rendering therefore agrees with validation — None means not-required in both places, so the prompt cannot claim a field is mandatory that crud would not enforce, or vice versa. core_schemas.rs:1344 confirms core schemas set Some(false) explicitly. No issue.

🟢 Verified: rendering-format change is safe for other consumers and for truncation

📁 packages/core/src/ops/context_ops.rs:270-274

I grepped for parsers keyed on the old comma format. Nothing parses this block — it is terminal output into a prompt string; the only consumers are the model and the two tests in this file. No frontend, CLI, or Rust code splits on it. The separator change is safe.

On the separator itself: ; between fields with , required inside a descriptor is the right choice, not a cosmetic one — with comma-only separation, amount: number, required, reference: string is genuinely ambiguous about whether required is a field name. The two-level delimiter removes that ambiguity. Good call.

Truncation (:276-280) remains sane: the per-line out.len() + line.len() > max_chars check is unchanged and still breaks on whole lines, so longer descriptors mean fewer types rendered, never a half-rendered line. format_for_prompt_truncates_on_budget still passes.

Token cost is a real but small regression — roughly 3-5 tokens per field. Justified: it buys the referent the entire fix depends on, and per my notes on the resident-prompt work, dilution risk comes from bulk irrelevant prose, not from densifying a block the guidance directly references.

🟢 Verified: test coverage is adequate; the !contains("(") assertion still holds

📁 packages/core/src/ops/context_ops.rs:382-415, 420-430

I ran cargo test -p nodespace-core --lib context_ops — 19/19 pass, including the new format_for_prompt_marks_required_fields. Also ran cargo test -p nodespace-agent --lib — 380/380 pass.

Specifically on your question: format_for_prompt_schema_no_fields's assert!(!output.contains("(")) still holds, because sample_schema("invoice", "Invoice", &[]) produces an empty field_descriptors, which takes the String::new() branch and emits no parenthesis. Verified by execution, not inspection.

The new test is well-constructed — it asserts the positive (amount: number, required), the negative (!contains("reference: string, required")), and that the unmarked field is still present with its type (reference: string;). That third assertion is what stops a naive implementation from passing by dropping unmarked fields. Good test design.

🟢 Guidance prose is now accurate — with one caveat about delivery

📁 packages/agent/src/skill_pipeline.rs:306-323

I grepped the changed guidance for surviving references to absent structures: all five schema_metadata mentions are gone, replaced with "the RELEVANT ENTITY TYPES block". The remaining schema_metadata hits in the repo are legitimate (the skill_ops builder, agent_types struct field, routing.rs renderer, tests) — none is guidance prose pointing at a phantom.

The example was correctly updated in lockstep to the new notation (widget: Widget (label: string; quantity: number; ...)), so the demonstrated format matches what's actually rendered. That lockstep update is easy to forget and would have re-created the bug in miniature.

Caveat worth stating explicitly in the PR: this guidance is DB-seeded, and seed_nodes_from_templates (node_service/mod.rs:1341-1375) skips seeds whose _seed.key already exists. So the skill_pipeline.rs half of this fix does not reach an existing install without a DB purge — which is exactly what the verification run did (purged DB + rebuilt daemon), so the measurement is valid. But it means change #2 of the three is inert for any developer who pulls this without purging, and their local behavior will differ from the eval. This is the known seeded-guidance staleness gap, not a defect introduced here.

🟢 Attribution caveat is honestly scoped — not over-claimed

You asked me to assess whether the conclusion is over-claimed relative to n=1 plus a 12-scenario eval. It is not. The PR states plainly: "all three changes shipped together, so this repro does not isolate which carries the effect... that is reasoning, not measurement, and n=1 on a nondeterministic model."

The mechanistic argument for the rendering change being primary is genuinely strong and doesn't rest on the n=1: rewording an instruction cannot fix an instruction whose referent does not exist. Changes #2 and #3 are prose edits to text the model was already receiving and already failing to act on; only #1 adds information that was absent. That's a structural argument, and the PR correctly presents it as such rather than dressing it up as measurement.

The eval delta (8→9) is weak evidence individually but corroborating, and the baseline is stated as the honest post-#1839 number rather than the pre-#1839 inflated one. I'd rather see this level of epistemic hygiene than a confident claim.

🟢 Project standards — clean

  • No lint suppression, no #[allow(dead_code)], no #[deprecated] in the diff.
  • No backward-compat shims — old format deleted outright, correct for greenfield.
  • No issue-number references in comments or docs. I checked all three files specifically as asked. The new context_ops.rs comments describe the behavior and mechanism directly ("the node-creation guidance instructs the model to read fields[].name...") without citing create_node discards user-supplied schema field values: instances persist as bare shells (guidance/prose, not tool schema) #1841. The single # match in skill_pipeline.rs:131 is pre-existing example prose ("Invoice #001"), not a reference.
  • The module-doc correction at context_ops.rs:4-16 is a real improvement: the old text asserted entity types were discovered on-demand via search_skills returning schema_metadata — the stale claim that made the phantom referent look correct. Deleting a comment that actively misleads is worth as much as the code fix.

Recommendation: APPROVE

The diagnosis is correct and independently verified, the fix is minimal and at the right layer, tests pass, standards are clean, and the uncertainty is disclosed rather than papered over.

The 🟡 findings are both about adjacent surfaces rather than defects in this diff: the routing.rs duplicate renderer and the unrendered title_template. Neither should block a change that measurably fixes the reported bug — but the duplicate renderer in particular deserves a follow-up issue, because it is the same failure mode this PR just paid to diagnose, and leaving two divergent producers of one model-facing block is how it recurs.

Suggested follow-up: converge context_ops::format_for_prompt and routing::render_schema_metadata on one renderer, carry required into schema_metadata at skill_ops.rs:186, and render title_template and enum values in the unified block.

@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.

Recommendation: APPROVE (submitted as a comment — GitHub blocks self-approval on your own PR). Full report in the review comment above.

Diagnosis independently verified: the guidance's schema_metadata/fields[].name/required=true referent genuinely did not exist in the assembled prompt, and context_ops.rs was the field-metadata source on the creation turn. required.unwrap_or(false) matches the enforcement semantics in crud.rs:1705. No consumer parses the entity block, so the separator change is safe. Tests pass: 19/19 context_ops, 380/380 agent lib; format_for_prompt_schema_no_fields's !contains("(") still holds.

Two non-blocking 🟡 follow-ups on adjacent surfaces: routing.rs::render_schema_metadata is a second, unfixed producer of the same RELEVANT ENTITY TYPES header that co-occurs in the same prompt with a different format and still no required; and tools.rs promises title_template is "shown in ENTITY TYPES" when no renderer emits it — the same phantom-referent class this PR fixes.

malibio and others added 2 commits July 31, 2026 08:57
…required and title_template through

Review of #1847 found the workspace-context block is only one of two producers
of this heading. agent_loop concatenates the routing candidate block into the
same system prompt, so a single prompt carried two spellings of one concept:
'(is_returned: boolean; replacement_cost: number)' from context_ops and
'is_returned (boolean), replacement_cost (number)' from routing, the latter
three times. Confirmed against a captured prompt, not inferred.

The routing renderer also never emitted required-ness at all — it was dropped
at construction in skill_ops — which is the same phantom-referent defect this
branch fixes, surviving in the other half of the prompt. And create_node's
description promises title_template is 'shown in ENTITY TYPES' while neither
renderer emitted it.

- skill_ops: carry required into schema_metadata
- routing: same 'name: type[, required]' notation, semicolon-separated,
  enum values preserved as 'name: enum (a, b)'
- both renderers: emit title_template, giving the tool description a referent

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

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the 🟡 second-renderer finding — it was right, and confirmed against a real prompt

Pushed 210c3340 + formatting (c9af4f6f).

Verified before fixing. Captured a live system prompt with NODESPACE_PROMPT_DUMP rather than reasoning from the call graph. One prompt carried four rendered entity blocks in two notations:

- equipment_item: Equipment Item (is_returned: boolean; replacement_cost: number)   <- context_ops (fixed)
- equipment_item: is_returned (boolean), replacement_cost (number)                  <- routing.rs  x3

So the review's read was exactly right: agent_loop.rs concatenates both, and the routing block appeared three times (once per eligible candidate), outnumbering the one I had fixed.

Changes

  1. skill_ops.rs — carry required into schema_metadata. It was dropped at construction, so the routing renderer could not have emitted it. That is the same phantom-referent defect this branch fixes, surviving in the other half of the prompt.
  2. routing.rs — same name: type[, required] notation, semicolon-separated. Enum values preserved, re-spelled status: enum (todo, done) to fit the shared shape.
  3. Both renderers — emit title_template, closing the 🟡 gap where tools.rs:498 promises it is "shown in ENTITY TYPES" while nothing emitted it.

After

- equipment_item: Equipment Item (is_returned: boolean; replacement_cost: number)
- equipment_item: is_returned: boolean; replacement_cost: number   x3

Field notation is now identical across all four. The residual difference is that context_ops prefixes the display name — deliberate, since that block names types while the routing block scopes a candidate's procedure.

End-to-end on the rebuilt daemon: create_node [fields=2], persisting both is_returned: false and replacement_cost: 2400.

A correction to my own earlier numbers

While re-verifying I found the daemon I measured mid-investigation was stale — built during the pre/post-fix control for #1846 and never rebuilt after I restored the sources. One intermediate reading in the issue comments came from pre-fix code. It did not affect the reported results (the 9/12 eval and the original verification both ran on correctly-built daemons, and the eval records evalCommit in its provenance), but the mistake is worth stating rather than quietly fixing. The re-verified result is stronger than what I first reported: fields=2, not fields=1.

Tests

  • routing.rs — two tests updated to the shared notation; new schema_metadata_marks_required_and_renders_title_template
  • context_ops.rs — new format_for_prompt_renders_title_template
  • cargo test -p nodespace-core --lib 1041 passed · -p nodespace-agent --lib 381 passed
  • bun run test:all exit 0 · quality:fix clean · pre-push gate passed

Not done here

The review's suggested follow-up — collapsing the two renderers into one shared function — I have deliberately left out. They now agree on notation and content, but they read from different sources (SchemaNode vs schema_metadata JSON) and serve different callers, so unifying them is a refactor with its own risk surface rather than part of this fix. Worth its own issue if you want it.

I have not re-run bun run eval:agent after this commit — it is ~10 minutes of inference and the change is notation-only on a path already verified end-to-end. Say the word if you would like the score re-confirmed before merge.

The review noted the routing renderer expands core_values/user_values while
context_ops did not, so a 'status: enum' field reached the model without its
legal values — the model then invents one and the write path rejects it. Same
defect class as the missing type and required-ness this branch fixes: an
instruction with no referent.

Both renderers now emit 'name: enum (a, b)'. Covered by
format_for_prompt_renders_enum_values.

Addresses reviewer recommendations from PR #1847 review.

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

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/address-review summary

Ran the review systematically against the posted findings. I had addressed the two headline 🟡 items ad-hoc before running this properly; the pass caught three items I had missed, buried in sub-points rather than headline findings.

✅ Addressed (6)

Sev Recommendation Commit
🟡 Second renderer unfixed — converge notation 210c3340
🟡 required dropped at construction in skill_ops.rs:186 210c3340
🟡 title_template promised by tools.rs:498, never rendered 210c3340
🟢 context_ops lacks enum values (missed on first pass) 626060a8
📝 Follow-up issue for renderer convergence (missed) #1848
📝 Seeded-guidance caveat stated in the PR (missed) below

Enum values were consequence #3 of the 🟡 finding and I skipped them. A status: enum field reached the model without its legal values, so the model invents one and the write path rejects it — the same defect class as the missing type and required-ness. Both renderers now emit name: enum (a, b). Covered by format_for_prompt_renders_enum_values.

📝 The seeded-guidance caveat, stated explicitly as the review asked

The skill_pipeline.rs half of this fix is DB-seeded, and seed_nodes_from_templates (node_service/mod.rs:1341-1375) skips seeds whose _seed.key already exists. Anyone pulling this branch without purging their DB gets the code changes but not the guidance change, and their local behavior will differ from the eval. The verification runs purged the DB and rebuilt the daemon, so the measurement is valid — but the discrepancy is real for local dev. Pre-existing gap, not introduced here.

⏭️ Skipped (1)

Collapsing both renderers into one shared function. They read different sources (SchemaNode vs the schema_metadata JSON projection) and serve different callers, so this is a refactor with its own risk surface rather than a mechanical extraction. The review said "not necessarily in this PR" and "if you'd rather keep this PR to the measured change, that's a defensible call."

Revisit condition: filed as #1848 with acceptance criteria, including the open question of whether the block should appear up to four times per prompt at all — flagged to be measured, not assumed.

🧪 Tests

  • cargo test -p nodespace-core --lib 1042 passed · -p nodespace-agent --lib 381 passed
  • 9 renderer tests pass incl. enum values, required-ness, title_template
  • bun run test:all exit 0 · quality:fix clean · pre-push gate passed

One honest note on verification: I tried to confirm enum rendering end-to-end on a live model and could not, because create_schema fails on enum creation for unrelated model-side reasons (emitting an enum with no values, then quote-mangled JSON keys). That is an existing weakness in schema creation; this change only affects reading schemas back into the prompt, which the unit tests cover deterministically. Worth its own issue if enum schema creation matters.


Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Three commits have landed since the reviewed 3902a742, and they are not cosmetic — a new skill_ops.rs field in the schema_metadata contract, a rewritten routing.rs renderer, and enum expansion in context_ops. Two files touched here (routing.rs, skill_ops.rs) were not in the original review's scope at all. That is new logic on the live prompt path, written in response to feedback and not yet examined by anyone.

@malibio

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1847 (Re-Review)

Review Type: Re-Review (delta pass)
Scope: 3902a742..HEAD — 3 commits, 3 files, +135/−8. Commit 3902a742 was reviewed and approved separately and is not re-litigated here.

Two files in this delta — routing.rs and skill_ops.rs — were not in the original review's scope at all, so I reviewed them fresh rather than as a diff.


Previous Review Summary

Sev Prior finding Status
🟡 Second renderer (routing.rs) unfixed, divergent notation ✅ Fixed in 210c3340
🟡 required dropped at construction (skill_ops.rs:186) ✅ Fixed in 210c3340
🟡 title_template promised by tools.rs:498, never rendered ✅ Fixed in both renderers
🟢 context_ops lacked enum values that routing had ✅ Fixed in 626060a8
📝 Record the divergence as a follow-up ✅ #1848 filed, OPEN, with ACs
📝 State the seeded-guidance caveat in the PR ✅ Stated explicitly
⏭️ Converge the two renderers into one function Skipped — defensible, see below

Requirements Check (issue #1841)

The delta does not change the AC verdicts from the initial review; it strengthens AC2.

📝 On the self-correction: the PR author disclosed that a daemon measured mid-investigation was stale, and that one intermediate reading came from pre-fix code. Volunteering an invalidated measurement that nobody would have caught, when the corrected result is more favorable, is the behavior that makes the other numbers in this PR trustworthy. Noted approvingly.


Code Review Findings

✅ Verified: skill_ops.rs conditional insertion is correct, and nothing downstream breaks

📁 packages/core/src/ops/skill_ops.rs:186-200

Conditional insertion (required present only when true) is the right choice here, not a shortcut:

  1. It matches the sibling enum_values convention three lines below, which is likewise omitted when empty.
  2. It matches SchemaField's own wire contract — packages/nodespace-types/src/schema.rs:43-44 marks required with #[serde(skip_serializing_if = "Option::is_none")]. Emitting "required": false would make the JSON projection more verbose than the source type.
  3. schema_metadata is a prompt-bound projection, not a persisted or API-versioned structure. Absent-means-false costs nothing and saves tokens on every non-required field, which is the majority.

Consumer check (I grepped this specifically, as asked): schema_metadata is consumed by routing.rs::render_schema_metadata, the agent_types.rs:584 struct field (typed serde_json::Value, so a new key cannot break deserialization), tools.rs:2425 (passes it through opaquely), and tests. No TypeScript, Svelte, or Tauri consumer exists — zero hits across packages/ and scripts/. Adding a key is safe.

The reader is correctly defensive: .and_then(|v| v.as_bool()).unwrap_or(false), so a legacy entry without the key, or with a non-bool, renders as not-required. That agrees with crud.rs:1705's enforcement semantics — the prompt cannot claim a field is mandatory that the write path would not enforce.

✅ Verified: routing.rs renderer — malformed-entry skip preserved, key names match

📁 packages/agent/src/local_agent/routing.rs:304-355

I checked each risk you flagged:

  • Malformed-entry skip is intact. The let ... else { continue; } on type_id is unchanged, and the field-level ? still sits inside filter_map, so it skips one field rather than the type. I confirmed by execution with a temporary probe (since removed — working tree is clean): a metadata array mixing a type_id-less entry with a valid one renders - ok: n: string, dropping only the malformed entry. The existing regression test a_malformed_metadata_entry_does_not_discard_the_others still guards this.
  • title_template reads a key skill_ops actually writes. Confirmed both ends: skill_ops.rs:214-216 writes entry["title_template"], routing.rs:349 reads entry.get("title_template"). Same level (entry, not field), same spelling. This was the single highest-risk item in the delta — a renderer reading a key nobody writes would have silently re-created the exact phantom-referent bug this PR exists to fix — and it is correct.
  • Enum rendering survives the rewrite. name: enum (a, b), verified by schema_metadata_renders_enum_values (updated) and by probe.
  • Separator ; matches context_ops. Confirmed identical.

The restructure from match-returning-Option to let mut descriptor = match ... then push is the right shape — required is orthogonal to enum-ness, so composing suffixes beats a four-arm match. Low complexity, no nesting added.

✅ Verified: context_ops enum iterator chain is correct

📁 packages/core/src/ops/context_ops.rs:265-274

You asked specifically whether .iter().chain(...).flatten() silently drops one side. It does not. Both fields are Option<Vec<EnumValue>> (schema.rs:38-40). Option::iter() yields an iterator of 0-or-1 &Vec<EnumValue>; chaining gives 0-2 vec refs; .flatten() flattens each into its elements. Both are included, and None on either side contributes nothing rather than short-circuiting.

Ordering is core-then-user, deterministic, and matches skill_ops.rs:198-206's explicit extend(core) then extend(user) — so the two renderers list enum values in the same order, which matters because they land in one prompt. Proven by format_for_prompt_renders_enum_values, which asserts (open, blocked) with a core value and a user value.

Empty-enum case renders sensibly: the values.is_empty() guard falls back to status: enum with no trailing (). Note the two renderers gate differently — context_ops on values-non-empty, skill_ops on field_type == "enum" — but I checked core_schemas.rs and every field carrying core_values/user_values is field_type: "enum", so the conditions coincide in practice and neither can emit a stray ().

✅ Verified: guidance prose is still accurate for both renderers

📁 packages/agent/src/skill_pipeline.rs:306, 312

This was the sharpest question, since the PR's thesis is that guidance must not describe things that don't exist. The claim reads "lists each type's fields as (name: type)".

It holds, and the example is the load-bearing part. (name: type) is stated as the base shape, and both renderers emit exactly that, with , required and (a, b) as suffixes onto it rather than replacements for it. The worked example at line 312 — widget: Widget (label: string; quantity: number; ...) — matches character-for-character what context_ops now produces, semicolons included. Models weight a concrete example far more heavily than a prose gloss, and the example is exact.

The residual gap is small and self-evident from context: prose says (name: type) while a required field renders amount: number, required. A model reading amount: number, required alongside the sentence "fields marked required" in the same paragraph has everything it needs. Not worth another commit.

🟢 Suggestion: routing renderer emits a dangling - type_id: for a zero-field type

📁 packages/agent/src/local_agent/routing.rs:344

When fields is absent or empty, format!("- {type_id}: {}", fields.join("; ")) produces a trailing-colon line with nothing after it:

- t2:
- t3:  [title_template: {x}]      <- note the double space

context_ops handles this case correctly — field_descriptors.is_empty() yields String::new() and renders - invoice: Invoice, guarded by format_for_prompt_schema_no_fields. The routing renderer has no equivalent guard.

Why this is 🟢 and not 🟡: it is currently unreachable. Zero-field schemas exist (core_schemas.rs:294 — text, date, etc.), but all are is_core: true, and skill_ops.rs:167-174 filters to !s.is_core when no node_types scope is declared. No seeded skill declares one today, so no zero-field type reaches this renderer.

It becomes reachable the moment a skill sets node_types to include a core type — which skill_ops.rs:150-154 explicitly documents as the recommended configuration ("Skills should set node_types to avoid this fallback as workspaces grow"). So this is latent breakage sitting on a documented growth path.

Recommendation: fold into #1848 rather than this PR — the convergence work will delete one of these two branches anyway, and fixing it here means writing a guard that #1848 immediately removes.
Engineering principle: two implementations of one contract diverge at the edges before they diverge in the middle. The happy paths were converged in 210c3340; the empty case is exactly where the seam remains, and it is the argument for #1848 rather than an argument against this PR.

🟢 Suggestion: [title_template: ...] notation is undescribed by the guidance

📁 packages/agent/src/local_agent/routing.rs:349, packages/core/src/ops/context_ops.rs:290-296

Both renderers now emit [title_template: {reference} - {amount}], and the guidance's TITLE paragraph does tell the model what a title_template means. But nothing tells it that the bracketed suffix is that template, and tools.rs:498's phrase is the vaguer "shown in ENTITY TYPES".

This is a much milder version of the bug this PR fixes — the referent now exists, it just isn't named by its rendered notation. Braces around field names make it fairly self-describing, and the initial-review finding (promise with no referent at all) is genuinely closed. Worth a one-clause tightening next time skill_pipeline.rs guidance is touched; not worth a commit or a DB purge on its own.

✅ Test coverage of the delta is adequate

Three new tests, two updated, all passing. I ran both suites: cargo test -p nodespace-core --lib context_ops → 21/21; cargo test -p nodespace-agent --lib routing → 30/30.

Coverage maps cleanly onto the delta: required in both renderers, title_template in both, enum values in both, notation change in the two updated assertions. The format_for_prompt_renders_enum_values test is well-built — it uses a core value and a user value, so it would catch a chain that dropped either side, which is precisely the failure mode you asked about.

Untested paths: the zero-field routing case above (unreachable today), and required: false explicitly present in schema_metadata — though the reader's unwrap_or(false) makes that behaviorally identical to absent.

📝 On the enum verification gap — acceptable

create_schema fails on live enum creation for unrelated model-side reasons, so enum rendering is unit-tested only. I consider that acceptable, for a specific reason: this change only affects reading an existing schema back into a prompt string. That path is pure, synchronous, dependency-free formatting, fully determined by its input — the class of code where a unit test is not a weaker substitute for an end-to-end run but an equivalent one. An E2E run would exercise the same format! calls with more moving parts and more ways to be flaky.

What is not covered is whether a model, shown status: enum (open, blocked), actually picks a legal value. That is a behavioral question the eval answers, not a test — and it is the right thing to defer to #1848's measurement.

The blocked-live-verification finding is itself worth filing: create_schema emitting an enum with no values and then mangling JSON keys on retry is a real defect on the schema-creation path. Recommend an issue so it isn't rediscovered.

✅ On skipping renderer convergence — defensible, correctly recorded

You asked me to assess this directly. The call was right.

The two renderers read genuinely different sources — context_ops walks a typed SchemaNode with Option<Vec<EnumValue>> fields, routing walks an untyped serde_json::Value projection where every access is a fallible get().and_then(). Unifying them is not extraction; it requires choosing a common input type, which means either parsing the JSON back into SchemaNode (adds a fallible step to the live prompt path) or degrading the typed path to Value (loses compile-time safety). That is a design decision with a real risk surface, and doing it inside a PR whose value is a measured bug fix would put a verified change behind an unverified refactor.

The initial review said this explicitly: "if you'd rather keep this PR to the measured change, that's a defensible call, but the divergence should be recorded." It was recorded — #1848 is open with ACs, including the open question of whether the block should appear up to four times per prompt at all, flagged to be measured rather than assumed. That is the correct disposition.

📝 On the 4-block duplication — not a blocker

One system prompt now carries 4 entity blocks (1 from context_ops + 3 from routing candidates), differing only in the display-name prefix. My assessment: not worth blocking on, and worth measuring rather than reasoning about.

The redundancy is pre-existing — 210c3340 did not create the duplication, it made the four blocks agree. Before this delta the model saw the same types in two notations, which is strictly worse than seeing them four times in one. Token cost is real but bounded by MAX_UNSCOPED_SCHEMA_METADATA.

The reason not to fix it by intuition: repetition of a key referent sometimes helps a small model, and #1827's finding was that dilution comes from bulk irrelevant prose, not from repeating a block the guidance directly cites. Whether 4 blocks beat 1 is an empirical question with a plausible answer in both directions. #1848 flagging it for measurement is the correct call.

✅ Project standards — clean

Comment quality in the delta is notably good: every new comment explains why (the model invents an illegal enum value; the guidance has nothing to key on) rather than what. That is the standard, and it is met.


Recommendation: APPROVE

The delta does what it claims. Both 🟡 findings from the initial review are properly closed — not papered over — and the fix went one level deeper than the review asked by correcting skill_ops.rs, where required was dropped at construction and without which the routing renderer could not have emitted it. The 🟢 enum sub-point that was missed on the first pass was caught by running the review systematically rather than from memory.

The two previously-unreviewed files hold up under fresh scrutiny. The highest-risk item — routing.rs reading a title_template key that skill_ops must write — is correct at both ends, and the malformed-entry skip that protects the whole block survived the rewrite. schema_metadata has no frontend or Tauri consumer, so the added key cannot break a contract outside Rust.

My two new findings are both 🟢: a dangling - type_id: line for zero-field types (unreachable today, becomes reachable on a documented configuration path — fold into #1848) and the undescribed [title_template: ...] notation. Neither should hold up a change that measurably fixes the reported bug and moves the eval 8/12 → 9/12.

Not merging — that call is yours.

@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.

Re-review (delta 3902a742..HEAD): APPROVE. Both prior 🟡 findings properly closed, plus the 🟢 enum sub-point and the two process items. The two previously-unreviewed files (routing.rs, skill_ops.rs) hold up under fresh scrutiny — title_template key names match at both ends, malformed-entry skip survived the rewrite, and schema_metadata has no non-Rust consumer. Two new 🟢 findings, neither blocking. Full report in the PR comment above. Not merging — that call is yours.

… block

A type with no fields rendered as '- type_id: ' — a trailing separator
promising a field list that never arrives, which is the malformed-prompt
class this branch exists to fix. context_ops already guards this; routing
did not.

Not reachable today (skill_ops filters to non-core schemas and zero-field
types are all core), but a skill scoping itself with node_types makes it so,
which skill_ops documents as recommended.

Covered by a_zero_field_type_renders_without_a_dangling_separator.

Addresses the re-review's first new finding. The second — that the
[title_template: ...] notation is not described by the guidance prose — is
deliberately skipped: the referent now exists, which was the defect, and the
braces are self-describing. Editing seeded guidance requires a DB purge to
take effect, so a cosmetic rewording is not worth re-seeding for.

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

malibio commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/address-review — re-review pass

Both new 🟢 findings triaged. Pushed ddc4fe8c.

✅ Addressed (1)

🟢 Dangling - type_id: for a zero-field type — routing.rs.

Fixed rather than deferred. The reviewer marked it unreachable today, and that is correct (skill_ops filters to !is_core, and zero-field types are all core) — but it becomes reachable as soon as a skill sets node_types, which skill_ops.rs:150-154 documents as recommended. A trailing separator promising a field list that never arrives is exactly the malformed-prompt class this branch exists to fix, and context_ops already guards it. Three lines to make the two renderers agree on one more edge, versus leaving a latent trap in a follow-up issue.

Covered by a_zero_field_type_renders_without_a_dangling_separator, which asserts the bare form, the absence of the dangling colon, and that the populated form is unaffected.

⏭️ Skipped (1)

🟢 [title_template: ...] notation not described by the guidance prose.

The defect was that the referent did not exist; it now does. The braces are self-describing, and the reviewer framed it as "a one-clause tightening next time guidance is touched." Editing skill_pipeline.rs guidance only takes effect after a DB purge (the seeded-guidance gap noted earlier in this PR), so a cosmetic rewording would ship inert for anyone who does not purge — cost without benefit.

Revisit condition: fold into the next substantive guidance edit, or into #1848 if the renderers are unified.

🧪 Tests

  • cargo test -p nodespace-agent --lib 382 passed (31 routing, +1 new)
  • bun run test:all exit 0 · quality:fix clean · pre-push gate passed

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The delta since the last review is a single three-line guard on an unreachable branch, plus one test. No logic change to any reachable path, no new API surface, no change to what the model receives for any schema that exists today. The re-review already examined the substantive work (routing.rs, skill_ops.rs, enum rendering) and approved it; this is the trivial-refactor case the loop is meant to terminate on.

The review cycle is complete. Both passes returned APPROVE, every 🟡 is closed, and the two skipped 🟢 items carry stated justifications and revisit conditions.

The PR is ready to merge — that call is the user's, not mine. Open follow-ups: #1846 (schema field contamination, pre-existing, proven not caused here) and #1848 (converge the two renderers; decide the 4-block duplication with measurement).

@malibio
malibio merged commit d9fb7ef into main Jul 31, 2026
2 checks passed
@malibio
malibio deleted the issue-1841-create-node-properties branch July 31, 2026 15:37
malibio added a commit that referenced this pull request Jul 31, 2026
SchemaField gained local_only, unique, and unique_case_insensitive while
PR #1847 was in review. That branch never saw them, so it merged green and
broke main on contact — the two test constructors added there no longer
compile.

Adds the three fields with their defaults. Renderer behavior is unchanged.

Note for later: local_only marks a field machine-bound for sync purposes, not
model-invisible, so the entity block advertising one would not be a leak. The
two fields that set it today are on the core ai-chat schema, which neither
renderer can reach (skill_ops filters to !is_core; context_ops renders only
semantically-retrieved user schemas).

Co-Authored-By: Claude <[email protected]>
malibio added a commit that referenced this pull request Jul 31, 2026
…1848) (#1856)

* Converge the RELEVANT ENTITY TYPES renderers on one shared function (#1848)

The block reaching the agent was produced by two independent renderers —
`context_ops::format_for_prompt` reading `SchemaNode`, and
`routing::render_schema_metadata` reading the `schema_metadata` JSON built
in `skill_ops`. #1847 aligned their output by hand; nothing kept them
aligned. That divergence caused #1841: guidance conditioned `properties`
population on field metadata only one renderer emitted, so the model saw an
instruction with no referent and dropped every user-supplied value.

Both paths now convert into `EntityTypeDescriptor` and render through
`entity_types_block::render_entity_types`. The descriptor is the choke
point — a field added to `SchemaField` reaches the prompt only through it,
so it cannot land in one path and not the other.

`skill_ops` now encodes its JSON *from* the same descriptor rather than
hand-writing a parallel projection. The wire shape is unchanged: it is the
model-facing `search_skills` response body, pinned by the routing latency
suites, so it stays a contract rather than becoming an internal detail.
Encode and decode sit adjacent as one reversible mapping.

Behaviour note: routing now renders a named type as `- id: Name (fields)`,
matching the workspace-context format. Production `schema_metadata` carries
`name`, but every existing routing fixture omitted it, so the format the
agent actually shipped was unasserted. Pinned by a new test.

Measurement for the duplication question, rather than an assumption: a
Stage-2 prompt carries 4 copies of the block (RETRIEVAL_TOP_K=3 candidates
plus workspace context), ~141 redundant tokens for a 2-schema workspace.
No seeded skill declares `node_types`, so every candidate takes the
unscoped branch and the copies are identical rather than differently
scoped — pinned by a test so the premise fails loudly if a seed scopes
itself later. De-duplication is left as a separate decision; this change is
behaviour-neutral on the block's content.

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

* Address review findings on the entity-block convergence (#1848)

The AC-2 guard did not guard. `both_prompt_paths_render_a_schema_identically`
derived both sides from one `from_schema` call, so it asserted round-trip
fidelity — already covered by the test above it — while its docstring
claimed it would catch a `SchemaField` addition wired into only one path.
The JSON side is now spelled out independently, as `skill_ops` emits it.
Verified by mutation: dropping `required` from the decoder now fails this
test, where before it passed.

The docstring no longer overclaims either. The structural guarantee is the
real one and does not depend on the test: a single `render_line` means a new
field reaches both paths or neither. The test pins the conversion seams on
either side of that.

Corrected the `enum_values` note. The claim that the widened condition is
unobservable holds only for seeded core schemas. `validate_schema_field`
enforces enum ⇒ has-values and never the converse, and `coreValues` is a
documented key on the model-facing `create_schema` tool, so a `text` field
carrying values validates today. Emitting values there is still the better
behaviour — the model can only use legal values it is shown — but it is a
widening of the `search_skills` response, not a no-op, and the comment now
says so.

Renamed the duplication test to the invariant it actually asserts, one copy
per eligible candidate. Its `println!` was swallowed without `--nocapture`,
so the measurement is now a dated finding in the doc comment rather than
output nobody sees.

Matched `no_seeded_skill_scopes_its_schema_metadata` to `find_skills`'
predicate: an empty `node_types` array also falls through to the unscoped
branch, so only a non-empty list really scopes a candidate.

Fixed two stale comments in `search_skills_latency.rs` asserting entity
types are not injected into the system prompt. Both routes are live, as this
change measured.

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

* Re-run pre-push gate with the GPU free

The two prior pushes used --no-verify because ai_chat_send_to_idle_test
timed out at 300s waiting on live inference it could not get: another
session held the model. This empty commit exists to exercise the gate
under normal conditions.

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

* Address review: fix the scenario-3 copy of the stale prompt comment

The review's finding 7 flagged `search_skills_latency.rs` for asserting
entity types are not injected into the system prompt. Both routes are live,
as this change measured, so the claim is false.

The earlier fix corrected the module doc and the scenario-2 message but
missed an identical scenario-3 message carrying the same false claim and
the same stale issue reference. Verified by grep that no occurrence of
either phrasing now remains in the crate.

Also re-verified the AC-2 guard by mutation rather than by inspection:
dropping the decoder's `required` read fails
`both_prompt_paths_render_a_schema_identically`, and restoring it passes.
A guard that cannot fail is worse than no guard, so this is checked rather
than assumed.

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_node discards user-supplied schema field values: instances persist as bare shells (guidance/prose, not tool schema)

1 participant