Repository navigation
Split the two-linked-types ordering constraint out of the one-schema policy - #2818
Conversation
…policy (closes #2812) The "one schema per request" rule packed a restraint policy and a mechanical ordering constraint into one paragraph, with the policy leading and owning all the examples. An agent asked for two explicitly-linked types correctly judged the policy didn't apply, and skimmed past the constraint that did — then planned a single call pointing at a type that didn't exist yet. Three changes: - Rescope ONE_SCHEMA_PER_REQUEST to the restraint policy alone, renamed "only the types asked for". It now says explicitly that it governs restraint, not call count, so a legitimately-requested pair doesn't read as forbidden. - Add CREATING_TWO_LINKED_TYPES, stating the sequencing remedy the rules never assembled: create the target type first, then the referencing type declaring the relationship on the referencing side, whose required reverseName gives the other end its accessor for free. One stored edge, no schema update. - Fix TARGET_TYPE_MUST_EXIST, where "omit the relationship entirely" was the only escape offered. That silently delivers two unlinked types when the user asked for linked ones; omission is now scoped to targets never asked for. Wired into both renderers — the in-app agent prompt via schema_creation_guidance() and the skill markdown via gen_skill_md — so the rule can't reach one surface and not the other. Golden snapshot regenerated; the diff is the three edits above. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Pragmatic Code Review — PR #2818Review Type: Initial Review (no prior reviews on this PR) Requirements Check (issue #2812)
Issue requirements are met. Scrutiny Items You Raised1. Does the new text fix the reported failure mode? Reading the prompt in emission order (
There is no remaining path I can find where the agent reads the policy and stops after one call. The three formerly-divergent surfaces now converge. Same structure holds in 2. Cross-reference resolution. Verified both directions, both renderers:
Imperative/prose halves agree in substance on all three rules — I diffed them clause by clause. The only asymmetry is deliberate: the imperative adds 3. Audit of the rest of I grepped the whole file for "omit the relationship", "single … call", "one call", "then stop and report". Results:
Outside 4. Technical correctness of the example — verified against source. The example is not merely plausible; it is verbatim an existing passing test: Point by point:
No technical defect in the example. 5. Golden file.
Code Review Findings🟡 Important🟡-1 📁 This is the last surviving instance of the exact framing the PR set out to remove, and it renders at
An agent that has just read "that is TWO create_schema calls, not one", then makes the first call and gets a schema object back, reads the very next rule as "do NOT call create_schema again" and "respond to the user immediately". That is a direct instruction to stop at exactly the point the new rule says to continue — and it arrives later in the prompt, which for a sequentially-read instruction block is the stronger position. The rule's intent is clearly anti-re-try ("do not re-issue the same call to double-check"), the same intent This is the same class of defect as the one being fixed: two distinct meanings (don't re-verify vs. don't proceed) packed into one sentence, where the model picks the wrong one. Leaving it means the fix is complete at the planning stage but can still be undone at the execution stage — and the failure would be invisible, delivering one type where two were requested. Suggested narrowing (both halves):
Principle: single-responsibility applied to instructions — one rule, one decision. It is also the precise defect class this PR exists to eliminate, so fixing it here keeps the change atomic rather than leaving a known instance of the same bug behind. 🟡-2 📁
One-line fix: Principle: DRY / single source of truth. A hand-written paraphrase of a generated rule is a drift source by construction; here it has already drifted. 🟢 Suggestions🟢-1 📁 PR description — the claimed test gap does not exist; the guard is already there The PR body states:
This is not accurate.
Its So: no follow-up issue is needed, and no new guard belongs in this PR. My recommendation on your question 5 is neither — the correct action is to delete that paragraph from the PR description so it doesn't seed a duplicate issue. (Answering your framing directly: had the guard genuinely been missing, it would have belonged in this PR, not a follow-up — the PR is the point at which the gap was proven to bite.) Worth noting why it didn't save you during implementation: the guard lives in 🟢-2 📁
🟢-3 📁
Nitpicks
Standards Compliance
AssessmentThis is a well-executed, genuinely net-positive change, and the diagnosis in the issue and commit message is unusually sharp — the split between "policy" and "ordering constraint" is the right abstraction boundary, and pulling the constraint out so it owns its own worked example is the correct fix rather than a reworded patch. The example is not just correct but is a live test in Two things keep this from a clean approve. 🟢-1 is worth acting on before merge too, purely so the PR description doesn't seed a follow-up issue for a guard that already exists and already passes. Recommendation: REQUEST CHANGESBlocking on 🟡-1 and 🟡-2 (both one-paragraph edits; 🟡-1 needs the golden regenerated). 🟢-1 is a PR-description correction. 🟢-2, 🟢-3 and the nits are optional or out of scope. |
malibio
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES (posted via --comment — GitHub blocks self-approval/self-request-changes on one's own PR).
Full review: #2818 (comment)
Summary: Strong, correctly-diagnosed change. The policy/ordering split is the right abstraction boundary, the worked example is verbatim a passing test (packages/core/src/schema/schema_test.rs:3083), reverseCardinality: "many" is confirmed the correct direction against packages/core/src/ops/rel_ops.rs:626-630, customer/invoice are the correct normalized schema IDs, cross-references resolve in both renderers, and the golden diff is clean. Agent 643 passed / skill_md_generation 11 passed.
Two blocking items, both small:
- 🟡
packages/agent/src/skill_rules.rs:64(SCHEMA_ALREADY_EXISTS) still says "do NOT call create_schema again" and renders two lines after the new rule (golden:39). An agent told "that is TWO create_schema calls" makes the first, gets a schema object, and then reads a later, stronger-positioned instruction to stop. Same packed-instruction defect this PR exists to remove — anti-re-verify intent, but worded as anti-proceed. Needs narrowing to "that same call" plus the golden regenerated. - 🟡
packages/skill/SKILL.md:217still reads "one schema per request". That file has noBEGIN GENERATEDmarkers, so regeneration will never fix it, and it names a rule that no longer exists under that name.
One correction to the PR description (non-blocking): the claim that "nothing currently guards the markdown half" is not accurate — every_schema_rule_reaches_the_skill (packages/cli/tests/skill_md_generation.rs:548) is exactly that guard, its skill_md() helper covers references/*.md, and I reproduced the failure by reverting the gen_skill_md.rs interpolation. No follow-up issue needed and no new guard belongs in this PR — just drop that paragraph so it doesn't seed a duplicate. It didn't catch you during implementation only because it lives in packages/cli tests, which cargo test -p nodespace-agent doesn't run.
Remaining findings (60-char prefix collision in the guard, a pre-existing "above" that points below, two nits) are optional or out of scope.
Addresses review of #2818, plus a contradiction the review surfaced. The prose fix in the previous commit told the agent that a linked pair is two sequential create_schema calls. The in-app agent could not comply: a structural guard in agent_loop.rs refused ANY second create_schema in a turn, and its refusal message told the model the opposite — that a two-type request "needs its own follow-up request". The prompt instructed an action the runtime blocked. The existing test made the defect explicit. Its user message was "keep track of invoices and customers" — both types named — and it asserted the Customer call must be refused. That encoded the very bug #2812 reports, one layer down: the user asks for two linked types and silently gets one. The guard now turns on whether the user named the type rather than on call count, so it still blocks inventing an unrequested type (its actual purpose) while permitting the second type of a legitimately-requested pair. - second_schema_should_be_refused() replaces the bare call-count check - user_message_names_type() does the matching: case-insensitive, tolerates plurals, requires every word of a multi-word name. Deliberately loose — a false positive only permits a type the user probably did ask for, while a false negative reinstates the bug being fixed - The refusal message no longer claims a one-type-per-request cap, and names the type it refused - second_create_schema_in_one_turn_is_not_executed inverted and renamed: its own scenario names both types, so both must now execute - New test for an unrequested type (Sprint) still being refused - New unit tests for the matching helper's case/plural/multi-word behavior Verified the new tests are load-bearing: with the guard reverted, the user-named test hangs (the refused call leaves the loop with no scripted round) while the unrequested-type test still passes. Also from review: SCHEMA_ALREADY_EXISTS said "do NOT call create_schema again", which read as a stop signal immediately after being told to make a second call — narrowed to that same type. SKILL.md's "one schema per request" aside was stale and is hand-written, outside the generated markers. Dropped a GitHub issue number from a code comment per CLAUDE.md. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Pragmatic Code Review — PR #2818 (Re-Review)Review Type: Re-Review Previous Review Summary
All three actionable findings resolved. Nothing regressed. The Test Inversion — Independent ScrutinyYou asked me to attack this rather than accept it. I went to the history and to the two mechanisms. The inversion is justified, and the reasoning is stronger than the version in the PR description — but it is stronger for a different reason than you gave, and the "hangs without the fix" claim is wrong. Details below. Was the original test about a different scenario than its user message describes?I traced the guard to its origin:
And its acceptance criterion, verbatim: "If a split is ever correct, the resulting types are actually linked and both are populated — no silently empty half." This is decisive, and it cuts in your favour more sharply than your own argument does. The harm the original guard was written to prevent was a dangling/unlinked split, not two types existing. The issue text explicitly contemplates that "if a split is ever correct" — it never asserts one type per request as a safety property. The call-count cap was one of two mechanisms proposed in that issue ("either surface a stronger warning… or reject the second So: the test's user message ("keep track of invoices and customers") was not a sloppy fixture that accidentally described a legitimate scenario. It described the exact scenario the parent issue called a possibly-correct split, and the implementation then refused it. Your reading is right — the test encoded the bug one layer down. The over-broad cap was an implementation shortcut against a criterion that never demanded it. Is there harm the call-count cap prevented that the data-layer validation does NOT cover?This is the question that would have blocked the PR, so I worked it independently rather than checking your answer. The same commit I then looked for residual harm the cap alone covered:
Does the new pair of tests cover what the original single test covered?Yes, and with better resolution. The original asserted one thing (second call refused) on a fixture whose message named both types — conflating "refuse unrequested" with "refuse second". The new pair separates them along the axis that now matters: Verdict on the inversion: legitimate. This is a test that was wrong, not a test bent to fit. The history supports it independently of the PR's framing. Findings🟡 Important🟡-1 📁 The PR description says:
and you asked me whether a hang is a fragile failure mode. It would be — but it isn't what happens, and that matters because the claim is doing load-bearing work as evidence the test is non-vacuous.
if idx >= responses.len() {
// Return empty response if we run out of pre-configured ones
on_chunk(StreamingChunk::Done { ... });
return Ok(InferenceUsage { prompt_tokens: 0, completion_tokens: 0 });
}It returns a clean empty So the real regression behavior is a clean assertion failure on Two consequences, both small:
I'd have raised this as 🟢 if it were only a wording slip, but a stated verification result that the code contradicts is the kind of thing that outlives the PR. No code change required. Principle: claims in review artifacts are load-bearing documentation; an unfalsifiable-because-false verification claim is worse than none. 🟢 Suggestions🟢-1 📁 I compiled the function standalone and ran it against the cases you flagged plus the ones I could construct. Results that matter:
On your fail-open argument — "a false positive only permits a type the user probably asked for" — I think it is mostly right but stated too strongly, and the gap is the negation row. I still land where you land, though, for a reason worth making explicit in the doc comment rather than the one that's there now: the guard is a backstop, not the primary control. The prose rule is the primary control, and a model that has just been told "only the types asked for" and then invents The substring rows ( Non-ASCII: no defect. 🟢-2 📁
On "can't wrongly refuse a valid call whose name field is shaped differently": I checked the tool schema ( One small note: the same 🟢-3 📁 You asked for arity and wording. Arity: correct. Four No test pins the removed sentence. I grepped for the removed phrases across all of Wording — this is the right call and the highest-leverage placement in the whole PR. The model reads this at the exact moment it makes the mistake, which beats any amount of upfront prompt. Substance is correct and matches The one soft spot: "create '{target}' first, then re-send this schema with the relationship." "Re-send this schema" is slightly ambiguous about what to re-send — the model has to infer it means the identical payload it just submitted, unchanged, after an intervening call. Compare the prompt rule, which is concrete about the sequence ("create Customer (no relationship), then create Invoice with {...}"). A model that misreads "re-send" as "send a correction" may start mutating the payload. Suggested tightening:
Minor; the current text is not wrong, just less concrete than its siblings. Also worth noting for completeness: this message is reachable from 🟢-4 📁 Grepping for the old phrasing after your let system = "You are a schema-design assistant. … Do not create more than one schema per request.";This is not blocking and I am not asking you to change it: it is an Nitpicks
Standards Compliance
AssessmentThe follow-up commit is the stronger half of this PR. Tracing a prose contradiction into a runtime guard that made the new rule unfollowable is the kind of finding that justifies a review existing at all — the prose fix alone would have shipped a rule the in-app agent structurally could not obey, and nothing in the test suite would have said so. On the inversion, which is the thing that needed to survive scrutiny: it survives. I went to The uncommitted Everything from the previous review is addressed, and 🟡-1 was addressed well rather than minimally — the rewrite separates re-verify from proceed instead of just deleting the offending clause. Nothing here blocks. The one 🟡 is a factual correction to the PR description (the "hangs without the fix" claim is contradicted by Recommendation: APPROVEMerge-ready once the "hangs" sentence in the PR description is corrected. 🟢-1 through 🟢-4 and the nits are optional. Two suggested follow-up issues: (1) structural detection of a linked-pair request that ends up unlinked; (2) word-boundary matching in |
malibio
left a comment
There was a problem hiding this comment.
Verdict: APPROVE (posted via --comment — GitHub blocks self-approval on one's own PR).
Full re-review: #2818 (comment)
All three previous findings addressed. 🟡-1 (SCHEMA_ALREADY_EXISTS) was addressed well rather than minimally — it separates re-verify from proceed instead of deleting the offending clause. 🟡-2 (SKILL.md:217) now also carries the ordering constraint forward. 🟢-1 PR-description claim corrected.
On the test inversion — it survives scrutiny. I went to db708a90 and issue #1905 independently. The originating issue is explicit that a split may be correct ("If a split is ever correct, the resulting types are actually linked and both are populated") and that the mechanism was unsettled ("not prescriptive — the actual mechanism needs its own investigation"). Its criterion was "no silently empty half", never one-type-per-request. The call-count cap was an over-broad implementation of a narrower requirement, and the data-layer guard shipped in that same commit — validate_relationship_targets_exist, untouched here, both call sites live at mod.rs:1161 and :1935 — is what actually addresses the issue's harm. Your two-mechanism argument is correct.
One residual gap the cap covered and the data layer does not: two types created but left unlinked (targetType: None is deliberately unvalidated, mod.rs:402). Not blocking — it is strictly less harmful than the behavior it replaces (half a request, silently), and closing it structurally is a feature. Worth filing.
One 🟡, and it resolves in your favour. The PR description's "with the guard reverted, the test hangs" is not what happens. MockEngine::generate handles exhaustion explicitly (agent_loop.rs:3887-3900, returns an empty Done), and the ReAct loop is bounded by MAX_TOOL_ITERATIONS = 5 (agent_loop.rs:35). The real regression mode is a clean assert_eq! failure — the good failure mode you were hoping for. Just correct the description sentence; no code change.
Uncommitted mod.rs change verified. Arity correct (4 placeholders, 4 args). No test pins the removed sentence — all four assertions at schema_test.rs:3359,3525,3532,3540 match the preserved "not an existing schema" clause; nothing in the repo matches "omit the relationship entirely". rust:test:lib 1604/1604, clippy clean. Highest-leverage edit in the set. One soft spot: "re-send this schema" is less concrete than its sibling rules and reads oddly from the add_schema_relationship call site — suggest "send this same create_schema call again unchanged".
Heuristic probed empirically (compiled standalone). Confirmed false positives: Note/"make a note of this", Ask/"tasks", Boo/"books", Sprint/"don't create a Sprint" (negation), Bug Report/"a report about bugs". Your fail-open argument is mostly right but stated too strongly — the negation case is not "probably did ask for". The asymmetry that actually justifies it is severity, not likelihood: a false negative silently delivers half a request, a false positive creates a visible deletable type. Worth amending the doc comment at agent_loop.rs:653-658. Non-ASCII is fine (Unicode-aware lowercase/alphanumeric; the s-stem is Anglocentric but fails closed into exact match).
The "" fallback is correct — malformed call refused, and repair_parsed_tool_arguments runs before the guard so it is only reachable for genuinely malformed calls. Guard bypass is closed: user_message at the guard site is the raw run_turn parameter (no shadowing), sourced in the daemon from history.last() gated on m.role == Role::User (local_agent_service.rs:751) — model output cannot reach it.
Tests: agent lib 645, skill_md_generation 11, rust:test:lib 1604, clippy clean, skill resource copies byte-identical. Standards clean — the diff removes an issue-number comment.
Merge-ready once the "hangs" sentence is corrected. Suggested follow-ups: (1) structural detection of a linked-pair request that ends up unlinked; (2) word-boundary matching to drop the Ask/tasks substring class.
…ic's rationale Addresses the re-review of #2818. The data-layer validator that rejects a dangling targetType carried the same "omit the relationship entirely" advice this PR removes from the prose — and in the highest-leverage place, since the model reads it at the instant it makes the mistake. It now tells the model to create the target type first and send the same call again when the user asked for both types, and scopes "omit" to types the user never asked for. The re-review also falsified the justification in user_message_names_type's doc comment. "A false positive only permits a type the user probably did ask for" is wrong: substring matching also says yes to a negated mention ("don't create a Sprint, just an ADR") and to incidental words ("make a note of this"). The asymmetry that does justify matching loosely is severity, not likelihood — a false positive creates a visible, deletable type, while a false negative silently delivers half a request. Comment restated; behavior unchanged, since the conclusion still holds. Left alone deliberately: binding the args["name"] lookup once would mean hoisting it above the if-chain and computing it on every tool call to save a map lookup on a rare path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The suggested wording applied in the previous commit said "send this same call again unchanged". That is right for create_schema, but validate_relationship_targets_exist has two callers — create_schema (mod.rs:1161) and update_schema's add_relationships path (mod.rs:1935) — and re-sending an update_schema call unchanged after creating the target is not the same operation the model just attempted. The message cannot assume which caller it is under. "Retry this call" is correct for both. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
* Flag a turn that creates two unlinked schemas Relaxing the second-create_schema guard (PR #2818) made it possible for a legitimately-requested linked pair to land as two sequential calls that never declare a relationship to each other -- targetType: None is intentionally unvalidated (a relationship-free schema is legitimate on its own), so two unlinked types was a silent, valid outcome. At turn end, re-fetch every schema created this turn and check whether any relationship connects two of them. When two or more were created and none do, append a short note to the assistant's response rather than guess at user intent from phrasing. Closes #2839. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Describe the guard gap directly instead of citing issue/PR numbers Per repo convention, code comments describe behavior/constraints directly rather than embedding GitHub issue or PR numbers. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Address review: per-schema orphan detection, log re-fetch errors Address review: per-schema orphan detection instead of a single existential check over the whole batch. With three or more schemas created in a turn, two of them being linked to each other used to suppress the note even when a third was a genuine orphan. Now every created schema is checked individually against the set, and the note names only the orphan(s) when the batch is partially linked. Also log a genuine re-fetch failure (a real NodeService error, not "schema not found") via tracing::warn!, matching this file's other error arms, instead of collapsing it into the same silent return as the benign case. Addresses reviewer recommendations from PR review. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Closes #2812.
Problem
ONE_SCHEMA_PER_REQUESTpacked two rules of different kinds into one paragraph: a policy about restraint and a mechanical ordering constraint. The policy led and owned both examples; the constraint arrived last, in a subordinate clause, framed as a side-effect prohibition.An agent asked for "Customer and Invoice, linked" read the policy, correctly judged it didn't apply — both types were requested — and skimmed past the constraint that did. It planned a single call creating
Customerwith a relationship pointing at a not-yet-existentinvoice.The prose fix
ONE_SCHEMA_PER_REQUEST→ "only the types asked for" — rescoped to the restraint policy alone, and now states explicitly that it governs restraint, not call count.CREATING_TWO_LINKED_TYPES— states the sequencing remedy the rules never assembled: create the target type first, then the referencing type declaring the relationship on the referencing side, whose requiredreverseNamegives the other end its accessor for free. One stored edge, noschema updatefollow-up.TARGET_TYPE_MUST_EXIST— "omit the relationship entirely" was the only escape offered, which silently delivers two unlinked types. Omission is now scoped to targets the user never asked for.SCHEMA_ALREADY_EXISTS— said "do NOT call create_schema again", which renders immediately after the new rule and read as a stop signal right after being told to make a second call. Narrowed to that same type.SKILL.md— a hand-written aside still said "one schema per request". It sits outside the generated markers, so regeneration would never have corrected it.The runtime contradiction the review surfaced
Review of the prose change turned up something larger: the in-app agent could not follow the new rule. A structural guard in
agent_loop.rsrefused any secondcreate_schemain a turn, and its refusal message told the model that a two-type request "needs its own follow-up request" — the direct opposite of the new guidance.The existing test made it explicit. Its user message was
"keep track of invoices and customers"— both types named — and it asserted theCustomercall must be refused. That encoded the bug this issue reports, one layer down: ask for two linked types, silently get one.The guard now turns on whether the user named the type, not on call count:
second_schema_should_be_refused()replaces the bare call-count checkuser_message_names_type()does the matching — case-insensitive, tolerates plurals, requires every word of a multi-word name. Deliberately loose: a false positive only permits a type the user probably did ask for, while a false negative reinstates the bug being fixedTests
second_create_schema_in_one_turn_is_not_executedinverted and renamed to..._for_a_type_the_user_named_executes— its own scenario names both types, so both must execute..._for_an_unrequested_type_is_not_executed(aSprintnobody asked for) — the policy keeps its teethVerified load-bearing. With the guard reverted,
..._user_named_executesfails its call-count assertion (only onecreate_schemareaches the executor, not two) while..._unrequested_type_is_not_executedstill passes. The new test fails without the fix rather than passing vacuously.Two renderers
These constants feed the in-app agent prompt (
imperative) and the generated skill markdown (prose). Both use explicit named-substitution templates, so adding a rule toSCHEMA_RULESrenders it nowhere until it is interpolated into each:schema_creation_guidance()—packages/agent/src/skill_pipeline.rsrender_schema_rules_block()—packages/cli/examples/gen_skill_md.rsBoth are guarded:
schema_rules_are_wired_or_explicitly_excluded(agent) andevery_schema_rule_reaches_the_skill(packages/cli/tests/skill_md_generation.rs:548). An earlier draft of this PR claimed the markdown-side guard was missing — it isn't; it lives inpackages/clitests, whichcargo test -p nodespace-agentdoesn't run.Note on the issue's file path
The description cites
packages/skill/src/skill_rules.rs; the real path ispackages/agent/src/skill_rules.rs(line numbers are correct). Correction posted on the issue.Verification
cargo test -p nodespace-agent— 645 passed, 0 failedcargo test -p nodespace-cli --test skill_md_generation— 11 passedbun run quality:fix— clippy / tsc / fmt / design-tokens cleanbun run skill:check— skill content up to date🤖 Generated with Claude Code