Skip to content

feat(events)!: one shared event feed per client (2.0.0) - #902

Merged
Blind-Striker merged 6 commits into
masterfrom
feat/851-shared-event-feed
Nov 15, 2026
Merged

Blind-Striker merged 6 commits into
masterfrom
feat/851-shared-event-feed

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

One shared event feed per root client replaces the per-call reconnecting event streams. It follows upstream's first-party shared-events.ts at the pin (v2.3.0):

  • every SubscribeAsync enumeration is an independent subscription over one shared background source;
  • event types are selected locally;
  • each subscriber's queue is bounded, and overflowing it raises a typed exception;
  • connection state is coalesced, and consumers can watch it;
  • ordinary attempt failures retry forever.

This is the 2.0.0 change: it breaks behaviour, and the version moves to 2.0.0 on the same opencode 2.3.0 pin.

Closes #851. The one remaining provenance step is #901 (see "Deferred").

Public surface (the names the maintainer approved)

  • EventsClient.GetConnectionState() and EventsClient.WatchConnectionAsync(CancellationToken), both virtual.
  • EventConnectionState (sealed), with Status, Attempt and Error, and a public constructor (EventConnectionStatus status, int attempt, Exception? error).
  • EventConnectionStatus: Idle, Connecting, Connected, Reconnecting.
  • OpenCodeEventSubscriberOverflowException (sealed, derives from OpenCodeException), with Capacity.
    • It has the three standard public constructors that every public SDK exception has.
    • Capacity always reports the SDK's single 4,096 bound.

PublicApi.verified.txt changes by exactly these entries.

Design and canon

  • GLOSSARY records the approved names: Event feed, Event subscription, Subscriber overflow and Connection state.

  • ADR 0041 records one shared event feed per client. Its divergences from upstream each have a reason and a reversal trigger:

    • retry runs inside the one source;
    • cancellation throws instead of ending with done;
    • Idle is an explicit state;
    • Error is an exception, not a message;
    • overflow has its own exception type;
    • Solid's application facilities are left out: history, resync, page lifecycle, re-resolution, batching and onActivity.
  • client-runtime.md gains the internal Pipeline.RegisterOwned hook. The Events door registers its feed there, so the feed is disposed before the transport when the root client is disposed. Pipeline stays free of Events types.

  • ADR-0007 narrows its stream sentences to the other streams; the event bus follows ADR 0041.

  • Guides (streaming, errors and responses, getting started), README, GLOSSARY and the HQ playground README now describe the status quo.

  • CHANGELOG: the 2.0.0 entries are under 💥 Breaking, ✨ Added and 🔧 Changes.

Upstream parity details worth a look

  • Every server.connected marker is cached, and a late subscriber gets the latest one, as shared-events.ts:52 does.
  • A raw stream refuses an operation whose traits say it reconnects. The other generated streaming operations are unchanged.
  • A stored fault is captured once and thrown from that capture on every pull, so its stack does not grow.

The HQ playground

The board and the conversation recover from overflow: a new admission, a refresh at the marker, then the idempotent turn ends and the final-text replacement.

One limitation is stated in the code and in the streaming guide's recovery recipe. A text delta buffered across a refresh can repeat text until the part's SessionTextEnded replaces it, because the snapshot carries no delta cursor. Upstream's events give no identity that could decide the overlap (session-event.ts:419-439, publish-llm-event.ts:177-201).

Clone baseline

tools/jscpd/tests.baseline.json loses six fingerprints that this change's own test rewrite made stale. No fingerprint was added. A shrinking baseline needs no reason.

Deferred (#901)

The receipt route for adding shared-events.ts to the source watch belongs to the generator's provenance tooling. It is tracked as #901, and these files are untouched here:

  • spec/source-watch.json;
  • spec/receipt.json;
  • spec/SNAPSHOT.md.

Reviews and their outcome

The change was implemented by one agent and reviewed by four independent readers:

  • lifetime and concurrency;
  • the whole diff;
  • upstream parity and test value;
  • a re-check of the fix-up commits.

Every finding was fixed, except these:

  • Declined: retire-path context capture. The context captured while a retired source's cancel runs is short-lived, and is not the source-lifetime leak that the start path guards against.
  • Declined: the runner ledger. The runner ledger that observes each source's cancel task is a deliberate design rule. It stays.
  • Recorded as equivalent: the cancel-callback drain. Deleting the subscription's cancel-callback drain cannot be observed. EndLocked already drains the queue on a live cancellation (EventSubscription.cs:157), and a fault-ended subscription keeps its unread prefix until the next pull or its disposal, as upstream does. The live-cancellation row stays as a regression test.

Tests

  • New classes: EventSelectionTests, EventSourceRunnerTests, EventSourceTests, EventStateWatcherTests, EventSubscriptionTests, SharedEventFeedTests, PipelineOwnedResourceTests, plus the scripted attempt source and the scenario support.
  • Existing tests whose expectations the approved behaviour changes were migrated, each with its reason:
    • the reconnect spine now asserts the raw-stream refusal;
    • one-minute give-up errors become connection-state oracles;
    • the idle-window propagation moved to its new owner.
  • Mutants were killed at their oracles on net10.0, net11.0 and net472, across the feed, subscription, watcher, source, runner and HQ.

Verification

  • The local check on the final head c0080e3e (master b587e7e3), on Linux, net10.0 and net11.0, SDK 11.0.100, Bun 1.4.4 at the pin: every step passed.
    • Slopwatch 0 issues, Release build 0 warnings, both format passes, verify-clones 0 new.
    • --help, and generate --verify: current.
    • OpenCode.Sdk.Tools.Tests except NativeAot: 2,823.
    • OpenCode.Sdk.Tests: 4,366 on each target framework.
    • The ServiceElection pass: 9 on each.
    • Extensions: 21 on each. HQ: 92.
    • Total 11,707 passed, 0 failed.
  • The full Windows local check on 9d405e14 (master 422c45ad), before the last rebase: GATE PASS.
    • Static steps, --help and generate --verify.
    • Tests:
      • OpenCode.Sdk.Tests 4,365 / 4,365 / 4,357 on net10.0 / net11.0 / net472;
      • the service-election pass 9 on each;
      • Tools 2,823;
      • Extensions 21 / 21 / 20;
      • HQ 92.
    • The NativeAot pass is out of scope.
  • The last rebase onto b587e7e3 (fix(rpc): a plugin call waits until the plugin answers #899) was clean. It overlaps this change only in CHANGELOG.md and client-runtime.md, which is why the final head ran its own local check.
  • CI on all three operating systems: this PR's run. It covers net472 on the final head.

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.

Events: the event door follows upstream's shared feed, with a connection status and endless retry

1 participant