Skip to content

[sagas] SSE event feed scans the keyspace every 100 ms per client and loses events #2637

Closed

Description

@rickylabs

Summary

The saga SSE event feed writes each event as a KV key, polls the whole prefix every 100 ms per connected client, and deletes the key once one client has sent it. Each client causes ten keyspace scans per second, and with more than one client only one of them receives a given event.

Evidence (main at b0eb079, same on v0.0.9)

  • plugins/sagas/services/src/routers/v1-handlers.ts:184-197: kv.watchPrefix(['saga', 'events'], { pollInterval: 100 }), then kv.delete(watchEvent.key) after the event is yielded.
  • plugins/sagas/services/src/routers/v1-handlers.ts:305-308: kv.set(['saga', 'events', crypto.randomUUID()], event). The random key gives no order.
  • On the Redis KV adapter, watchPrefix runs a SCAN + MGET sweep per interval (packages/kv/adapters/redis.adapter.ts).
  • The event id is a per-connection counter, so Last-Event-ID cannot resume a feed.

Expected behavior

Every connected client receives every event in publish order, a reconnecting client resumes from its last event id, and an idle feed does not scan the keyspace.

Acceptance

  • Two concurrent clients both receive every published event, proven by a test that fails on current main.
  • Events are delivered in publish order with stable ids, and a client reconnecting with Last-Event-ID receives what it missed within the retention bound.
  • An idle feed issues no periodic keyspace scan.
  • Retention of the event history is bounded and documented.

Design note: this feed is an append-only log. The fix must work on the stores NetScript supports today; it must not depend on Redis Streams, which the managed Garnet cache does not have yet.

Acceptance evidence: #2646 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions