Repository navigation
Add GraphMutationObserver to store-graph - #6096
Open
William Wong (compulim) with Copilot wants to merge 2 commits into
Open
William Wong (compulim) with Copilot wants to merge 2 commits into
William Wong (compulim) with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
William Wong (compulim)
marked this pull request as ready for review
December 2, 2026 11:51
William Wong (compulim)
requested review from
Eugene (OEvgeny),
Chris Whitten (cwhitten) and
Thomas Durnford (tdurnford)
as code owners
December 2, 2026 11:51
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An observer registered from a subscribe() listener can incorrectly receive a notification for a commit that preceded its registration, violating the promised skip rule.
1 open issue
What changed in this PR
Adds synchronous, identifier-filtered graph observation to store-graph, modeled after MutationObserver.
Changes:
- Introduces validated observer registration, filtering, and disconnection.
- Indexes observations by identifier and shares listener error handling.
- Adds behavioral tests and an observer-scaling benchmark.
| File | Description |
|---|---|
packages/store-graph/src/private/ObservationIndex.ts |
Indexes and dispatches matching observations. |
packages/store-graph/src/private/callListener.ts |
Shares callback error isolation. |
packages/store-graph/src/index.ts |
Exports the observer and its types. |
packages/store-graph/src/GraphMutationObserver.ts |
Implements observer lifecycle and validation. |
packages/store-graph/src/GraphMutationObserver.test.ts |
Tests filtering, lifecycle, and notification behavior. |
packages/store-graph/src/Graph.ts |
Integrates observer dispatch after subscription listeners. |
packages/store-graph/src/benchmark.ts |
Measures updates with per-node observers. |
Review effort: Balanced
| callListener(listener, affectedNodeIds); | ||
| } | ||
|
|
||
| this.#observationIndex.notify(affectedNodeIds); |
This branch has not been deployed
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.

Adds a
GraphMutationObservertostore-graph, modelled after the HTMLMutationObserver. It observes graph changes synchronously and can filter them by a list of@idor alternateidentifiervalues.takeRecords()is not included.Graph(Graph.ts)#observersset. Astatic {}block sets the module-levelobserveGraph(graph, observer) => unobserve, so the observer can reach it without a public API. It is exported fromGraph.tsonly, not fromindex.ts.#notifyAll()callssubscribe()listeners first, then observers, all in the same synchronous job.has()before each call.callListener()helper, used by both listeners and observers.GraphMutationObserver(GraphMutationObserver.ts)identifierListis intersected with the graph's affected-ID set, which already includes alternate identifiers from before and after the change. So@idandidentifiermatching both work, including when an identifier is added or removed. If nothing in the list was affected, the callback is not called.MutationObserver:observe()again on the same graph replaces its options.identifierListis copied whenobserve()is called.TypeError.observe()uses valibot to check thatgraphis aGraphand thatidentifierListis aSetof valid identifiers.FrozenSet).index.tstogether with theGraphMutationCallbackandGraphMutationObserverInittypes.Review focus
identifierListis not set, the callback gets the same set assubscribe()listeners. That set includes alternate identifiers, e.g.['_:m-1', 'urn:x-message:1'].identifierListmust be valid identifiers, so arbitrary strings are rejected rather than silently never matching.