Skip to content

Filter is_core schemas out of semantic schema retrieval - #1903

Merged
malibio merged 2 commits into
mainfrom
issue-1900-schema-iscore-filter
Aug 1, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-1900-schema-iscore-filter

Conversation

@malibio

@malibio malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

workspace_context's semantic schema retrieval (context_ops.rs) had no is_core filter — core types (text/task/date) are stored schema nodes with embeddable content, so unfiltered retrieval could surface them into the RELEVANT ENTITY TYPES block. The sibling recently-created-schema injection in local_agent_service.rs already guards on is_core; this brings the two branches, which write into the same relevant_schemas vector, into agreement.

Why it matters

#1897's create_node guidance treats presence in RELEVANT ENTITY TYPES as proof a type is user-defined (bare property keys) vs. built-in (custom:-prefixed keys). A core type reaching that block would make the model write a bare key onto a core type — the exact ADR-063 violation #1897 was fixed to prevent.

Currently latent, not live

Seeding uses raw store.create_node, which doesn't queue embedding, and the backfill path skips schemas without a legacy description field (core schemas have none) — so core schema nodes are likely unembedded/unretrievable on a fresh DB today. Nothing prevents this from activating on a future backfill or re-index, though, and nothing would catch it.

Change

  • context_ops.rs: extracted the parse-and-collect step into parse_and_filter_non_core_schemas, adding .filter(|s| !s.is_core).
  • Added parse_and_filter_non_core_schemas_excludes_core_types, mutation-verified (fails when the filter is removed).

Testing

  • cargo test -p nodespace-core --lib: 1106 passed
  • Full bun run rust:test workspace: all green
  • bun run test (frontend): 4108 passed, 171 files
  • bun run test:scripts: 77 passed
  • bun run test:skill: 20 passed
  • cargo clippy --all-targets -- -D warnings: clean
  • Pre-push gate (test:all + cargo build + Tauri-seam e2e): green

Closes #1900. Split out of #1899's investigation per that issue's closing discussion.

Co-Authored-By: Claude [email protected]

workspace_context's semantic schema search was scoped only by
node_type == "schema", so core types (text/task/date) were retrievable
alongside user-defined ones -- unlike the sibling recently-created-schema
injection in local_agent_service.rs, which already guards on is_core.
A core type reaching RELEVANT ENTITY TYPES would make the #1897
create_node guidance read it as user-defined and write a bare property
key onto it, the ADR-063 violation that guidance exists to prevent.

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

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #1903 — Filter is_core schemas out of semantic schema retrieval

Review type: Initial Review
Verdict: Approve. Net positive, correctly scoped, well-tested. One residual gap noted below is a follow-up, not a blocker.


Summary

This is a tight, minimal fix that does exactly what #1900 asked and nothing more. The change is 4 lines of behavior (.filter(|s| !s.is_core) plus an extract-function) and 30 lines of test + rationale comment. I verified every load-bearing claim in the PR description against the code rather than taking it on trust:

  • Sibling guard exists as described. packages/daemon/src/services/local_agent_service.rs:1878 does if schema.is_core { continue; } before pushing into context.relevant_schemas. The two branches genuinely do write into the same vector, and they genuinely did disagree. Bringing them into agreement is the right framing — this is a consistency defect, not a speculative hardening.
  • The premise is real and load-bearing. packages/agent/src/skill_pipeline.rs:318-319 is explicit: "node_type is a type from RELEVANT ENTITY TYPES (one the user defined): use the bare key" vs. "node_type is a built-in type (text, task, date): prefix with custom:". Presence in that block is literally the model's discriminator. A core type appearing there inverts the branch.
  • The premise is load-bearing in more places than context_ops semantic schema retrieval missing is_core filter (ADR-063 premise gap) #1900 listed. agent_guidance.rs:35 also says "Never call create_schema for a type already in RELEVANT ENTITY TYPES", and tools.rs:304/400/508 instruct the model to copy type ids verbatim from that block. So the block's "these are user-defined types" contract has at least four consumers, not one. That strengthens the case for the fix.
  • Mutation verification is genuine. I removed the .filter(|s| !s.is_core) line and re-ran: parse_and_filter_non_core_schemas_excludes_core_types fails. Restored the file afterward. The test is not a tautology.
  • Test suite green. cargo test -p nodespace-core --lib context_ops: 31 passed, 0 failed.

The "currently latent, not live" framing in both the issue and PR body is honest and worth calling out as good practice — it correctly resists overclaiming a user-visible bug fix while still justifying the change on the grounds that nothing prevents activation and nothing would catch it.


Findings

Critical Issues

None.

Suggested Improvements

[Improvement] related_schemas can still surface a core type into the prompt — via the incoming-relationship traversal.

related_one_hop_schemas (packages/core/src/ops/context_ops.rs:161) draws from node_service.get_all_schemas() — the unfiltered corpus including core schemas — and applies no is_core filter of its own. Both traversal directions can in principle place a core schema into related_schemas:

  • Outgoing — related_ids collects target_type values declared by retrieved schemas, then resolves them against the full corpus. Retrieved is now core-free after this PR, but nothing stops a surviving user schema from declaring target_type: "task"; I grepped for validation rejecting core ids as relationship targets and found none. This path is reachable today.
  • Incoming — the loop adds candidate.id for any corpus schema declaring a relationship that points at a retrieved one. A core schema qualifies only if it declares an outgoing relationship, and I confirmed every core schema in packages/core/src/models/core_schemas.rs declares relationships: vec![]. Closed by that accident, not by a guard.

So the outgoing path genuinely leaks core types into related_schemas as soon as any user schema relates to task/text/date — which is an ordinary thing for a user to model. That is the same class of accident #1900 was written to eliminate — "true by current accident of what's embedded" is the issue's own phrasing, and the same reasoning applies to "true by current accident of what relationships core schemas declare." The mitigating factor, and the reason this is not a blocker: related_schemas renders under a different header — "RELATED (via relationship, not directly matched):" at context_ops.rs:408 — not RELEVANT ENTITY TYPES. The #1897 guidance keys specifically on the latter string, so a core type in the RELATED block does not trip the bare-key branch. The ADR-063 premise is intact.

Recommendation: add .filter(|s| !s.is_core) to the related_ids resolution at context_ops.rs:213-216, or open a follow-up. Cheap, symmetric with this fix, and removes the reliance on core schemas happening to declare no relationships. Not blocking this PR.

[Improvement] Acceptance criterion 2 is met in substance but not quite in letter.

The issue asks for a test that pins "a core schema, even if embedded/retrievable, never appears in the rendered RELEVANT ENTITY TYPES block." The added test asserts on the helper's return value, not on format_for_prompt output. Since relevant_schemas is the only input to that block and format_for_prompt has its own rendering tests, coverage is real — but a test that ran a core schema through parse_and_filter_non_core_schemas and then asserted !output.contains("task") on the formatted string would pin the property the guidance actually depends on, end to end, and would survive a future refactor that changed how the block is assembled.

This is a judgment call, and testing the helper is the more maintainable choice for a unit test. I'd accept as-is; flagging so the divergence from the written criterion is a recorded decision rather than an oversight.

Nitpicks

Nit: the doc comment on parse_and_filter_non_core_schemas references issue numbers.

context_ops.rs:214 and the test's doc comment both say "The #1897 create_node guidance...". CLAUDE.md's documentation standard is explicit: "Do not embed GitHub issue numbers in documentation content or code comments — describe the behavior/constraint directly, and reference decisions by ADR." The comment already describes the constraint well enough to stand alone; dropping "#1897" and "#1900" (keeping the existing ADR-063 reference) would satisfy the standard with no loss of meaning. The rationale itself is genuinely valuable and should stay — this is only about the ticket references.

Nit: unrelated bun.lock drift in the working tree.

git status shows bun.lock modified (packages/desktop-app version 0.1.0 → 0.2.0). I confirmed it is not in commit 8de9b5cc — the commit is clean at one file, 54 insertions. This appears to be leftover working-tree drift from the version-reconciliation change (fde58ff5) rather than anything this PR introduced. No action needed for the PR; worth not accidentally sweeping into a later git add ..


Assessment against the framework

  • Architecture — Correct. Extracting the helper rather than inlining the filter is the right call: it creates a testable unit for a behavior that otherwise only exists inside an async function requiring an embedding service. That is justified extraction, not premature abstraction.
  • Correctness — Verified. SchemaNode::from_node (schema_node.rs:152-156) reads isCore with .unwrap_or(false), and the test fixture writes {"isCore": is_core}, so the fixture faithfully exercises the real parse path rather than constructing SchemaNode directly. Good fidelity choice. Filter ordering (filter_map then filter) is correct — parse must precede the is_core read.
  • Security — N/A. No auth, input-handling, or data-exposure surface. If anything this narrows what reaches the model's context.
  • Maintainability — Good. The doc comment explains why the filter exists, which is exactly the non-obvious constraint that warrants a comment. Without it, a future reader would plausibly delete the filter as redundant.
  • Testing — Strong. Mutation-verified by the author and independently re-verified by me.
  • Performance — Negligible; one extra predicate over a list capped at MAX_SEMANTIC_SCHEMAS.
  • Dependencies — None added. The use change from SchemaNode to {Node, SchemaNode} is required by the new signature.

Recommendation

Approve. Optionally address the issue-number nit before merge (one-line comment edit). The related_schemas incoming-traversal gap is worth a follow-up issue but does not affect the ADR-063 premise this PR was written to protect, since that block renders under a different header.

@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 verdict: Approve (posting as a comment — GitHub blocks self-approval on your own PR).

Verified independently rather than taking the PR description on trust: the sibling is_core guard at local_agent_service.rs:1878, the ADR-063 premise in skill_pipeline.rs:318-319, and the mutation-verification claim (removed the filter, the new test fails; restored). cargo test -p nodespace-core --lib context_ops: 31 passed.

Non-blocking follow-ups in the detailed review comment above: (1) related_one_hop_schemas outgoing traversal still resolves core types into related_schemas — but renders under the RELATED header, not RELEVANT ENTITY TYPES, so the ADR-063 premise is intact; (2) issue numbers in the new doc comments conflict with the CLAUDE.md documentation standard.

…ue refs from comments

- related_one_hop_schemas now filters is_core, closing the same class of
  gap on the incoming/outgoing relationship traversal: a user-defined
  schema relating to a core type (e.g. project -> task) could otherwise
  place that core type in related_schemas. It renders under a different
  heading than RELEVANT ENTITY TYPES so this wasn't the ADR-063 hazard
  itself, but there's no reason for a core type in either block, and
  fixing it removes reliance on core schemas happening to declare no
  relationships of their own.
- Removed #1897/#1900 references from doc comments per the documentation
  standard (describe behavior directly, cite ADRs not tickets).

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

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed — f94044a6

Both non-blocking findings from the review addressed:

Improvement: related_schemas outgoing traversal could still surface a core type
related_one_hop_schemas now filters is_core too. Confirmed the reviewer's finding first: a user-defined schema relating to a core type (e.g. project --has_task--> task) is an ordinary thing to model, and nothing prevented that outgoing traversal from placing the core type into related_schemas. Added related_schemas_excludes_core_types_reached_via_outgoing_relationship, mutation-verified (removed the filter, test fails; restored). This wasn't the ADR-063 hazard itself (renders under RELATED, not RELEVANT ENTITY TYPES), but there's no reason for a core type in either block, and the fix removes reliance on core schemas happening to declare no relationships of their own.

Nit: issue numbers in doc comments
Removed #1897/#1900 from both doc comments per the documentation standard — the rationale text stands on its own without the ticket references, ADR-063 citation kept.

Not addressed: the acceptance-criterion letter-vs-substance point (testing the helper vs. format_for_prompt output) — agreed with the reviewer's own read that testing the helper is the more maintainable choice; no change made.

Verification

  • cargo test -p nodespace-core --lib: 1107 passed (was 1106; +1 new test)
  • cargo clippy -p nodespace-core --lib --all-targets -- -D warnings: clean
  • cargo fmt --check: clean
  • Both is_core filters mutation-tested (removed each in turn, confirmed the corresponding test fails, restored)
  • Full pre-push gate (test:all + Rust workspace + Tauri-seam e2e): green

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Both changes are small, mechanical, and directly match what the reviewer already verified and recommended (a symmetric filter application + a doc-comment edit) — no new design surface, no architectural change, low risk. The reviewer's original verdict was already Approve with these as optional follow-ups rather than blockers.

@malibio
malibio merged commit 7046828 into main Aug 1, 2026
2 checks passed
@malibio
malibio deleted the issue-1900-schema-iscore-filter branch August 1, 2026 19:33
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.

context_ops semantic schema retrieval missing is_core filter (ADR-063 premise gap)

1 participant