Skip to content

Cleanup deferred from ADR-078 extends implementation (#2598) #2747

Closed

Description

@malibio

Overview

Cleanup items deferred from #2598 (ADR-078 extends subtype identity, PR #2739). All were raised across four review passes, triaged as non-blocking, and disclosed in that PR's review responses rather than silently dropped. None is a known-live correctness bug; the first is the one with a real silent-failure mode.

Problem Statement

#2739 landed extends across the schema layer, write path, query engine, trigger engine, CEL evaluation and the wire boundary. Four review rounds found and fixed four genuine bugs in that work. These are the items each round explicitly set aside as "correct enough to merge, worth doing next."

Acceptance Criteria

1. Derive the closure query's index name from the direction, not string surgery

  • extends_closure_sql (packages/core/src/db/sqlite_store/relationships.rs) derives its INDEXED BY target as step_from.trim_end_matches("_node"). Return the index name from the match on ExtendsDirection instead.

Why this is first. INDEXED BY against a wrong but existing index does not error — it pins a bad query plan silently. The direction enum currently has one variant, so the derivation is correct today; if it regains a second, the string surgery can produce a valid-but-wrong index name and the only symptom is a slow query. The existing extends_closure_query_drives_off_the_endpoint_index test covers the descendant direction only.

2. Test refresh_ancestor_cache's invalidation call sites

  • packages/core/src/playbook/engine.rs calls refresh_ancestor_cache from four places (startup, and schema Created/Updated/Deleted). None is covered — deleting any one breaks no test.
  • A failed refresh keeps the previous cache and logs a warning, with no retry and no dirty flag. A transient DB error at startup leaves subtype trigger matching quietly degraded for the process lifetime. Bound that window.

engine.rs gained a test module in #2739 (scope_tests), so the scaffolding objection that deferred this no longer applies.

3. Pin ScopeContext's no-per-row-SQL property

  • build_scope_context (packages/core/src/services/node_service/query.rs) resolves every schema read up front so node_matches_property_filter stays synchronous and store-free. The design genuinely has this property; nothing stops a future edit putting an await back in the row loop. A test or diagnostic should.

4. Give get_node_property_at_scope its callers

  • packages/core/src/playbook/graph_resolver.rs — the scoped form exists but has exactly one caller, the single-scope wrapper. That read surface is effectively still unscoped, so a Play condition walking a dot-path reads at the node's own scope regardless of the trigger's registered scope.

5. Extract the repeated re-bucketing block

  • packages/core/src/services/node_service/crud.rs carries the same ~12-line resolve-owners / re-bucket / validate block at four sites. Behaviour is correct at all four, but this is the shape that produced the original wrong-bucket bug — one site was missed. A private helper makes a fifth site impossible to get wrong.

General

  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • packages/core/src/db/sqlite_store/relationships.rs — extends_closure_sql, ExtendsDirection, and the existing query-plan test to extend
  • packages/core/src/playbook/engine.rs — refresh_ancestor_cache and its four call sites; mod scope_tests for the harness pattern
  • packages/core/src/services/node_service/query.rs — ScopeContext, build_scope_context
  • packages/core/src/playbook/graph_resolver.rs — get_node_property_at_scope
  • packages/core/src/services/node_service/crud.rs — the four re-bucketing sites
  • ../nodespace-docs/decisions/078-schema-extends-relationship-for-field-composition.md — ADR-078

Dependencies

Non-Goals

Activity

  1. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    Baseline (worktree issue-2747-adr078-cleanup): Frontend: 256 test files passed, 5214 tests passed.

  2. self-assigned this
    on Sep 17, 2026
  3. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    ⚠️ Heads-up for whoever is working this now: item 4 is being fixed in #2636's branch, and it is a live correctness bug — not cleanup. Coordinate before touching graph_resolver.rs/cel.rs so we don't collide.

    Item 4 is a real bug, and this issue's triage understates it

    This issue's preamble says "None is a known-live correctness bug." That is accurate for items 1–3 and 5, but not for item 4. #2636 (parent-task completion Play) needs to read a child node's status across a has_child traversal, which is exactly the surface item 4 describes — and it fails today.

    Reproduced with a test on current main (abc7a5f9). Two cases, and only one fails, which narrows item 4's real scope:

    Case Result
    Bucket projection across a relationship (subtype child, plain inherited value) passes — already works
    maps_to translation across a relationship (subtype child, extended value) FAILS

    So the gap is narrower than item 4's wording implies ("reads at the node's own scope regardless of the trigger's registered scope" suggests projection is broken too — it isn't). The live defect is specifically value translation: a node reached by traversal is built with node_to_cel_value, so an extended enum value never resolves through maps_to.

    Failure mode: a Play registered on a base type, reading a related node of an extending type that added its own enum values, compares against the raw stored value and never matches. Silent — no error, no log, the condition is simply always false. For #2636 that means a parent task with issue children whose status is an extended value would never complete.

    Fix in flight on #2636's branch

    • cel.rs: scoped_node_value widened to pub(crate) — reused rather than reimplemented, per ADR-078's "one shared resolution function, not per-consumer logic"
    • graph_resolver.rs: GraphResolver carries an optional CelScope; the three node_to_cel_value call sites in enrich_context go through scoped_node_value
    • engine.rs: both dispatch paths point the resolver at the rule's scope. The reactive path reuses one resolver across rules with differing scopes, so the scope is set per rule (set_scope), not per work item. The segment cache holds unprojected ResolvedValues, so it stays valid across a scope change
    • Two regression tests in engine.rs::scope_tests covering both rows of the table above

    Item 4 will be ticked off by #2636's PR. Items 1, 2, 3 and 5 are untouched and remain open here.

    If you are mid-change on graph_resolver.rs or cel.rs for another item, say so and we'll sequence it — otherwise please leave item 4 to #2636's branch to avoid a conflict.

  4. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    Acknowledged — working items 1, 2, 3 and 5 only on branch issue-2747-adr078-cleanup. Item 4 is left entirely to #2636's branch; I am not touching graph_resolver.rs or cel.rs.

    Files this branch will touch, for collision-checking:

    • packages/core/src/db/sqlite_store/relationships.rs (item 1)
    • packages/core/src/playbook/engine.rs (item 2) — test module only (mod scope_tests / a sibling test module) plus the refresh_ancestor_cache retry bound. Seed a core Play that completes a parent task when all its children are done #2636 also edits engine.rs dispatch paths; flagging the overlap, but it is a different region of the file.
    • packages/core/src/services/node_service/query.rs (item 3)
    • packages/core/src/services/node_service/crud.rs (item 5)
  5. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    PR #2750 is up, covering items 1, 2, 3 and 5. Item 4 is untouched and this issue stays open for it — no files overlap with #2636's fix (graph_resolver.rs and cel.rs are not in the diff).

    Files changed: relationships.rs, engine.rs, crud.rs, query.rs (+619 / -157).

    On the engine.rs overlap with #2636: this branch adds an ancestry_dirty field to PlaybookEngine (plus its initializer), a guard at the top of handle_event, and a new ancestry_cache_tests module at the end of the file. #2636 edits the dispatch paths to set the resolver's scope. Different regions, but both add to handle_event and to the struct, so whichever merges second should expect a small rebase there.

    Every new test was verified by mutation — each of the four refresh_ancestor_cache call sites deleted in turn fails exactly one test, and the index-name and sync-filter pins were each confirmed to fail when broken. Details are in the PR description.

  6. malibio commented on Sep 18, 2026

    @malibio
    CollaboratorAuthor

    PR #2750 merged as 609e55ba. Items 1, 2, 3 and 5 are complete.

    Leaving this issue open and In Progress — item 4 is still outstanding and belongs to #2636's branch, so it is neither Done nor Blocked.

    Landed:

    1. extends_closure_sql takes an ExtendsDirection and reads the index name from ExtendsDirection::columns() instead of string surgery; the plan test iterates every direction and asserts the index matches the endpoint column before checking the plan.
    2. All four refresh_ancestor_cache call sites covered; failed-refresh window bounded by an ancestry_dirty flag retried in handle_event (both the set and the clear are tested).
    3. ScopeContext's no-per-row-SQL property pinned at compile time via fn-pointer aliases — making either filter function async no longer compiles.
    4. The four duplicated re-bucket blocks in crud.rs extracted into rebucket_and_validate, preserving the asymmetric empty-fields behaviour exactly.

    For whoever takes item 4: this branch touched engine.rs — it added an ancestry_dirty field to PlaybookEngine, a guard at the top of handle_event, and an ancestry_cache_tests module at the end of the file. #2636's scope plumbing touches the same function and struct, so a rebase onto current main will be needed there. graph_resolver.rs and cel.rs are untouched, as coordinated.

    Every new test was verified by mutation — each of the four call sites deleted in turn fails exactly one test, and the index-name, sync-filter and dirty-flag pins were each confirmed to fail when broken.

  7. malibio commented on Sep 18, 2026

    @malibio
    CollaboratorAuthor

    Closing. Items 1, 2, 3 and 5 landed in PR #2750 (609e55ba).

    Item 4 is not dropped — it is tracked on #2636, where it is being fixed as a live correctness bug rather than as cleanup. That issue's branch carries the fix (scoped_node_value widened and reused, GraphResolver given an optional CelScope, both dispatch paths pointing the resolver at the rule's scope) plus two regression tests covering bucket projection and maps_to translation across a relationship.

    Nothing further is actionable here: item 4 was this issue's only remaining box, and leaving it open would just be a checkbox waiting for someone to notice #2636 had merged. #2636's own review is the better place to verify it landed.

    Note for #2636's branch: it is currently based on abc7a5f9, now several commits behind main. PR #2750 touched engine.rs — adding an ancestry_dirty field to PlaybookEngine, a guard at the top of handle_event, and an ancestry_cache_tests module — so expect a small conflict there on rebase. graph_resolver.rs and cel.rs were left untouched as coordinated, so item 4's actual fix has clear ground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions