Skip to content

feat(service): read events through the service, woken by its writes - #120

Merged
PiquelChips merged 1 commit into
refactor/parking-lotfrom
feat/server-events
Nov 25, 2026
Merged

PiquelChips merged 1 commit into
refactor/parking-lotfrom
feat/server-events

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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::events reads 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 watch now 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)

  • Adds OriginService::events(&self, _caller: &Caller, query: &EventsQuery) -> Result<Page, ServiceError>.
  • The method applies the query filters. It waits for matching events when the query has a cursor.
  • Without a cursor, the method starts at the current event-log end and returns only new events.
  • The default limit is 1024. The limit is capped at 1024.
  • The requested wait is capped at OriginService::MAX_WAIT, a Duration constant set to one minute.
  • The service holds a Wakeup. It calls notify after successful record writes, after landing attempts (including attempts that return an error), and after target creation.
  • The service documentation describes index refresh and event-wait behavior.

Event reader (apps/origin-src/src/events.rs, +60/-4)

  • Adds the Wakeup type. Wakeup::notify(&self) increments a write counter and wakes waiting readers.
  • Adds the private field wakeup: Option<&'a Wakeup> to Events<'a, P>.
  • Adds Events::waking_on(self, wakeup: &'a Wakeup) -> Self to attach a wakeup to a reader.
  • The constructor creates readers without a wakeup.
  • Events::wait reads 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.
  • Documentation states that writes from the same process can wake attached readers. Writes from other processes appear on the next poll.

Workspace watch (apps/origin-src/src/workspace/ops.rs, +22/-13)

  • Changes Workspace::watch from watch(&self, filter: &Filter, since: Option<u64>) to watch(&self, kinds: Vec<KindPattern>, subjects: Vec<String>, since: Option<u64>).
  • watch now calls OriginService::events as the owner. It passes the optional since cursor, a wait of OriginService::MAX_WAIT, and a page limit of 256.
  • For each page, watch prints the events and advances the query cursor to page.next.
  • Removes the local Events cursor initialization and the Duration::from_secs(60) wait.

CLI (apps/origin-src/src/cli.rs, +1/-8)

  • Removes the Filter import.
  • The Watch command passes kind and subject directly to workspace.watch. It still passes since.

Totals: 4 files, +136/-31 lines (matches the diff summary).

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f45c901e-a241-4fc3-b254-1abc000a33d8
Commits

Reviewing files that changed from the base of the PR and between 79844db and 51da609.

Files selected for processing: 4

  • apps/origin-src/src/cli.rs
  • apps/origin-src/src/events.rs
  • apps/origin-src/src/service.rs
  • apps/origin-src/src/workspace/ops.rs

No actionable comments were generated in the recent review.

Walkthrough

The PR adds process-local wakeups for event readers, exposes bounded event queries through OriginService, and routes workspace watch requests through the service.

Changes: Event long-polling and watch

Layer / File(s) Summary
Event reader wakeups
apps/origin-src/src/events.rs
Events can attach a Wakeup and wait for its write counter to change. Readers without a wakeup continue polling.
Service event queries and notifications
apps/origin-src/src/service.rs
OriginService adds event queries with capped page limits and wait durations. It notifies waiting readers after record writes, landing attempts, and successful target creation.
Workspace watch service integration
apps/origin-src/src/cli.rs, apps/origin-src/src/workspace/ops.rs
The CLI passes watch filters directly to Workspace. Workspace::watch requests owner-scoped event pages and advances its cursor after each page.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant WorkspaceWatch
  participant OriginService
  participant Events
  participant OpLog
  WorkspaceWatch->>OriginService: request event page
  OriginService->>Events: wait with cursor and filters
  Events->>OpLog: read entries after cursor
  OpLog-->>Events: return entries
  Events-->>OriginService: return event page
  OriginService-->>WorkspaceWatch: return event page
Loading

Possibly related issues

  • sourceorigin-dev/origin#68 — The PR adds cursor-based event reads and same-process wakeups, which are also described in this issue.
  • sourceorigin-dev/origin#23 — The PR changes the origin watch event polling path described in this issue, though it does not add the proposed file-system watcher.

Possibly related PRs

Merge Risk: Minimal · previous review 79844

This change adds a process-local wakeup so event long-polls answer promptly after the service writes, and routes origin watch through the service. No concrete merge-blocking defect was found. In an edge case, origin watch may now fail or create a node key when the key file is unreadable or missing, which is a minor behavior change.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the change reads events through the service and that those reads are woken by the service's writes. The changeset adds OriginService::events with cursor, filter, and wait handling, adds…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the change reads events through the service and that those reads are woken by the service's writes. The changeset adds OriginService::events with cursor, filter, and wait handling, adds a Wakeup notified after record writes, landings, and target creation, and moves origin watch onto the service. The title names the main change and its wakeup mechanism. It follows the conventional feat(scope): format and stays under a typical length limit.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit heard the event bell ring,
Then watched the pages hop and spring.
A counter stirred; the wait was through,
New records joined the waiting queue.
“Next page, please!” the rabbit cried,
And bounded on with cursor wide.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51f0f762-5808-491b-95a4-002e93a16687
Commits

Reviewing files that changed from the base of the PR and between 4717e73 and 79844db.

Files selected for processing: 4

  • apps/origin-src/src/cli.rs
  • apps/origin-src/src/events.rs
  • apps/origin-src/src/service.rs
  • apps/origin-src/src/workspace/ops.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@PiquelChips
PiquelChips added this pull request to stack #165 November 22, 2026 14:59
@PiquelChips
PiquelChips force-pushed the feat/server-events branch 4 times, most recently from 36d95ad to 1f7d6b3 Compare November 23, 2026 08:16
@PiquelChips
PiquelChips force-pushed the feat/server-events branch 5 times, most recently from 2114c23 to a6c09b3 Compare November 23, 2026 22:51
Base automatically changed from feat/server-records to main November 24, 2026 22:46
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.
@PiquelChips
PiquelChips removed this pull request from stack #165 November 24, 2026 22:57
@PiquelChips
PiquelChips changed the base branch from main to refactor/parking-lot November 24, 2026 22:57
@PiquelChips
PiquelChips added this pull request to stack #192 November 24, 2026 23:00
@PiquelChips
PiquelChips merged commit 8d52a38 into main Nov 25, 2026
6 checks passed
@PiquelChips
PiquelChips deleted the feat/server-events branch November 25, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant