Repository navigation
Description
Context
Follow-up from PR #2864 (closing #2828), which made get_workflow_state's scheduled/cron candidate fan-out resolve node_type's extends ancestry live (via NodeService::resolve_type_chain) instead of reading the possibly-stale PlaybookLifecycleManager::ancestor_cache. The graph-event candidate path (lookup_rules -> ancestor_keys in packages/core/src/playbook/lifecycle.rs) was explicitly left unchanged, per #2828's own non-goals — it's shared with the live trigger-dispatch hot path (engine.rs/cel.rs), which cannot afford a DB read per event the way get_workflow_state's out-of-band diagnostic call can.
Problem — sharper framing than "staleness still exists"
Before #2864, both halves of a get_workflow_state response (scheduled/cron and graph-event) read the same cache, so during a staleness window they were wrong together: a base-registered Play could be silently missing from both, in agreement.
After #2864, cron resolves live while graph-event still reads the cache. During that same staleness window, the two halves can now disagree within a single response: a scheduled Play on a base type is correctly found, while a property_changed rule registered the same way on the same base type (via lookup_rules's ancestor fan-out) can still be silently missing. This is a new internal-inconsistency failure mode, not just the original bug left in place for one path.
degraded_reasons does not (and, per below, cannot cheaply) flag this: a cache read that returns a stale-but-successful answer is not a resolution failure, so nothing records it. WorkflowState::degraded_reasons's doc comment (added in #2864) notes this limitation explicitly.
Why a cheap fix isn't straightforward
Two approaches were considered and rejected as part of #2864's review, for these reasons:
-
Surface
PlaybookEngine::ancestry_dirtyinget_workflow_state. This flag is the accurate "has a refresh failed and not yet retried" signal, but it lives onPlaybookEngine, notPlaybookLifecycleManager.get_workflow_state's signature (lifecycle: &Arc<RwLock<PlaybookLifecycleManager>>,node_service: &Arc<NodeService>) has no path to it without a real API change touching every call site (packages/daemon/src/services/node_service.rs,packages/agent/src/local_agent/tools.rs,packages/cli). This is exactly the kind of signature/architecture change both get_workflow_state's cron/scheduled and graph-event candidates read inconsistent extends-chain views (cache vs. live, no shared snapshot) #2828 and Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache #2864 scoped out. -
Compare the live-resolved chain against
lm.ancestors_of(&node.node_type)per call, and flag a mismatch. Cheap and needs no new access, but has poor precision with the cache's current design:ancestor_cachecannot distinguish "this type genuinely has no ancestry" from "the cache has never been populated for this type yet" — both fall back to[node_type]inancestors_of. Confirmed empirically while prototyping this during Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache #2864's review: it false-positives in every existing unit test that builds aPlaybookLifecycleManagerdirectly (without going throughPlaybookEngine's startuprefresh_ancestor_cachewarm-up), which is most ofworkflow_state.rs's test suite — including several tests with realextendsedges that predate Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache #2864 and are unrelated to cache staleness. Shipping this would have required touching those tests too, well outside get_workflow_state's cron/scheduled and graph-event candidates read inconsistent extends-chain views (cache vs. live, no shared snapshot) #2828/Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache #2864's scope, for a signal that isn't actually precise.
Possible directions (not prescribed)
- Give
get_workflow_statereal access toancestry_dirty(a signature/plumbing change) and surface it directly when set — accepting it's process-wide, not per-node-type. - Redesign
ancestor_cacheto distinguish "never populated for this type" from "resolved to no ancestry" (e.g.Option<Vec<String>>per entry, or a separate populated-set), which would make a precise per-call staleness comparison possible. - Make
lookup_rules's ancestor fan-out resolve live too, matching the scheduled/cron path — the largest option, since it touches the live trigger-dispatch hot path shared withengine.rs, which is the reason it was scoped out of both get_workflow_state's cron/scheduled and graph-event candidates read inconsistent extends-chain views (cache vs. live, no shared snapshot) #2828 and Resolve get_workflow_state's scheduled/cron ancestry live, not from the cache #2864 in the first place.
Non-goals
Same as #2828: no change to PlaybookEngine's existing refresh semantics or the live trigger-dispatch path, unless a chosen direction above requires it deliberately.
Activity
Address review: clarify ancestry_dirty doc-comment precision