fix(authority): fence controller lifecycle races - #92
Merged
trvon merged 2 commits intoSep 5, 2026
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
It changes several core lifecycle/concurrency paths (session teardown, wake buffering, and workflow fire cleanup) where subtle ordering/race regressions are hard to fully rule out without human sign-off.
Pull request overview
This PR hardens controller authority/lifecycle boundaries in pi-loop by fencing session-generation/store-identity races across backlog bootstrap, monitor/orchestration teardown, and post-fire cleanup, while also tightening workflow-vs-standalone-task separation and improving notification buffering correctness.
Changes:
- Adds generation/store/createdAt fencing to prevent stale async operations (e.g., backlog bootstrap and post-fire cleanup) from mutating or re-waking rebound/replaced controllers.
- Runs monitor shutdown and orchestration shutdown concurrently during session shutdown/switch to reduce teardown ordering hazards.
- Improves notification buffering semantics (queue sequencing + workflow wake invalidation when waiting on a monitor) and adjusts workflow inferred max-fires budgeting for
startImmediately.
File summaries
| File | Description |
|---|---|
| test/workflow-task-integration.test.ts | Adds RA-03 integration coverage for inferred fire budget when startImmediately is used. |
| test/store.test.ts | Adds RA-08 coverage ensuring workflows can’t be projected into standalone task behaviors. |
| test/session-runtime.test.ts | Updates teardown-order assertions and adds RA-06 coverage for concurrent monitor/orchestration shutdown behavior. |
| test/notification-runtime.test.ts | Adds RA-04/RA-07 coverage for buffered wake supersession and monitor-wait invalidation. |
| test/notification-coordinator.test.ts | Updates notification fixtures for the new queueSequence field. |
| test/index.test.ts | Adds RA-02/RA-05 race coverage and improves timer/mock cleanup between tests. |
| src/tools/workflow-tools.ts | Reserves additional inferred fire budget for startImmediately cadence activations. |
| src/store.ts | Rejects invalid workflow+task/orchestration combinations at normalization and creation time. |
| src/runtime/session-runtime.ts | Executes shutdownMonitors and shutdownOrchestrations in parallel on shutdown/switch. |
| src/runtime/notification-runtime.ts | Introduces queueSequence and prevents older same-key wakes from clobbering newer ones; invalidates buffered workflow wakes while waiting on a monitor. |
| src/notification-reducer.ts | Extends the reducer notification contract to include queueSequence. |
| src/index.ts | Adds store/generation/createdAt fencing for backlog bootstrap and post-fire cleanup; prevents workflow controllers from triggering autoTask behavior. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
trvon
force-pushed
the
fix/controller-lifecycle-authority
branch
from
September 5, 2026 02:19
ba4a17c to
c0551ed
Compare
trvon
force-pushed
the
fix/controller-lifecycle-authority
branch
from
September 5, 2026 02:51
c0551ed to
3d2a0fa
Compare
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
Validation
Stack
5 of 6. Base:
fix/notification-relevance.