Skip to content

Guard against a SCHEMA_RULES entry silently missing the in-app agent prompt - #2479

Merged
malibio merged 2 commits into
mainfrom
issue-2438-unwired-schema-rule-guard
Sep 8, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2438-unwired-schema-rule-guard

Conversation

@malibio

@malibio malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds schema_rules_are_wired_or_explicitly_excluded (packages/agent/src/skill_pipeline.rs), a test that checks every SCHEMA_RULES entry is either interpolated into schema_creation_guidance() (the in-app agent's prompt) or explicitly named in a new SCHEMA_RULES_NOT_IN_PROMPT exclusion list.
  • SCHEMA_RULES_NOT_IN_PROMPT names the 5 field/enum shape rules ADR-064 deliberately moved onto create_schema's own tool schema instead of the prompt (no-name-title-field, fields-from-request-only, name-placeholder-exception, enum-format, enum-edge-fields), with the rationale recorded inline as comments so a future reader can tell a deliberate omission from a forgotten one.
  • The test's failure message says what to do — wire the rule into schema_creation_guidance()'s format string, or add it to the exclusion list with a reason — not just that a count mismatched. It also fails if a rule is both wired and listed as excluded, since that would mean the exclusion list itself is wrong.

Why

SchemaRule carries two renderings consumed by two different renderers (prose → shipped SKILL.md, imperative → the in-app agent prompt via schema_creation_guidance()). A rule can be registered in SCHEMA_RULES and rendered into SKILL.md without ever reaching the in-app prompt — this happened for real with DELETE_A_SCHEMA in PR #2435. The existing every_schema_rule_reaches_the_skill test (packages/cli/tests/skill_md_generation.rs) only checks the SKILL.md renderer, and the prompt_assembly_snapshot golden can't catch an unwired rule since an unwired rule never enters the rendered prompt at all — the golden stays silent on exactly the omission that matters.

Verification

Per the issue, confirmed the test actually catches the failure mode before finalizing: temporarily added an unwired, unexcluded rule to SCHEMA_RULES and confirmed the test failed with the expected message; separately added a wired rule's id to the exclusion list and confirmed that failure mode (wrongly-excluded) also fires; reverted both temporary changes.

Test plan

  • cargo test -p nodespace-agent --lib schema_rules_are_wired_or_explicitly_excluded — passes
  • cargo test -p nodespace-agent --lib — 599 passed, 0 failed
  • cargo test -p nodespace-cli --test skill_md_generation — 11 passed, 0 failed (existing SKILL.md guard still green)
  • bun run test:all — clean pass (233 frontend test files / 4909 tests, 4 skill test files / 55 tests, all Rust crates 0 failed)
  • bun run quality:fix — no additional changes
  • Pre-push gate (test:all + cargo build --bin nodespaced + test:e2e) — passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY

…prompt (closes #2438)

Adds schema_rules_are_wired_or_explicitly_excluded, a test that checks every
SCHEMA_RULES entry is either interpolated into schema_creation_guidance() (the
in-app agent's prompt) or named in the new SCHEMA_RULES_NOT_IN_PROMPT
exclusion list, with the ADR-064 rationale recorded inline for the five
field/enum shape rules that are deliberately prose-only.

This closes the gap that let DELETE_A_SCHEMA (PR #2435) reach the shipped
SKILL.md without ever being wired into the in-app prompt: the existing
every_schema_rule_reaches_the_skill test only checks the SKILL.md renderer,
and the prompt_assembly_snapshot golden cannot catch an unwired rule since it
never changes the rendered output. Verified the new test actually fails on an
unwired rule and on a wrongly-excluded one before finalizing the failure
messages, which name the two concrete fixes (wire it, or exclude it with a
reason) rather than just reporting a mismatch.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY
@malibio

malibio commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Automated Pragmatic Code Review — PR #2479

Review Type: Initial Review (no prior review comments found)

Requirements Check (issue #2438)

  • ✅ A test asserts every SCHEMA_RULES entry is either interpolated into schema_creation_guidance() or explicitly listed as prose-only — schema_rules_are_wired_or_explicitly_excluded in packages/agent/src/skill_pipeline.rs.
  • ✅ The exclusion list names 5 rules with inline ADR-064 rationale — verified 4 of 5 against the actual create_schema/update_schema tool schemas in packages/agent/src/local_agent/tools.rs (see finding below for the 5th).
  • ✅ The test fails when a new rule is added unwired/unexcluded — reproduced independently (see Verification).
  • ✅ The failure message says what to do, not just that a count mismatched — confirmed by reading the actual assert! messages.
  • ➕ Beyond the literal acceptance criteria, the test also catches the inverse inconsistency (a rule both wired and excluded) — reproduced independently, not just accepted on the author's word.

Verification performed independently

I did not trust the PR description's claim of having tested both failure modes — I reproduced both myself on a fresh checkout of the PR branch, mutating source and reverting after each:

  1. Unwired + unexcluded (the original bug class): added a throwaway SchemaRule to SCHEMA_RULES without wiring or excluding it. Test failed with the unaccounted assertion, correctly naming the injected rule's id.
  2. Wired + wrongly excluded (the inverse case): added "one-schema-per-request" (a genuinely-wired rule) to SCHEMA_RULES_NOT_IN_PROMPT. Test failed with the wrongly_excluded assertion, correctly naming it.

Both reverts left cargo test -p nodespace-agent --lib at 599 passed / 0 failed, matching the PR's stated baseline. Also ran cargo test -p nodespace-cli --test skill_md_generation (11 passed) and cargo clippy -p nodespace-agent --lib -- -D warnings (clean).

On the substring-matching robustness question: schema_creation_guidance() interpolates each wired rule's .imperative field verbatim via format!, and the test's wired check is prompt.contains(rule.imperative) — an exact match against the same string that was interpolated, not a paraphrase or fuzzy comparison, so this is about as robust as this style of test gets. I additionally checked all 22 SchemaRule/InteractionRule imperative strings pairwise for substring collisions (one rule's text being a substring of another's, which would let a false negative slip through contains) — none exist in the current data. This is a live-data guarantee, not a structural one: a future rule author writing an unusually short/generic imperative could in principle create a collision, but given how long and distinctive these strings are in practice, this is a low-severity residual risk, not something worth blocking on.

Code Review Findings

🟡 Important: enum-edge-fields exclusion comment misstates where the rule is enforced

📁 packages/agent/src/skill_pipeline.rs (in SCHEMA_RULES_NOT_IN_PROMPT)

The comment reads:

// Edge field shape (coreValues, closed vocabulary): stated on
// create_schema's relationships/edgeFields description.
"enum-edge-fields",

I checked packages/agent/src/local_agent/tools.rs's def_create_schema() and def_update_schema() — their relationships array schema has properties name, targetType, direction, cardinality, reverseName, reverseCardinality, description. There is no edgeFields property anywhere in either tool's schema (confirmed via grep -n "edgeFields" packages/agent/src/local_agent/tools.rs, zero hits, and by listing every fn def_* tool definition in the file — no relationship/edge-specific tool exists either). edgeFields/coreValues-on-edges validation is real and does exist, but only at the storage layer (packages/core/src/schema/mod.rs::validate_edge_fields) — which fires only after the model has already committed to a shape, i.e. exactly the failure mode ADR-064 is trying to avoid (rule stated nowhere the model reads it before calling).

This is a pre-existing gap — this PR does not touch tools.rs (confirmed via git diff main...pr-2479-review -- packages/agent/src/local_agent/tools.rs, empty) — so it is not a regression introduced here. But the issue's explicit requirement is that the exclusion list's comments let "a future reader tell deliberate-omission from forgotten-to-wire." As written, this comment tells a future reader the omission is safe because the constraint is stated on the tool schema, when it currently is not stated anywhere the in-app agent sees before calling create_schema. That is precisely the "silent drift" shape the issue is trying to eliminate, just relocated from SCHEMA_RULES/prompt drift to exclusion-list-comment/reality drift.

Recommendation: Either (a) correct the comment to state the current true location (validation-time error message only, not the tool schema) and treat wiring edgeFields onto the tool schema as a followup item, or (b) if this was intended to already be fixed, file a follow-up issue now rather than merging a comment that asserts something not currently true. This does not need to block merge — the test itself is sound and additive — but the comment should not overstate the current state, per the issue's own bar for what makes these comments useful.

🟢 Suggestion: fields-from-request-only's grouping is explained but is still a wobble

📁 packages/agent/src/skill_pipeline.rs

The comment for this entry is unusually self-aware: it says the rule "is not an argument shape" but is grouped in anyway "per ADR-064's grouping rather than getting a sixth, one-off list." This is honest rather than misleading, and I don't think it needs to change — flagging only because it's the one entry where the given rationale is explicitly an administrative convenience rather than a doctrinal fit, and a future reader skimming quickly could miss that distinction. Nit-level; no action required.

🟢 Nit: doc-comment cross-reference says seed_skill_nodes(), test checks schema_creation_guidance()

📁 packages/agent/src/skill_rules.rs:14-18 (pre-existing, not touched by this PR)

The module doc comment states imperative is used by seed_skill_nodes(), but the actual interpolation site for SCHEMA_RULES is schema_creation_guidance() (which is presumably called from within seed_skill_nodes()'s template construction, but the doc comment doesn't make that indirection clear). This predates this PR and isn't something it needs to fix, but since this PR's own new doc comments lean heavily on precise function references for future readers, it's worth a follow-up cleanup pass. Not blocking.

Architectural / Design Assessment

  • Purely additive, confirmed structurally: git diff main...pr-2479-review --stat shows exactly one file changed, 108 insertions, 0 deletions. The schema_creation_guidance() function body is untouched (only a doc comment was prepended above it) — verified line-by-line, not just via the diff stat. No production code path changes as a side effect.
  • Correctly test-scoped: SCHEMA_RULES_NOT_IN_PROMPT is #[cfg(test)]-gated, appropriate since it exists solely to drive an assertion and carries no runtime behavior — consistent with this repo's "no dead code" standard (it's not dead, it's compiled only for tests, and used there).
  • Test independence from prior guards: correctly distinguishes itself from every_schema_rule_reaches_the_skill (checks .prose reaching SKILL.md) and the prompt_assembly_snapshot golden (can't observe an absence). This is a real, non-overlapping test, not a redundant addition.
  • Data-driven over the live array rather than hardcoded counts: matches the issue's implicit intent (the issue was filed against a 15-rule snapshot; the array had grown to 16 by implementation time) and avoids the classic "test encodes today's count" brittleness.

Security / Performance

Not applicable — this is a test-only addition with no user input, no I/O, no new dependencies, and negligible runtime cost (string containment checks over a fixed small array, #[cfg(test)]-gated).

Testing

The new test itself is the subject under review and has been independently verified above (both failure directions reproduced). No additional test coverage is needed for this change — it is test infrastructure, not business logic.

Recommendation

APPROVE, with one non-blocking Important finding (the enum-edge-fields comment's factual claim about where the rule is enforced) that the author should either correct or track separately before or shortly after merge. The core mechanism — the test, its exclusion list, and its failure messages — is sound, genuinely catches both failure directions the issue cares about (independently verified, not taken on trust), is purely additive with zero production-path risk, and directly closes the gap that let DELETE_A_SCHEMA ship unwired in PR #2435.


🤖 Automated pragmatic-code-review

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

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). One non-blocking Important finding (the enum-edge-fields exclusion comment misstates where that rule is currently enforced — see full review comment above). Both failure-mode claims independently reproduced by mutating source and reverting; purely additive with zero production-path changes; full findings in the review comment above.

Review of PR #2479 caught that the enum-edge-fields entry in
SCHEMA_RULES_NOT_IN_PROMPT claimed enforcement via create_schema's
edgeFields tool-schema description. Neither create_schema nor
update_schema takes an edgeFields parameter (local_agent/tools.rs) --
the only enforcement is the post-hoc validator in
packages/core/src/schema/mod.rs, which runs after the model has
already committed to a shape. That's exactly the failure mode
ADR-064 exists to prevent for this rule category.

Rewrote the comment to say so plainly: the rule sits in the
exclusion list per ADR-064's intent, but the tool-schema side that
intent describes hasn't been built for this specific rule yet.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KwcVcLdvBUjSkUFmtFNiTY
@malibio
malibio merged commit 7ce692e into main Sep 8, 2026
@malibio
malibio deleted the issue-2438-unwired-schema-rule-guard branch September 8, 2026 12:32
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.

1 participant