Repository navigation
Generalize flatten_chain_fields for relationships, run per-hop resolve calls concurrently - #2862
Conversation
…e calls concurrently (closes #2830) resolve_relationships now reuses the same nearest-scope-wins dedup as resolve_field_owners via a new flatten_chain_by_name generic (keyed by a name_of closure), replacing its own hand-rolled HashSet dedup loop. flatten_chain_fields becomes a thin field-specific wrapper around it. workflow_state.rs's walk_path_against_schema and validation.rs's validate_schema_path each called resolve_field_owners and resolve_relationships sequentially per hop despite neither depending on the other's result. Both now run concurrently: validate_schema_path via tokio::try_join! (both arms react identically to either call failing, so collapsing to the first error loses nothing), and walk_path_against_schema via tokio::join! instead, since its two calls have genuinely independent degrade-and-fallback handling that try_join! would collapse (cancelling the still-in-flight call and discarding a result that would otherwise have succeeded). Not done: caching resolve_type_chain/resolve_field_owners/ resolve_relationships across calls. NodeService has no cache over the extends-chain edges the way PlaybookLifecycleManager's ancestor_cache does for its own consumer, and none of the three call sites here are on the live engine's trigger-dispatch path (get_workflow_state is an explicitly out-of-band diagnostic query per its own module doc), so a shared-cache primitive is left for a follow-up rather than folded into this change. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Pragmatic Code Review — PR #2862 (closes #2830)Scope check against issue #2830. The issue flagged three findings; this PR addresses #2 (sequential → concurrent per-hop resolve calls) and #3 (hand-rolled dedup → generalized 1. Architectural Design & Integrity
2. Functionality & Correctness
3. Concurrency correctness (the PR's most subtle claim — given special scrutiny per instructions)
4. SecurityNo new input handling, no new trust boundaries, no secrets. N/A. 5. Maintainability & ReadabilityDoc comments are updated to match the new implementation, not left stale — 6. Testing StrategyRan the full targeted suite locally: 7. Performance & ScalabilityDirectly addresses the issue's finding #2 (sequential → concurrent), consistent with an existing codebase pattern for independent read-parallelism. Finding #1 (caching) is correctly left out — see scope discussion above. 8. Dependencies & DocumentationNo new dependencies ( SummaryThis is a clean, well-scoped, well-tested refactor. The Nothing found rises to blocking. Two non-blocking suggestions noted above (a one-line comment on the Recommendation: APPROVE |
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
…schema_path Pragmatic-code-review on PR #2862 flagged (Improvement, non-blocking) that collapsing the two independent resolve calls into tokio::try_join! means the reported error string can now come from whichever call loses the race, rather than always resolve_field_owners as before. Documents that this is harmless: both calls fail for the same underlying chain-walk reason against the same node type, and SchemaResolutionFailed's node_type/location fields stay identical either way. Skipped: the review's other (Nit) finding — no integration test forces one of workflow_state.rs's two tokio::join!-ed calls to fail while the other succeeds, the one scenario that would directly distinguish join! from try_join! in a running test. The reviewer itself flagged this as "not requested here" (the current test harness uses a real SqliteStore over a tempdir with no fault-injection seam, so adding one would be disproportionate scope creep for this PR). Co-Authored-By: Claude Sonnet 5 <[email protected]>
The ultra-review's "angle J" finding: flatten_chain_by_name took chain_items by reference (&[Vec<T>]) and cloned every surviving item, where resolve_relationships's original hand-rolled loop moved owned values out of schema.relationships at zero cost. Given this whole PR is about removing per-call inefficiency, cloning on every merge was a self-inflicted regression for the one caller (resolve_relationships) that previously paid nothing here. Every caller of flatten_chain_by_name/flatten_chain_fields builds its chain_items/chain_fields buffer fresh per call and never reads it again afterward, so there is nothing a &[Vec<T>] + Clone signature buys over taking ownership and moving surviving items into the result. Switched both to take Vec<Vec<T>> by value; flatten_chain_fields, resolve_field_owners, resolve_relationships, and resolve_effective_fields (schema/mod.rs) all updated to pass ownership instead of a borrow. This also drops the Clone bound entirely — SchemaRelationship never needed to satisfy it. Folded in a second small fix while touching this function: check `seen.contains(name)` before allocating the owned String for `seen.insert`, so a shadowed (redeclared, discarded) item costs a &str comparison instead of a throwaway allocation — same dedup semantics, cheaper on the common "already seen" path. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Address-review summaryTwo review passes ran on this PR: the pragmatic-code-review agent (APPROVE, posted above) and a separate ultra-level multi-angle review (10 finder angles, posted above as a JSON findings list). Combined, all non-blocking findings were triaged as follows. Addressed
Skipped (with reasoning)
Verification after changes
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: The doc-comment addition is text-only. The The PR is ready for merge (pending the user's own sign-off, per CLAUDE.md's merge-is-not-automatic policy). |
Summary
Closes #2830. Two of the three findings in that issue are addressed; the third (a shared cache for
resolve_field_owners/resolve_relationships/resolve_type_chain) is deliberately left out — see below.resolve_relationships(packages/core/src/services/node_service/schema.rs) hand-rolled its own chain-walk +HashSet<String>-based dedup loop, duplicating the shapeflatten_chain_fields(extends_chain.rs) already provides for fields. Extracted a genericflatten_chain_by_name<T>(chain_items, name_of)inextends_chain.rs;flatten_chain_fieldsis now a thin field-specific wrapper around it, andresolve_relationshipswas rewritten to build its per-schema relationship lists (with the existing type-system-relationship filter and owners map) the same wayresolve_field_ownersbuilds its field lists, then call the shared helper. Added a direct unit test (flatten_chain_by_name_generalizes_over_relationships) exercising the generalization over relationships.resolve_field_ownersandresolve_relationshipssequentially even though neither depends on the other's result:validation.rs'svalidate_schema_pathnow usestokio::try_join!— both arms react identically to either call failing (push oneSchemaResolutionFailedand return), so collapsing to the first error loses no information.workflow_state.rs'swalk_path_against_schemausestokio::join!instead (nottry_join!): its two calls have genuinely independent degrade-and-fallback handling (distinctdegraded_reasonsmessages, distinct schema-local fallbacks) thattry_join!would collapse — a failure in one call would cancel the still-in-flight other call and discard a result that would otherwise have succeeded.tokio::join!preserves the existing independent-failure semantics while still running both concurrently.Deliberately out of scope
No shared cache over
resolve_type_chain/resolve_field_owners/resolve_relationships. The issue's own suggested approach calls this the "ideal" fix but flags it as the largest slice, and notes a smaller well-justified slice is acceptable.NodeServicehas no existing cache over theextends-chain edges the wayPlaybookLifecycleManager::ancestor_cachedoes for its own consumer (graph-event/scheduled trigger matching), and building one raises real design questions this PR doesn't want to rush: cache scope (per-request vs. process-lifetime onNodeService), invalidation (aset_schema_relationships/schema-update write must invalidate it), and thread-safety. None of the three call sites this issue names are on the live engine's trigger-dispatch path —get_workflow_stateis an explicitly out-of-band diagnostic query per its own module doc, andvalidate_schema_pathruns at Play-authoring/validation time, not per-event. Left for a focused follow-up rather than folded into this change.Test plan
cargo test -p nodespace-core --libforschema::extends_chain::,playbook::(workflow_state + validation), andservices::node_service::— all passing (18 + 446 + 162 tests)cargo check -p nodespace-corecleanbun run quality:fixclean (rustfmt + clippy-D warnings -D clippy::unused-async)bun run test:all+cargo build --bin nodespaced+test:e2e) passed in full🤖 Generated with Claude Code