fix(core): commit state before finalize publishes - #38983
Merged
Conversation
kitlangton
force-pushed
the
state-event-ordering
branch
from
July 27, 2026 14:18
9c48a52 to
715ea9b
Compare
kitlangton
force-pushed
the
state-event-ordering
branch
from
July 27, 2026 15:03
715ea9b to
196a03f
Compare
Contributor
Author
|
Unit checks fail with |
4 tasks
This was referenced Jul 27, 2026
6 tasks
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.
What
Stateupdate events now act as read barriers: a subscriber that observes a domain update event (command.updated,agent.updated,catalog.updated, ...) and immediately refetches is guaranteed to see the rebuilt state.Fixes #37422.
Before / After
Before:
State.commitranfinalize(where every domain publishes its update event) before assigning the rebuilt state:finalizepublishescommand.updated.command.list().state = nexthas not happened yet, so the subscriber reads the old commands and never refetches again.After: the rebuilt state is assigned first, then
finalizeruns. Any consumer reading on the event observes committed state.How
packages/core/src/state.ts—State.commitswapsstate = nextbefore invokingfinalize, and thefinalizedoc comment now states the read-barrier contract.packages/core/test/state.test.ts— new testcommits rebuilt state before finalize runs, written and confirmed red against the old ordering.All seven
finalizeconsumers were audited (agent,command,catalog,skill,websearch,integration,reference): six only publish their update event;referencerebuilds its derivedmaterializedmap and then publishes, so its event also still fires after both the swap and the rebuild. None rely on pre-commit ordering.Scope
First slice of the config source reload plan (
docs/design/config-source-reload.mdon theconfig-source-reloadbranch). Deliberately excluded, coming as separate PRs:config.changesand narrowing Config's rediscovery.Testing
bun typecheckinpackages/corereports only pre-existing sdk-drift diagnostics also present at the base commit; none referencestate.ts.