Repository navigation
Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache - #2864
Merged
Merged
Conversation
…he cache The scheduled/cron candidate fan-out read node_type ancestry from PlaybookLifecycleManager::ancestor_cache (via lm.ancestors_of), which is refreshed asynchronously by PlaybookEngine and stays stale after a failed refresh until the next event retries it. get_workflow_state has no access to PlaybookEngine's ancestry_dirty flag or its refresh routine, so it had no way to detect or repair that staleness — a scheduled Play registered on a base type could silently vanish from a subtype node's response with no error and no degraded_reasons entry, right after an extends edit or during a refresh-failure retry window. Resolve the extends chain live instead, via NodeService::resolve_type_chain (the existing uncached resolver already used for one-off reads), once per call, and use it for the scheduled/cron eligibility test in place of the cache read. A resolution failure is recorded in degraded_reasons like every other schema lookup in this function, rather than silently dropping candidates. The graph-event candidate path (lookup_rules -> ancestor_keys) still consults the cache for its own ancestor fan-out and PlaybookEngine's refresh semantics are unchanged — both are out of scope here per the issue's stated non-goals (the live trigger-dispatch hot path cannot afford a query per event the way this out-of-band diagnostic call can). Updates the existing ancestor-fan-out regression test to exercise a real extends edge instead of manually seeding the cache, and adds a new test that seeds the cache with a deliberately wrong/stale entry to prove the fan-out no longer depends on it. Closes #2828 Co-Authored-By: Claude Sonnet 5 <[email protected]>
…stead of a second call Code review on PR #2864 flagged that get_workflow_state was resolving node_type's extends chain twice per call: once inside resolve_field_owners (discarded as _chain), and again via a separate resolve_type_chain call for the scheduled/cron candidate fan-out. Both walk the same get_extends_parent_map() table scan, so this doubled that portion of the call's DB I/O, opened a TOCTOU window where a concurrent schema write between the two awaits could give the property_changed and scheduled/cron halves of one response different ancestry snapshots, and would report a single underlying resolution failure as two separately-worded degraded_reasons entries. resolve_field_owners's third return value is the same chain resolve_type_chain would produce (it calls resolve_type_chain internally and returns the result verbatim), so reuse it directly instead of a second call, and fold the two degradation messages into one. Co-Authored-By: Claude Sonnet 5 <[email protected]>
… gap degraded_reasons only records live resolution failures (an Err from a schema/extends-chain call). The graph-event candidate path's own ancestor fan-out (lookup_rules -> ancestor_keys) still reads PlaybookLifecycleManager::ancestor_cache directly rather than resolving live, and a cache read that returns a stale-but-successful answer never registers as a failure. An empty degraded_reasons could therefore read as stronger confidence than it actually provides for that half of the response. Documents the distinction rather than changing behavior — this gap is the PR's stated non-goal, shared with the live trigger-dispatch path. Co-Authored-By: Claude Sonnet 5 <[email protected]>
7 tasks done
mstomar125
added a commit
that referenced
this pull request
Sep 23, 2026
* Surface ancestor-cache refresh failures in get_workflow_state (closes #2870) get_workflow_state's graph-event candidate path (lookup_rules -> ancestor_keys) still reads PlaybookLifecycleManager::ancestor_cache directly, unlike the scheduled/cron path fixed in #2864 which resolves extends ancestry live. After #2864 the two halves of a response can disagree during a staleness window instead of being wrong together, with no signal either way. Mirror the existing NodeService::playbook_lifecycle OnceLock-injection pattern for PlaybookEngine::ancestry_dirty, wired once from assembly.rs. get_workflow_state reads it off the node_service argument it already receives, so no signature change is needed and no other call site (daemon's gRPC handler, the local-agent tool, or the CLI, which just forwards an opaque JSON blob) needs touching. When the flag is set, a degraded_reasons entry names the failed refresh so a caller can tell the graph-event candidates may be missing a rule registered on an ancestor type. This covers the accurate, unbounded-duration staleness case (a failed refresh not yet retried) but not the ordinary sub-millisecond lag between a schema write and the engine's async refresh reacting to it — documented as out of scope, same as it is for every other in-memory index built the same way. Co-Authored-By: Claude Sonnet 5 <[email protected]> * Address review: clarify ancestry_dirty doc-comment precision Per-database, not process-wide (the daemon runs one PlaybookEngine/ NodeService pair per database id) — wording fix. Also name the brief process-startup window before the first refresh_ancestor_cache runs, where the flag reads false because nothing has failed yet, not because the cache is known fresh — same pre-existing "absent means no ancestry" default ancestor_cache already had, not a new gap. Addresses non-blocking findings from PR review (1 Improvement, 1 Nit) on PR #2891, for issue #2870. Doc-only change, no logic touched — no re-review needed per /address-review's own criteria (simple documentation update, trivial and low-risk). Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
Summary
Closes #2828.
get_workflow_state's scheduled/cron candidate fan-out readnode_typeancestry fromPlaybookLifecycleManager::ancestor_cache(vialm.ancestors_of), which is refreshed asynchronously byPlaybookEngineand stays stale after a failed refresh until the next live event retries it.get_workflow_statehas no access toPlaybookEngine'sancestry_dirtyflag or its refresh routine — it is called with only a lifecycle manager and a node service — so it had no way to detect or repair that staleness. A scheduled Play registered on a base type could silently vanish from a subtype node's response, with no error and nodegraded_reasonsentry, right after anextendsedit or during a refresh-failure retry window.Fix
Resolve the extends chain live instead, via
NodeService::resolve_type_chain— the existing uncached resolver already used for one-off reads (its own doc comment: "Resolved live rather than cached... this is the uncached resolver for write paths and one-off reads") — once perget_workflow_statecall, and use it for the scheduled/cron eligibility test in place of the cache read. A resolution failure now goes through the samedegraded_reasonsreporting every other schema/extends-chain lookup in this function already uses, instead of silently dropping candidates.effective_fields(the property_changed candidate field set) andancestry(the scheduled/cron eligibility chain) are resolved from a singleresolve_field_ownerscall — its third return value is the same live chainresolve_type_chaincomputes internally — rather than two independent calls, so the common path does one extends-chain walk, not two.Scope
The graph-event candidate path (
lookup_rules→ancestor_keys) still consultsPlaybookLifecycleManager::ancestor_cachefor its own ancestor fan-out, andPlaybookEngine's refresh semantics (ancestry_dirty,refresh_ancestor_cache) are unchanged — both are out of scope per the issue's stated non-goals. That fan-out is shared with the live trigger-dispatch hot path (engine.rs/cel.rs), which cannot afford a DB query per event the way this out-of-band, read-only diagnostic call can; re-architecting it is a larger change better suited to its own issue if it's ever needed.degraded_reasons's doc comment now notes this explicitly: an empty vec means no live resolution failed, not that the graph-event half is guaranteed fresh.The issue's second concern (multiple independent async schema reads with no single consistent snapshot across a whole response) is also left out of scope — it's a much broader architectural change (snapshotting arbitrarily-deep relationship-target schemas across every possible condition-path walk) than the concrete, timing-dependent gap this PR closes, and the issue explicitly allows scoping down to a well-documented partial fix.
Sharper framing on the above, worth flagging explicitly: before this PR, both the scheduled/cron and graph-event halves read the same cache, so during a staleness window they were wrong together (silently missing a base-registered Play in agreement). After this PR, cron resolves live while graph-event still reads the cache, so during that same window the two halves of one response can now disagree — a new internal-inconsistency failure mode, not just the original bug left in place. Filed as a follow-up: #2870, which also records why a cheap same-PR mitigation (surfacing
ancestry_dirty, or a per-call cache-vs-live comparison) isn't straightforward given the current cache design.Known trade-off
Because
effective_fieldsandancestrynow share oneresolve_field_ownerscall, a transient DB failure on that call degrades both halves together (fields to the node's own directly-declared set, ancestry to the node's own type) — reported as onedegraded_reasonsentry. Pre-PR, the cron half read the cache independently and so couldn't be taken down by aresolve_field_ownersfailure, but that independence bought silent staleness, not real resilience: the cache read never fails, but it also never tells a caller it might be wrong. Considered reintroducing a second, independentresolve_type_chaincall in just the failure branch to recover that narrow case, but decided against it — it only helps when the failure happens strictly after chain resolution succeeds insideresolve_field_owners(a narrow sub-case, sinceresolve_field_ownersresolves the chain first and a chain-resolution failure would sink both calls identically), and it re-adds exactly the kind of defensive double-resolution the fix above removes, for an already-rare, already-transparent (viadegraded_reasons) edge case. Explicit-and-narrower over silent-and-stale is the intended trade here.Testing
scheduled_trigger_on_ancestor_type_is_returned_for_subtype_nodeto exercise a realextendsedge (viahandle_create_schema) instead of manually seedingancestor_cache— the old version would no longer exercise the code path being tested after this change.scheduled_trigger_on_ancestor_type_survives_stale_ancestor_cache, which seeds the cache with a deliberately wrong/stale ancestry entry while the real schema graph declares a genuineextendsedge, and asserts the scheduled Play is still found — the direct regression test for the bug this PR fixes.cargo test -p nodespace-core --lib playbook::— 447 passed, 0 failed.Test plan
cargo test -p nodespace-core --lib playbook::workflow_state— 14/14 passedcargo test -p nodespace-core --lib playbook::— 447/447 passedcargo clippy -p nodespace-core --lib --all-targets -- -D warnings— cleanbun run test:all+cargo build --bin nodespaced+test:e2e) — passed🤖 Generated with Claude Code