Repository navigation
Flag a turn that creates two unlinked schemas - #2915
Merged
Merged
Conversation
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]>
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 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]>
Contributor
Author
|
Addressed `/pragmatic-code-review` findings:
Full pyramid re-verified: `cargo test -p nodespace-daemon --lib` (243 passed), `bun run quality:fix` clean, pre-push gate passed in full. Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Both changes are localized to `unlinked_pair_note` itself (no change to its call site, signature, or the surrounding turn-completion flow). The fixes are straightforward — a batch-wide `any()` replaced with a per-schema linked-set computation, and a bare `Err(_)` arm split into a logged case — verified by the existing tests plus one new regression test targeting the exact scenario the review found. No new architectural surface, no new external interaction. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2839.
Problem
Relaxing the second-
create_schemaguard (PR #2818) made a new end state reachable: the user asks for a linked pair, both types get created, and the relationship is never declared — two types, no edge, no error. The old guard refused any secondcreate_schemain a turn outright, so this couldn't happen; narrowing it to refuse only types the user never named is what lets a legitimately-requested pair land as two sequential calls, but nothing requires either call to actually declare the relationship back to the other.targetType: Nonestays deliberately unvalidated (validate_relationship_targets_exist,packages/core/src/schema/mod.rs) — a relationship-free schema is legitimate on its own — so nothing previously noticed when both halves of a requested pair land without one.Fix
At turn end (
LocalAgentServiceImpl::run_ai_chat_turn,packages/daemon/src/services/local_agent_service.rs), a newunlinked_pair_notehelper:completed_writes_from(&result.tool_calls_made).update_schema, not just ones declared atcreate_schematime).This deliberately does not try to infer from the user's phrasing whether a linked pair was actually requested — the issue itself calls that signal the hard part, and guessing wrong risks nagging over two independently-requested types. Instead it surfaces the weaker, unambiguous fact (multiple new types, zero edges between them) as an informational note, leaving the decision to the user or a follow-up turn.
Scope note: the second-
create_schemaguard and the agent's turn-loop live inpackages/agent/src/local_agent/agent_loop.rs, which is out of scope for this change. This fix lives entirely in the daemon's turn-completion path instead, re-fetching persisted schema state rather than needing any change to the guard or the ReAct loop.Tests
Three new tests in
packages/daemon/src/services/local_agent_service.rs, using the realhandle_create_schemapipeline against an isolatedNodeService://unlinked_pair_note_flags_two_schemas_created_without_a_relationship— two schemas, no relationship → note naming both.unlinked_pair_note_is_silent_when_the_pair_is_linked— second schema declares the relationship back to the first → no note.unlinked_pair_note_is_silent_for_a_single_schema— one schema created → no note.Verification
cargo test -p nodespace-daemon --lib— 245 passed, 0 failed (242 pre-existing + 3 new)bun run quality:fix— clean (clippy-D warnings, fmt, tsc, design-tokens, skill)bun run test:all,cargo build --bin nodespaced,bun run test:e2e) — passed in full🤖 Generated with Claude Code