You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generalize the error-collision-detection pattern: structured error kinds instead of one-off variants, and unify schema vs. node collision-resolution paths #2798
Surfaced by an "altitude" review of PR #2796 (core#2792's four latent-defect fixes). None of this blocks or needs to be folded into that PR — it's a genuine architectural observation about the pattern the fix establishes, worth tracking separately.
Finding 1: MarkdownError::AlreadyExists is a narrow, one-off fix to a broader pattern
`InvalidParams(String)` still collapses dozens of other distinct, semantically-meaningful schema rejection reasons (schema not found, reserved field name, field-rename-more-than-once, extensible-only violations, version mismatch, admin-only, etc. — all currently distinguished only by substring assertions in `schema_test.rs`). The same substring-matching anti-pattern #2792 just eliminated for one `MarkdownError` case still lives untouched in `packages/core/src/ops/search_ops.rs` (`err_msg.contains("not initialized")`, `.contains("no embeddings")`, etc.) for a different error type.
Worth considering: a general structured "error kind/reason" mechanism instead of adding one dedicated variant per newly-discovered need.
Finding 2: the forward-first precedence rule is hand-duplicated, not shared
`validation.rs`'s `resolve_forward_segment`/`resolve_reverse_segment` are explicitly self-documented as a hand-copy of `rel_ops::resolve_relationship_name`'s precedence (not a literal call-through, since validate-time schema-only checking lacks the concrete `node_id` the runtime resolver needs). #2792 fixed a drift between the two copies — but the underlying duplication (prose/control-flow, not a shared type or constant) remains, so the same class of drift can recur whenever either side is edited in isolation without remembering the connection.
Finding 3: schema-collision and node-collision detection now use structurally different mechanisms
`create_schema_resolving_collisions` matches the new structured `MarkdownError::AlreadyExists` variant directly. `create_node_resolving_collisions` must fall back to attempt-then-read-verify, because `NodeServiceError`/`DatabaseError` have no structured "duplicate id" signal — a UNIQUE-constraint violation surfaces only as an opaque string. This also leaves a narrow residual race in the node path (if the colliding node is deleted between the failed create and the follow-up verification read, a genuine collision could be misreported as a real fault) that the schema path's direct-match approach doesn't have.
Worth considering: giving node creation's duplicate-id case a structured signal (e.g. a `DatabaseError` duplicate-key variant mapped from the SQLite UNIQUE-constraint error) would let both collision-resolution functions share one generic helper instead of evolving independently.
Non-goals
Not proposing to implement any of this now — genuinely architectural, needs a maintainer decision on whether the generalization is worth it versus continuing to add narrow one-off fixes as needs arise.
Additional, more concrete finding from a later efficiency-focused review pass of PR #2796 — worth folding into this issue's scope since it's the same "the new schema_cache doesn't cover the actual expensive calls" theme already captured above:
resolve_forward_segment and resolve_reverse_segment (packages/core/src/playbook/validation.rs) each independently call node_service.resolve_type_chain(¤t_type) — a live, uncached DB query per that function's own doc comment ("Resolved live rather than cached"). Since forward always runs first and reverse only runs once forward has exhausted the whole chain without a match, any path segment that resolves via a reverse-only name pays for the identical SELECT ... FROM relationship WHERE relationship_type='extends' query twice, back to back, in the same segment resolution. The PR's schema_cache parameter covers schema-node lookups but not the chain resolution itself — extending it (or adding a sibling per-Play chain cache) would close this alongside the get_inbound_relationships gap already noted above.
Also: resolve_reverse_segment's ensure_schema_cached call is confirmed dead code in practice — forward-first ordering guarantees every scope it iterates was already cached by forward's own walk moments earlier, so the call can never actually trigger a fetch. No DB cost, but safe to delete as part of whatever cleanup addresses this issue.
None of this is release-blocking (validate-time only, bounded by rule/segment counts per Play) — same non-blocking framing as the rest of this issue.
A follow-up review pass on PR #2796 surfaced two more concrete instances of Finding 1's pattern (one-off structured errors vs. substring-matched ones), plus a scenario worth folding into Finding 3's scope:
packages/core/src/services/node_service/hierarchy.rs (~line 733): VERSION_CONFLICT is signaled by parsing a raw anyhow error string with strip_prefix, the same fragility class Fix four latent defects in methodology install and Play path validation #2792 eliminated for MarkdownError::AlreadyExists — any rewording of that in-transaction message silently breaks the match.
packages/desktop-app/src-tauri/src/commands/nodes.rs (~line 160): status_to_command_error hardcodes tonic::Code::AlreadyExists to "COLLECTION_EXISTS". PR Fix four latent defects in methodology install and Play path validation #2796 gives handle_create_schema's schema-collision case the same gRPC code, so a future desktop command wired to schema creation would have its "schema already exists" error mislabeled as a collection conflict in the UI. Dormant today (no such command exists yet).
Extending Finding 3: the node-collision path's residual race (colliding node deleted between the failed create and the follow-up verification read) is bounded in practice for its current only caller (create_node_resolving_collisions, static Play properties) — a real diagnosis failure there costs at most one wasted suffix attempt before self-correcting, not silent data loss. Worth noting as a severity data point if/when this gets prioritized.
No code changes made for any of these — still non-blocking, still needs the same maintainer call on whether the generalization is worth it.
Activity
mstomar125 commentedon Sep 22, 2026
Additional, more concrete finding from a later efficiency-focused review pass of PR #2796 — worth folding into this issue's scope since it's the same "the new schema_cache doesn't cover the actual expensive calls" theme already captured above:
resolve_forward_segmentandresolve_reverse_segment(packages/core/src/playbook/validation.rs) each independently callnode_service.resolve_type_chain(¤t_type)— a live, uncached DB query per that function's own doc comment ("Resolved live rather than cached"). Since forward always runs first and reverse only runs once forward has exhausted the whole chain without a match, any path segment that resolves via a reverse-only name pays for the identicalSELECT ... FROM relationship WHERE relationship_type='extends'query twice, back to back, in the same segment resolution. The PR'sschema_cacheparameter covers schema-node lookups but not the chain resolution itself — extending it (or adding a sibling per-Play chain cache) would close this alongside theget_inbound_relationshipsgap already noted above.Also:
resolve_reverse_segment'sensure_schema_cachedcall is confirmed dead code in practice — forward-first ordering guarantees every scope it iterates was already cached by forward's own walk moments earlier, so the call can never actually trigger a fetch. No DB cost, but safe to delete as part of whatever cleanup addresses this issue.None of this is release-blocking (validate-time only, bounded by rule/segment counts per Play) — same non-blocking framing as the rest of this issue.
mstomar125 commentedon Sep 22, 2026
A follow-up review pass on PR #2796 surfaced two more concrete instances of Finding 1's pattern (one-off structured errors vs. substring-matched ones), plus a scenario worth folding into Finding 3's scope:
packages/core/src/services/node_service/hierarchy.rs(~line 733):VERSION_CONFLICTis signaled by parsing a rawanyhowerror string withstrip_prefix, the same fragility class Fix four latent defects in methodology install and Play path validation #2792 eliminated forMarkdownError::AlreadyExists— any rewording of that in-transaction message silently breaks the match.packages/desktop-app/src-tauri/src/commands/nodes.rs(~line 160):status_to_command_errorhardcodestonic::Code::AlreadyExiststo"COLLECTION_EXISTS". PR Fix four latent defects in methodology install and Play path validation #2796 giveshandle_create_schema's schema-collision case the same gRPC code, so a future desktop command wired to schema creation would have its "schema already exists" error mislabeled as a collection conflict in the UI. Dormant today (no such command exists yet).create_node_resolving_collisions, static Play properties) — a real diagnosis failure there costs at most one wasted suffix attempt before self-correcting, not silent data loss. Worth noting as a severity data point if/when this gets prioritized.No code changes made for any of these — still non-blocking, still needs the same maintainer call on whether the generalization is worth it.
malibio commentedon Oct 13, 2026
Frontend: 5899 passed (326 files)
Classify semantic search failures by structured error variant, not me…