Skip to content

Resolve waitForFirstResult on the initial query result, not the seed emission - #2541

Merged
einari merged 2 commits into
mainfrom
fix/observable-query-seed-emission
Aug 13, 2026
Merged

Resolve waitForFirstResult on the initial query result, not the seed emission#2541
einari merged 2 commits into
mainfrom
fix/observable-query-seed-emission

Conversation

@einari

@einari einari commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

A one-shot HTTP read of a collection-backed observable query with waitForFirstResult=true returned the observable's empty seed value with isReady: true, deterministically and regardless of the timeout. Because the payload was a well-formed empty collection and the result reported itself as ready, a caller had no way to tell it apart from a genuinely empty read model. Anything that cannot hold a stream open was affected: cURL and scripted reads, readiness probes, integration specs, and server-to-server fetches.

Fixed

einari added 2 commits August 13, 2026 06:29
Observe() built its subject before running the initial query, so the
collection variants handed every subscriber a BehaviorSubject seeded with
an empty collection. A one-shot read with waitForFirstResult=true resolved
on that seed and returned an empty payload with isReady: true - a confident,
well-formed answer that was indistinguishable from a genuinely empty read
model, and never resolved by waiting longer.

Back the subject with a single-value ReplaySubject instead: nothing is
emitted until the initial query completes, and the latest emission is still
replayed so a subscriber arriving after that query sees its result. This
also closes the same gap on the single-document and joined variants, whose
plain Subject silently dropped the initial emission for a late subscriber.
Cover the three guarantees the seed-emission fix rests on: nothing is
emitted before the initial query completes, the first emission carries that
query's documents, and a late subscriber gets them replayed. Grant
Cratis.Arc.MongoDB.Specs access to Arc.Core internals so the observe specs
can configure Internals.ServiceProvider, matching how the EF Core observe
specs are wired.
@einari einari added the patch label Aug 13, 2026
public class and_the_initial_query_has_not_completed : given.an_observed_collection
{
ISubject<IEnumerable<ObservedDocument>> _subject;
List<IEnumerable<ObservedDocument>> _emissions = [];
@einari
einari merged commit ac51997 into main Aug 13, 2026
56 of 57 checks passed
@einari
einari deleted the fix/observable-query-seed-emission branch August 13, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant