Skip to content

redisstore: isolated bounded follow pool + store-owned follower lifecycle #876

Closed

Description

@samuv

Parent

Follow-up from #821 (M2 — "Cursor storage seam"), deferred out of #868 / #869.

Context

#869 migrated the Redis event log from a LIST to a Stream so XREAD BLOCK can serve
cross-process follow. Review on that PR raised that the connection-capacity mitigation we
shipped is the weaker half of the fix, and the reasoning in
ADR 0250 for deferring the
stronger one ("sizing guidance is enough, and a second pool would need its own inventory
row to buy a bound the operator can already set") does not hold up:

  • bounded 1s XREAD BLOCK slices cap a watcher's hold time, not the contention. N
    watchers still compete with Save/Append for the same pool.
  • raising the shared pool only moves the threshold, and redisstore exposes no pool
    controls anyway, so "the operator can already set it" is not true today.

That makes watcher load able to starve the write path that keeps runs alive — which matters
specifically for mecak8s multi-replica, the deployment that makes cross-process follow a
requirement in the first place.

Already shipped (not part of this issue)

Recorded so this issue does not re-do them:

  • bounded XREAD BLOCK slices with a ctx re-check between them.
  • per-cycle lease acquire/release, so a follower parked for hours can no longer pin a
    retired credential generation open, and Store.Close no longer waits out its full grace
    with a client held (TestCloseDoesNotWaitOnAParkedFollower).
  • the lease released before records are yielded, so a slow transport consumer holds no
    pooled connection.
  • an internal COUNT cap, so ReadOptions.Limit == 0 no longer means an unbounded fetch.

Scope

Change the resource boundary from "shared pool plus operator sizing" to "isolated bounded
follow capacity".

  • A store-owned, bounded follow client/pool per credential generation, separate from the
    client used for durability and metadata operations. Roughly one socket per actively
    blocked watcher
    , not a redis.Client each.
  • A configurable, fail-fast per-process watcher admission limit. On exhaustion return a
    resumable resource-exhausted error immediately rather than waiting out a pool timeout —
    a watcher that cannot be admitted should be told so it can retry with its cursor, not
    parked.
  • Store-lifetime cancellation of followers, so Store.Close can cancel in-flight
    blocking reads, join with a bound, then force-close. Force-closing the isolated follow
    pool is safe precisely because writes use a different client. This is the half of
    the lifecycle concern that feat(redisstore,grpcdriver): migrate the Redis event log LIST -> Stream #869 did not address: the store still does not own its
    followers, and a follower's own context remains the only prompt way to stop one.
  • Expose the follow-pool sizing/admission knobs, and document them in docs/usage.md
    plus the mecak8s deployment page.
  • Per AGENTS.md and ADR 0027: the follow
    pool and the admission limiter are resources whose lifetime outlives one call, so each
    needs a List 1 row (owner / scope / cleanup / re-attach). Neither holds session
    state a restart would lose, so no List 2 row is expected — state that explicitly
    rather than by omission.

Explicitly out of scope

Recorded because they will otherwise be re-litigated:

  • Consumer groups are not the answer. Every watcher needs the full event stream, which
    is the one thing a consumer group is designed not to give.
  • Pub/Sub must never carry authoritative events. It could serve as a lossy wake-up hint
    followed by draining the durable Stream, but the Stream stays the source of truth.
  • Later-scale shapes, for whenever this is not enough: collapse multiple local watchers
    behind per-session hubs, then shard sessions across multi-stream XREAD.

Verify

  • A test that saturates the admission limit and asserts a resumable typed error rather
    than a pool-timeout stall.
  • A test that concurrent watchers at the admission limit do not delay Append/Save — the
    starvation property, asserted directly rather than inferred from pool sizing.
  • A test that Store.Close cancels and joins in-flight followers within its grace, with no
    outstanding-operations diagnostic.
  • Resource-inventory rows present (the docs/lint citation gate covers the citations; the
    per-phase re-audit covers completeness).

References

Activity

  1. added
    enhancement
    on Aug 31, 2026
  2. samuv commented on Sep 11, 2026

    @samuv
    ContributorAuthor

    Removed from the completed SDK implementation parent. This remains an
    independent Redis storage and follower-lifecycle improvement and does not block
    the v0.1.0 SDK release in #1394.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions