Skip to content

get_workflow_state: graph-event candidates can disagree with scheduled/cron candidates during an ancestor-cache staleness window #2870

Closed

Description

@mstomar125

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:

  1. Surface PlaybookEngine::ancestry_dirty in get_workflow_state. This flag is the accurate "has a refresh failed and not yet retried" signal, but it lives on PlaybookEngine, not PlaybookLifecycleManager. 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.

  2. 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_cache cannot distinguish "this type genuinely has no ancestry" from "the cache has never been populated for this type yet" — both fall back to [node_type] in ancestors_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 a PlaybookLifecycleManager directly (without going through PlaybookEngine's startup refresh_ancestor_cache warm-up), which is most of workflow_state.rs's test suite — including several tests with real extends edges 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)

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.

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

Metadata

Metadata

Assignees

Labels

backendbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions