Skip to content

feat(mesh): cap concurrent RPCs per peer on the teapot - #115

Merged
chrnx-dev merged 1 commit into
developfrom
feat/mesh-max-inflight-per-peer
Nov 30, 2026
Merged

chrnx-dev merged 1 commit into
developfrom
feat/mesh-max-inflight-per-peer

Conversation

@chrnx-dev

Copy link
Copy Markdown
Contributor

Closes #98. Stacked on #114 (#112 ← #113 ← #114 ← this); GitHub retargets as each merges.

Behaviour

  • MeshConfig.maxInflightPerPeer (teapot side, default 256): RPCs one connected teacup may have running at once.
  • Over the cap the call is refused before any work starts: rpc-res error with status 503, plus mesh:rpc:error (status: 503) on the teapot.
  • The teacup maps a teapot 503 to retry-after: 1 for its client. No wire change: the existing error frame already carries the status.
  • The counter is per connection, which is per peer until identity lands (M8, mesh: per-teacup identity and secret rotation #101). It goes back down as calls finish, so it limits concurrency, not total calls.
  • A value that is not a positive integer fails the teapot's boot.
  • Cancelling timed-out work is still mesh: cancel frame for timed-out and abandoned RPCs #99 (cancel frame); this only bounds how much can pile up.

Decision to confirm: the default is 256, not unlimited, so the fix applies without any config. Mesh is experimental, so changing the default costs nothing; say if you want another number.

API

MeshConfig.maxInflightPerPeer?: number (api/index.api.md regenerated). MeshConfig is within D19.

Tests

test/mesh/max-inflight.test.ts: cap 2 with a 200ms step and 3 concurrent requests gives 200, 200 and 503 with retry-after: 1, one teapot event, then 200 again after they finish. An invalid cap is rejected. Node only: the logic is the shared teapot frame loop, and the Deno/Bun suites still pass (71/61).

Benchmark

Same teacup→teapot RPC bench as #114 (7 × 3000 sequential requests, Node): median 39.1–41.0 µs/req before, 38.4–38.8 after, within noise. Only the mesh RPC path was measured.

Verified locally

lint (0 errors), format, complexity, typecheck, coverage, build, api:check, test:deno, test:bun, test:edge.

A teacup that times out an RPC never cancels it on the teapot, so one peer could
pile up unbounded work behind a slow step. MeshConfig.maxInflightPerPeer
(default 256) caps the RPCs one connection may have running; over the cap the
call is refused before any work starts with a 503 rpc-res and a mesh:rpc:error
event. The teacup turns a teapot 503 into retry-after: 1 for its client.
Counted per connection until per-teacup identity (M8).

Closes #98

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
@chrnx-dev
chrnx-dev changed the base branch from feat/mesh-event-peer-latency to develop November 30, 2026 17:54
@chrnx-dev chrnx-dev closed this Nov 30, 2026
@chrnx-dev chrnx-dev reopened this Nov 30, 2026
@chrnx-dev
chrnx-dev merged commit 20f5094 into develop Nov 30, 2026
5 checks passed
@chrnx-dev
chrnx-dev deleted the feat/mesh-max-inflight-per-peer branch November 30, 2026 17:56
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.

mesh: MeshConfig.maxInflightPerPeer on the teapot

1 participant