Skip to content

fix(core): publish domain updates after committed state is readable - #37987

Closed
IbrahimKhan12 wants to merge 1 commit into
anomalyco:devfrom
IbrahimKhan12:catalog-event-order
Closed

IbrahimKhan12 wants to merge 1 commit into
anomalyco:devfrom
IbrahimKhan12:catalog-event-order

Conversation

@IbrahimKhan12

@IbrahimKhan12 IbrahimKhan12 commented Jul 20, 2026 •

Copy link
Copy Markdown

Issue for this PR

Fixes #37422 on dev. #38983 fixes the same issue on v2.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

State domains could publish update events from finalize before the rebuilt state replaced the readable snapshot. A subscriber reacting immediately to a catalog, integration, or reference event could therefore refetch the previous value with no later event to invalidate it.

This change adds a post-commit notify hook that runs only after state = next. Catalog, integration, and reference event publication moves to that hook, while asynchronous finalization still completes before the new snapshot becomes visible. An observed update event is therefore a safe boundary for refetching committed state.

How did you verify your code works?

  • State, catalog, integration, and reference tests: 30 pass, including a regression that refetches state from the update-event handler and observes the committed snapshot.
  • bun typecheck from packages/core: passes.

Screenshots / recordings

N/A, this changes state/event ordering only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

State.commit ran options.finalize before assigning state = next, and the
catalog, integration, and reference finalizers publish their Event.Updated
inside finalize. A client that reacts to the event and immediately refetches
could therefore read the previous snapshot with no later invalidation, so a
catalog/integration change was only observed once an unrelated later event
triggered another refresh.

Add a post-commit notify hook that runs after state = next and move each
Event.Updated publish from finalize into notify. Finalize keeps the work that
must complete before the state becomes visible (catalog provider removal,
reference materialization); notify announces the rebuilt, readable snapshot.
Because the event is emitted after the assignment, every public update event
is a safe invalidation boundary regardless of fiber scheduling.

Refs anomalyco#37422
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a related PR:

PR #37480 - fix(core): make state visible before finalize

This is an alternative approach to the same issue (#37422). The current PR #37987 explicitly chooses not to use that approach—the description notes that #37480 assigns the snapshot before running finalize, which would expose partially-finalized state (specifically, denied providers would transiently become readable during policy evaluation). Instead, PR #37987 keeps finalize before visibility and only defers event publication via a new notify hook.

These are related but distinct solutions to the same problem.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catalog update events can precede readable state

1 participant