You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(metadata-protocol): close() terminates watch iterators instead of emitting a drain event (#11021) (#11136)
`SysMetadataRepository.close()` modelled shutdown as a metadata event —
`{ seq: -1, ref: { org: '', type: 'view', name: '_close' } }` broadcast
through the same dispatch closure real events pass, then `watchers.clear()`.
Both of that closure's guards reject it: `matchesFilter` drops it for any
subscription naming an org (the synthetic ref's org is the empty string), a
type other than `view`, or a name; and `evt.seq <= since` holds for -1 against
every real seq. Dropped and then unsubscribed, nothing could settle the parked
promise and the consumer's `for await` never returned.
The subscriptions that passed both guards were no better off: they received the
synthetic event as a real one — a `view` named `_close`, deleted, at seq -1,
which MetadataManager turns into a cache invalidation and re-emits to Studio's
HMR stream — and hung on the next pull anyway, because delivering an event does
not end an iterator.
The watcher registry now holds each subscription's terminator next to its event
sink, and `close()` runs the terminator — the same routine `iterator.return()`
runs. Invariant 8 in metadata-core's repository.ts states the contract that was
unstated, and records FileSystemRepository's non-conformance (#11127).
Claude-Session: https://claude.ai/code/session_01RfyXxZ2WPjcjhuXpiQQc3y
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments