Repository navigation
Stop recommending a relationship name the validator rejects - #2238
Conversation
…2234, closes #2237) ## #2234 — guidance contradicted the validator `create_relationship` accepts a relation DECLARED on the source node's own schema, or one of the four universal built-ins in BUILTIN_RELATIONSHIP_NAMES (member_of, has_child, mentions, has_role). Two model-facing channels told the model to use `related_to` as a generic fallback, which is neither: - create_relationship's `relationship_type` parameter description - the seeded Relationship Management skill's CREATING A RELATIONSHIP rule A model following either had its write rejected. Observed live, with everything else about the turn correct — both ids recovered without being handed either, direction right: create_relationship is_error=true args={"from_id":"1fb911ba-…","relationship_type":"related_to","to_id":"c26d…"} error: Relationship 'related_to' not defined in schema 'task'. Both channels now state what is actually accepted and name `mentions` as the fallback when no declared relation fits. Not fixed by adding `related_to` to the universal set: those four are structural primitives with hardcoded semantics and their own UI affordances (models/schema.rs:48-56), not an allowlist to extend. `related_to` has no semantics to hang there. A regression test pins the coupling, keyed off BUILTIN_RELATIONSHIP_NAMES rather than a hardcoded list, so the prose and the validator cannot drift apart again — the failure that actually happened. Mutation-tested: restoring the old wording fails it, naming the offending channel. ## #2237 — the contamination guard's parser saw a phantom prompt `eval_prompts()` treated a backticked `prompt:` mention inside a doc comment as a scenario prompt, because its is-this-an-object-key check excluded alphanumerics, `_` and `.` but not a backtick. The agent matrix's own header comment names the guard's subject as inline code, so it matched, and the parser then read on to the next quote — capturing a span of comment prose as one enormous "prompt". Never made the guard vacuous (site accounting still balanced, and the phantom span cleared the threshold), but it was a latent false positive: the captured span is arbitrary file text that could collide with guidance wording. Excluding the backtick takes the matrix from 21 sites to 20, exactly its real prompt count. While pinning that, found and documented a genuine fail-open shape rather than quietly leaving it: a JSON-style quoted key (`{"prompt": "..."}`) writes `prompt":`, so `match_indices("prompt:")` never matches it and the site is not counted either — meaning `prompts.len() == sites` cannot catch it. No fixture uses that shape today. Left unfixed deliberately: widening what the scan matches changes the guard's own detection surface and deserves its own measurement, not a ride-along with a prose fix. `eval_prompt_parser_does_not_yet_see_a_quoted_prompt_key` pins it and fails the moment the parser learns the shape, so the caveat cannot outlive the gap silently. Co-Authored-By: Claude <[email protected]>
create_relationship_type_prefers_schema_defined_names asserted the literal string "relevant schema", which the old description satisfied while ALSO recommending related_to — so the test that existed to cover this parameter's guidance let the contradiction through untouched. Now checks the substance: the description must point at schema-declared names, must name every BUILTIN_RELATIONSHIP_NAMES entry so the model has a legal fallback, and must not offer related_to. Keyed off the shared constant, so changing the universal set updates what the test requires. Co-Authored-By: Claude <[email protected]>
Pragmatic Code Review — PR #2238Review Type: Initial Review (no prior reviews or comments on this PR) Scope: 2 commits, 3 files, +156/−6. Prose-only changes to model-facing guidance plus test hardening. No behaviour change to the code being described — verified: neither Requirements CheckIssue #2234 — description recommends a relation name the validator rejects
Issue #2237 —
|
| Check | Result |
|---|---|
bun run test:all |
exit 0 — 227 files / 4794 tests + 2 files / 24 tests, zero failures |
cargo test -p nodespace-agent --lib agent_guidance |
17 passed, 0 failed |
cargo test -p nodespace-agent --lib create_relationship_type_prefers |
1 passed |
| Site count 21→20 | Independently reproduced — reimplemented both parser versions in Python against the real fixtures |
| Mutation test: new guard | Fails correctly on both channels, naming the offender |
Mutation test: strengthened tools.rs test |
Fails correctly when builtin names are stripped |
| Validator semantics vs. new wording | Accurate — traced relationship.rs:476-712 |
| Worktree clean after mutation testing | ✅ confirmed via git diff --stat |
Site-count finding beyond the claim. The PR body and issue both describe this as fixing agent-matrix.ts (21→20). It also silently fixes a second fixture:
| Fixture | Before | After | Real prompt: keys |
|---|---|---|---|
agent-matrix.ts |
21 | 20 | 20 ✅ |
routing.ts |
16 | 15 | 15 ✅ |
scripts/eval/fixtures/routing.ts:17 carries the same backticked mention. Both now match their real prompt counts exactly. The fix is more valuable than advertised.
Mutation-test transcript (guard is not vacuous):
skill_pipeline::seed_skill_nodes offers "related_to", which create_relationship
rejects unless the source node's schema declares it
Legal names are a relation declared on the source node's own type, or one of
["member_of", "has_child", "mentions", "has_role"]. Prefer "mentions" as the generic fallback.
Restoring related_to in the tool description trips two independent tests — real defence in depth, not redundancy.
Is the new wording factually correct?
Traced against packages/core/src/services/node_service/relationship.rs:476-712 and packages/core/src/models/schema.rs:48-61. Every load-bearing claim checks out:
- "DECLARED on the source record's own type" — accurate and precise.
relationship.rs:537islet schema_id = &source.node_type;. The target's schema is never consulted; the target is only checked againsttarget_type, a field of the source's declaration (:567). No inheritance —SchemaNode::get_relationshipis a flat.iter().find(). - "Any other name is rejected" — accurate, with no escape hatch. A type with no schema row fails hard at
:540(query_failed), it does not pass permissively. - "these four universal names" — complete.
is_builtin_relationshipis the sole gate and every consumer keys off the constant. No fifth name exists. mentionsas a safe universal fallback — accurate. The builtin branch applies extra validation tomember_ofonly (:489-518).mentionscarries no target-type, cardinality, or uniqueness constraint, andcreate_generic_relationshipspecial-cases onlymember_of. It is genuinely safe between any two node types.
This directly answers the sharpest question the change raises, and the answer is favourable.
Code Review Findings
🟡 Important 1: Nine golden snapshots still contain the removed text
📁 packages/agent/goldens/ablation/*.toml — 9 files, 20 occurrences
Every ablation golden still embeds the old description verbatim:
"...otherwise a generic label (member_of, mentions, related_to, etc.)."
e.g. production-baseline.toml:131,186,262,318, full-tool-surface.toml:156,253, minimal-at-fidelity.toml:110,165,241,297.
These are frozen captures of past runs, so they are correct as history and should not be rewritten to fake a past state. The concrete risk is different: a file named production-baseline.toml no longer describes production. The next person diffing a fresh capture against it will see a prompt delta that looks like drift but is this PR, and guidance_corpus() does not reach these files, so nothing will tell them.
Recommendation: don't edit the goldens. Add a one-line note in the ablation directory (or the issue) recording that captures predating this PR carry the superseded relationship_type text. Cheap, and it converts a future confusing diff into an expected one.
Engineering principle: a snapshot's value is its fidelity to a known point in time — preserve it, but label when the reference has moved, or the next reader mistakes a known change for a regression.
🟡 Important 2: The enum option was passed over without a recorded rationale
📁 packages/agent/src/local_agent/tools.rs:1055
Issue #2234 asked for this to be decided deliberately, noting the enum version is "the one that measurably works (ADR-064 rule 1)". The PR argues carefully against option 2 (adding to the universal set) but does not address the prose-vs-enum choice at all.
The prose fix is the right call for this PR — the legal set is dynamic (source schema's declared relations ∪ four built-ins), so a static JSON enum cannot express it. That is a real, defensible reason, and it is exactly what is missing from the write-up.
Worth noting the constraint is tighter than the enum framing assumes: every seeded core schema declares relationships: vec![] except project (one relation, tasks). So for a task or text node the legal set today is exactly the four built-ins — statically enumerable right now, and only non-enumerable once users define their own relations.
Recommendation: add a sentence to the PR body (or a follow-up issue) stating that the enum was considered and rejected because the legal set is source-schema-dependent. Non-blocking — no code change needed.
Engineering principle: when an issue names a decision as explicitly requiring deliberation, recording the reasoning is part of closing it; otherwise the option looks overlooked rather than considered.
🟢 Suggestion 3: The guard cannot distinguish a recommendation from a prohibition
📁 packages/agent/src/agent_guidance.rs:790-798
for (channel, text) in guidance_corpus() {
for name in NOT_UNIVERSAL {
if text.contains(name) {Bare contains with no polarity analysis. Two plausible future false positives:
- Explicit prohibition. Writing "do NOT use
related_to" is a natural hardening move — and prior prompt work in this repo has found explicit negative rules effective. It would fail the guard, reportingoffers "related_to", which is the opposite of what the text says. - A legal declared relation.
related_tois legal when declared on the source node's own type. Acreate_schemaworked example declaring it on a user-defined type would be correct per the validator, yet rejected by the test.
Also note links_to matches inside links_to_document / links_to_page — plausible user-defined names.
Mitigations are real and I weigh them heavily: the doc comment at :757-773 is unusually clear about intent, the BUILTIN_RELATIONSHIP_NAMES pre-check at :785-790 forces a deliberate edit if a name is promoted, and the failure message names the channel. A future author hitting this has everything needed to edit NOT_UNIVERSAL consciously.
Recommendation: keep contains. Optionally add one line to the doc comment: "a legitimate future mention (a prohibition, or a user-type declaring the name) means removing it from NOT_UNIVERSAL deliberately — not weakening this assertion." Word-boundary matching would fix links_to_* but not the polarity case, so it is not the higher-value change.
Engineering principle: a guard that cannot express intent should make the escape hatch obvious, so the next author edits the rule deliberately rather than deleting the assertion.
🟢 Suggestion 4: Two prose references now describe a fixed bug in the present tense
📁 scripts/eval/fixtures/agent-matrix.ts:745-746
📁 ../nodespace-docs/development/agent-eval.md:328
The fixture comment still reads "the tool's own description names related_to as a valid generic fallback" — no longer true as of this PR. The docs entry likewise says the description "offers related_to".
Both are accurate as an account of why the scenario was rewritten, so the fix is a tense change, not a deletion — e.g. "named ... (fixed in #2234)". The docs file is in the separate repo, so it need not block this PR.
Engineering principle: comments explaining why stay valuable, but a present-tense claim about code that has changed will mislead the next reader into re-investigating a solved problem.
🟢 Suggestion 5: The '/" exclusion reasoning is correct — verified, no change needed
📁 packages/agent/src/agent_guidance.rs:321-334
I checked this specifically for a fail-open risk and the author's reasoning holds. A JSON-style key writes prompt": — the quote sits between the word and the colon, so match_indices("prompt:") never matches, and there is nothing for a preceding-char rule to exclude. Adding '/" would be a rule with no reachable case, while implying the quoted-key shape is handled. Declining to add them is the correct call, and the comment explains it better than most code does.
Confirmed the backtick exclusion cannot fail open: it only skips matches where the preceding character is a backtick. A real key is preceded by {, ,, or whitespace — never a backtick. A template-literal key ([`prompt`]:) was already invisible to the scan before this PR, so nothing regressed.
🟢 Suggestion 6: The weakened first clause is near-vacuous — but harmless here
📁 packages/agent/src/local_agent/tools.rs:3884-3887
desc.contains("schema") || desc.contains("type")Flagged as a possible vacuity regression. Assessment: the clause is indeed nearly always true — "type" appears in almost any relationship description, and this parameter is literally named relationship_type. As a standalone assertion it carries little signal.
But it is not a regression, because the test's real teeth moved elsewhere in the same change: the loop requiring every BUILTIN_RELATIONSHIP_NAMES entry, plus !desc.contains("related_to"). I mutation-tested this — stripping the builtin names from the description fails on member_of as intended. The old "relevant schema" assertion was more specific but less meaningful: it passed on a description that also recommended a rejected name, which is exactly the bug that shipped.
Recommendation: optionally drop the || desc.contains("type") disjunct, keeping desc.contains("schema") — the current description satisfies it, and it restores a little specificity at no cost. Genuinely optional.
Engineering principle: prefer asserting substance over phrasing — but keep assertions narrow enough to still discriminate, or they stop paying for their maintenance.
What this PR does well
Worth stating plainly, because it is the kind of work that is easy to under-credit:
- It fixes the test that let the bug through. The most valuable line in the diff is the recognition that
create_relationship_type_prefers_schema_defined_namesexisted, covered this exact parameter, and passed on the broken description. Fixing the description without fixing that test would have left the same hole open. - The regression guard is keyed off the shared constant, so prose and validator cannot drift apart again — pinning the actual failure mode rather than the specific string.
- The fail-open gap was found, pinned, and disclosed rather than quietly left.
eval_prompt_parser_does_not_yet_see_a_quoted_prompt_keyassertssites == 0and fails the moment someone teaches the parser the shape, with a message telling them exactly what to do. Deferring is correct here — widening the scan changes the guard's own detection surface and no fixture uses the shape today — and the pinning test is well-designed: it makes the caveat impossible to outlive silently. This is the right way to defer. - Both mutation tests were done by the author and I reproduced both. Claims in the PR body matched reality on every point I checked.
Recommendation
APPROVE ✅
Both issues are fully resolved, the reworded guidance is factually accurate against the validator (independently traced), mentions is genuinely a safe universal fallback, all tests pass with test:all at exit 0, and both new guards are mutation-verified non-vacuous. The 21→20 claim is correct and understated — a second fixture is fixed too.
No blocking findings. The two 🟡 items are documentation gaps, not defects: the stale golden snapshots deserve a one-line note, and the enum-vs-prose rationale deserves a sentence in the PR body. Both can land as follow-ups without holding this PR.
Net assessment: this change removes a live failure in which the model was rejected for following its own instructions exactly, and closes the testing hole that permitted it. Clear net improvement to code health.
🤖 Generated with Claude Code
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval on your own PR).
Both #2234 and #2237 fully resolved. Full findings in the review comment above. Verification I ran independently:
bun run test:allexit 0 (4794 + 24 tests, zero failures)- Reworded guidance traced against
relationship.rs:476-712— source-schema-only, no inheritance, no escape hatch, exactly four universal names, andmentionsconfirmed safe between any two node types (member_ofis the only builtin carrying extra validation) - 21→20 site count independently reproduced — and it understates the fix:
routing.tsalso goes 16→15, both now matching their real prompt counts exactly - Both new guards mutation-tested non-vacuous; restoring
related_totrips two independent tests
No blocking findings. Two 🟡 items are documentation gaps suitable for follow-up, not defects: 9 ablation goldens still embed the superseded description text (keep them, just note it), and the prose-vs-enum rationale from #2234 deserves a sentence in the PR body — the prose fix is correct because the legal set is source-schema-dependent and a static enum cannot express it.
Not merging — that call is yours.
…e assertion
All six review findings triaged; five addressed, one confirmed no-change.
🟡 Ablation goldens still embed the removed guidance (20 occurrences across 9
files). Left verbatim — they are captured snapshots and rewriting them would
invalidate the measurements recorded against them. production-baseline.toml now
carries a SNAPSHOT, NOT CURRENT PRODUCTION note calling out the known divergence
so a future reader does not mistake it for today's prompt.
🟡 Enum option passed over without recorded rationale. Now stated at the call
site: ADR-064 rule 1 would prefer the schema channel, but the legal set is
SOURCE-NODE-DEPENDENT, so no static enum is correct for every call — and one
naming only the universals would forbid the schema-declared names this
parameter exists to encourage.
🟢 Guard cannot tell a recommendation from a prohibition. Kept `contains`, with
the reasoning recorded: the guard's job is to keep these names out of
model-facing text entirely, and prose telling a small model what NOT to do is a
weaker instrument than not naming it. Documents the correct escape hatch —
remove the name from NOT_UNIVERSAL — rather than loosening the match.
🟢 Two present-tense references to the now-fixed bug, in the matrix fixture and
in agent-eval.md. Both now past-tense with a pointer to the fix; the docs one
keeps the lesson, since the drift is the transferable part.
🟢 The `|| desc.contains("type")` disjunct was near-vacuous. Removed — and
removing it exposed that this assertion had been weak in THREE successive
drafts:
contains("relevant schema") passed on the broken description (the original bug)
contains("schema")|| "type" near-vacuous; the parameter is named relationship_type
contains("declared") looked precise, but the trailing "when no declared
relation fits" clause satisfies it — so a description
that DROPPED the requirement still passed
Verified that third case by mutation rather than inspection. Now asserts
`contains("rejected")`: the one word that tells the model the set is closed,
supplied by no other clause. Mutation-tested — removing the rejection clause
fails it.
🟢 The '/" exclusion reasoning was confirmed correct by review; no change.
test:all exit 0, zero failures.
Co-Authored-By: Claude <[email protected]>
Address-review summaryAll six findings triaged: 5 addressed, 1 confirmed no-change. No blocking items existed. ✅ Addressed🟡 1 — Ablation goldens still embed the removed guidance (20 occurrences, 9 files). Left verbatim, as the reviewer recommended: they are captured snapshots, and rewriting them would invalidate the measurements recorded against them. 🟡 2 — Enum option passed over without recorded rationale. Now stated at the call site: ADR-064 rule 1 would normally prefer the schema channel, but it cannot apply here — the legal set is source-node-dependent, so no static enum is correct for every call, and one naming only the universals would forbid the schema-declared names this parameter exists to encourage. 🟢 3 — Guard can't distinguish recommendation from prohibition. Kept 🟢 4 — Two present-tense references to the now-fixed bug. Both past-tensed with a pointer to the fix. The docs one keeps the example rather than deleting it — the transferable lesson is that a recommendation and its validator were written in different places and drifted (nodespace-docs f75cc0b). 🟢 6 —
I found the third by mutation, not inspection: I removed the That is the same class of defect as the bug this PR fixes: an assertion that looks like it checks a constraint but actually checks incidental wording. ⏭️ No change needed🟢 5 — the Verification
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Every change is a comment, a doc-note, or a test assertion made stricter. No production code path changed — the guidance strings and the validator are untouched since the reviewed commit. The one substantive change is |
Closes #2234. Closes #2237.
Two guidance-vs-reality mismatches, both surfaced by the agent-matrix work in #1977. Neither is a behaviour change — the code they describe is unchanged; the descriptions were wrong about it.
#2234 — guidance recommended a name the validator rejects
create_relationshipaccepts a relation declared on the source node's own schema, or one of the four universal built-ins (member_of,has_child,mentions,has_role). Two model-facing channels told the model to fall back torelated_to, which is neither:create_relationship'srelationship_typeparameter descriptionCREATING A RELATIONSHIPruleA model following either instruction had its write rejected. Observed live with everything else about the turn correct — both ids recovered without being handed either, direction right:
Both channels now state what is accepted and name
mentionsas the fallback when no declared relation fits.Not fixed by adding
related_toto the universal set. Those four are structural primitives with hardcoded semantics and their own UI affordances (models/schema.rs:48-56), not an allowlist to extend —related_tohas no semantics to hang there. That was option 2 in the issue; option 1 is what shipped.#2237 — the contamination guard parsed a phantom prompt
eval_prompts()treated a backticked`prompt:`mention inside a doc comment as a scenario prompt: its is-this-an-object-key check excluded alphanumerics,_and., but not a backtick. The agent matrix's own header comment names the guard's subject as inline code, so it matched — and the parser then read on to the next quote, capturing a span of comment prose as one enormous "prompt".Never made the guard vacuous (site accounting still balanced, and the phantom span cleared the 4-word threshold), but it was a latent false positive, since the captured span is arbitrary file text that could collide with guidance wording. Excluding the backtick takes the matrix from 21 sites to 20 — exactly its real prompt count.
A fail-open shape found while fixing that, deliberately left unfixed
A JSON-style quoted key (
{"prompt": "..."}) writesprompt":, somatch_indices("prompt:")never matches it — the site is not counted either, which means theprompts.len() == sitesassertion cannot catch it. Such a prompt would be silently exempt from the contamination guard.No fixture uses that shape today. Left unfixed because widening what the scan matches changes the guard's own detection surface and deserves its own measurement rather than riding along with a prose fix.
eval_prompt_parser_does_not_yet_see_a_quoted_prompt_keypins it and fails the moment the parser learns the shape, so the caveat cannot outlive the gap silently.Tests
A new regression guard, keyed off
BUILTIN_RELATIONSHIP_NAMESrather than a hardcoded list, so the prose and the validator cannot drift apart again — the failure that actually happened. Mutation-tested: restoring the old wording fails it and names the offending channel.An existing test was strengthened rather than merely fixed.
create_relationship_type_prefers_schema_defined_namesasserted the literal phrase"relevant schema"— which the old description satisfied while also recommendingrelated_to. The test that existed to cover this exact parameter's guidance let the contradiction through. It now asserts substance: point at schema-declared names, name every universal relationship so the model has a legal fallback, and never offerrelated_to.Verification
bun run test:all— exit 0, zero failurescargo build+ full e2e)🤖 Generated with Claude Code