Repository navigation
Surface ancestor-cache refresh failures in get_workflow_state - #2891
Conversation
…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]>
Pragmatic Code Review — PR #2891Scope confirmed via 1.
|
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.
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]>
|
Addressed the review's two non-blocking findings, both doc-comment wording fixes in
No logic changed, no new tests needed — pure doc-comment precision. Per Ready to merge, pending sign-off. |
Summary
Follow-up from #2828/PR #2864.
get_workflow_state's scheduled/cron candidate fan-out was fixed to resolvenode_type'sextendsancestry live, but the graph-event candidate path (lookup_rules->ancestor_keysinpackages/core/src/playbook/lifecycle.rs) still reads the possibly-stalePlaybookLifecycleManager::ancestor_cache. After #2864 the two halves of a response can disagree during a staleness window instead of being wrong together, with no signal recorded either way.This issue's own text documents two directions already prototyped and rejected during #2828's review (a naive per-call cache-vs-live comparison that false-positived on most of
workflow_state.rs's existing tests, and a full signature change threading an engine handle through every call site including the Michael-ownedpackages/agent/src/local_agent/lane). I found a third path that avoids both problems:NodeServicealready has an establishedOnceLock-injection pattern for exactly this class of problem —playbook_lifecycleis injected post-construction (the play engine is built from an already-constructedNodeService, so it can't be passed atNodeService::newtime) and read back internally wherever needed.playbook_ancestry_dirty: Arc<OnceLock<Arc<AtomicBool>>>field mirroring that pattern exactly, plus aPlaybookEngine::ancestry_dirty()accessor mirroring the existinglifecycle()one, wired together inassembly.rsright next to the existingset_playbook_lifecyclecall.get_workflow_statereads the flag off thenode_serviceargument it already receives — no new function parameter, so no signature change and no other call site needs touching: not the daemon's gRPC handler, not the local-agent tool (packages/agent/src/local_agent/tools.rs— confirmed untouched, verified via a full workspacecargo check), not the CLI (its response is an opaqueresult_jsonblob, so the newdegraded_reasonsentry flows through automatically).OnceLockdefaults to unset everywhere it isn't explicitly wired (every existing test, most non-daemon callers), so nothing that doesn't wire it observes any behavior change.When
PlaybookEngine::ancestry_dirtyis set (a cache refresh most recently failed and hasn't yet succeeded again — the accurate signal per the issue's own analysis),get_workflow_statenow records adegraded_reasonsentry naming the failure, so a caller can tell the graph-event candidates may be missing a rule registered on an ancestor type.Scope note (documented in code)
This covers the one class of staleness that's both unbounded in duration and cheaply/precisely detectable: a failed refresh that hasn't yet been retried. It does not cover the ordinary sub-millisecond propagation lag between a schema write committing and the play engine's async event loop refreshing the cache in response — that's bounded, inherent to the in-process pub/sub architecture, and shared by every other in-memory index built the same way (e.g. the
TriggerIndexitself), not the risk this diagnostic exists to flag. Doc comments onWorkflowState::degraded_reasonsandget_workflow_statespell this out explicitly.Direction 3 (making
lookup_rules's ancestor fan-out resolve live, matching the scheduled/cron path) remains explicitly out of scope — it's the live trigger-dispatch hot path shared withengine.rs/cel.rs, which cannot afford a DB read per event, same reasoning as #2828/#2864.Files touched
packages/core/src/playbook/engine.rs— newancestry_dirty()accessor.packages/core/src/services/node_service/mod.rs— new field/setter/getter mirroringplaybook_lifecycle.packages/daemon/src/services/assembly.rs— one new wiring line.packages/core/src/playbook/workflow_state.rs— the actual check + doc-comment updates + 2 new tests.Test plan
cargo check -p nodespace-core -p nodespace-daemon(compilesnodespace-agenttransitively — confirms the restricted lane is untouched)cargo test -p nodespace-core --lib playbook::workflow_state— 16/16 passed (2 new: flag-set surfaces the reason; flag-unset stays silent, the exact false-positive mode that killed the earlier-rejected approach)cargo test -p nodespace-core --lib playbook::engine— 18/18 passed (untouched behavior)cargo test -p nodespace-core --lib services::node_service— 162/162 passedcargo test -p nodespace-daemon --lib get_workflow_state— 2/2 passedbun run quality:fix— clean (frontend, scripts, desktop-app, skill package,cargo fmt,cargo clippy --all-targets -D warnings)test:all+cargo build --bin nodespaced+test:e2e+ Tauri-seam integration tests) — all greenCloses #2870.
🤖 Generated with Claude Code