Repository navigation
feat(service): read events through the service, woken by its writes - #120
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
36d95ad to
1f7d6b3
Compare
2114c23 to
a6c09b3
Compare
a6c09b3 to
79844db
Compare
Plugins and agents react to events by long-polling for them. Reading the op log every 50 ms is fine for a command, but a server that just wrote a record knows there's something to read, and a waiting poll should hear of it at once. `OriginService::events` reads the events after a cursor that pass a filter, waiting up to a minute for some, or from the end of the stream without a cursor. Its writes wake the polls waiting in the same process through a `Wakeup`, rather than at their next read of the op log; writes from other processes still wait for that read. A failed landing wakes them too, since it may have written a conflict. `origin watch` now goes through the service, like the other commands the API offers.
79844db to
51da609
Compare
Plugins and agents react to events by long-polling for them. Reading the op log every 50 ms is fine for a command, but a server that just wrote knows there's something to read, and a waiting poll should hear of it at once.
OriginService::eventsreads the events after a cursor that pass a filter, waiting up to a minute for some, or only new events without a cursor. The service wakes the polls waiting in its process whenever it writes, a failed landing included, since it may have written a conflict. Writes from other processes are still seen at the next read of the op log.origin watchnow goes through the service.Benchmark (
long_poll_wakeup, added with the server benchmarks later in this stack): a long-poll answers about 0.7 ms after a put.Note
Written by Claude Opus 5.5 in Claude Code (via T3 Code)
Service layer (
apps/origin-src/src/service.rs, +53/-6)OriginService::events(&self, _caller: &Caller, query: &EventsQuery) -> Result<Page, ServiceError>.OriginService::MAX_WAIT, aDurationconstant set to one minute.Wakeup. It callsnotifyafter successful record writes, after landing attempts (including attempts that return an error), and after target creation.Event reader (
apps/origin-src/src/events.rs, +60/-4)Wakeuptype.Wakeup::notify(&self)increments a write counter and wakes waiting readers.wakeup: Option<&'a Wakeup>toEvents<'a, P>.Events::waking_on(self, wakeup: &'a Wakeup) -> Selfto attach a wakeup to a reader.Events::waitreads the write counter before it reads the op log. It then waits for the shorter of the poll interval and the remaining timeout. It waits on the wakeup when one is attached. Otherwise, it polls.Workspace watch (
apps/origin-src/src/workspace/ops.rs, +22/-13)Workspace::watchfromwatch(&self, filter: &Filter, since: Option<u64>)towatch(&self, kinds: Vec<KindPattern>, subjects: Vec<String>, since: Option<u64>).watchnow callsOriginService::eventsas the owner. It passes the optionalsincecursor, a wait ofOriginService::MAX_WAIT, and a page limit of 256.watchprints the events and advances the query cursor topage.next.Eventscursor initialization and theDuration::from_secs(60)wait.CLI (
apps/origin-src/src/cli.rs, +1/-8)Filterimport.Watchcommand passeskindandsubjectdirectly toworkspace.watch. It still passessince.Totals: 4 files, +136/-31 lines (matches the diff summary).