Public: anyone can read this; the crew can change it.

One signed-in account cannot hold more than its share of event streams #14982

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A signed-in caller's event streams now have caps of their own. Before this, they counted only toward the forge-wide allStreams (4096), so one account could hold the whole pool while everyone else got 429s. New caps (src/http/strangers.ts): holdStream takes the caller's account id, or undefined for a stranger.

Notes

shipped production is serving it deploy 5f527c6

opened this

A signed-in caller's event streams now have caps of their own. Before this, they counted only toward the forge-wide allStreams (4096), so one account could hold the whole pool while everyone else got 429s.

  • New caps (src/http/strangers.ts): holdStream takes the caller's account id, or undefined for a stranger. For a signed-in caller it also counts the stream against streamsPerAccount (64) and signedStreamsPerAddress (256). Both are named limits next to the stranger ones (streamsPerAddress, strangerStreams), and setStrangerLimits can change them. A refusal is the same plain 429 with retry-after the other doors use.
  • Counted apart from strangers: the per-address count for signed-in callers is kept separately from the stranger count at the same address. That way an office behind one address can still hold several people's tabs, and strangers there cannot use up the signed-in share.
  • How the account is found: src/http/caller.ts gains callerAccount(request), which src/http/sse.ts uses in place of the isSignedIn flag. The account comes from the caller noted after auth, so every token and browser of one account counts as one.
  • Replays: carryCaller makes the replayed request on the idempotency path in src/http/server.ts the same caller. Before, a replay carried the signed-in flag but not the account, so it lost the account behind it.
  • Choice of numbers: 64 and 256 are judgement calls, meant to be roomy for many tabs plus an agent watching runs. I did not add a rate limit on opening streams, because the issue asks only for a cap on streams held open.

Test: a new case in test/strangers.test.ts checks the account cap across two tokens and two addresses: the third stream is refused while another account still connects. It also checks the per-address cap across accounts, and that a stranger at a full address is counted separately. It fails on main (a 200 where it expects a 429) and passes here.

Checks run: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts named 2632 test files because server.ts changed, so I ran the suites that cover streams and standing instead (strangers, sse, standing*, system-stream, thought-stream): 58 pass, 0 fail. The forge's check runs the whole suite.

To try it: with one token, open more than 64 streams to /events (curl -N -H 'authorization: Bearer …'). The 65th answers 429 "too many open streams", and a token for another account still connects.

No page changed, so there is no review block. The keep_plan and estimate tools the issue mentions were not available in this run, so no plan or estimate was recorded.

🤖 Generated with Claude Code

Closes #14961

commented

A signed-in caller's event streams now have caps of their own. Before this, they counted only toward the forge-wide allStreams (4096), so one account could hold the whole pool while everyone else got 429s.

  • New caps (src/http/strangers.ts): holdStream takes the caller's account id, or undefined for a stranger. For a signed-in caller it also counts the stream against streamsPerAccount (64) and signedStreamsPerAddress (256). Both are named limits next to the stranger ones (streamsPerAddress, strangerStreams), and setStrangerLimits can change them. A refusal is the same plain 429 with retry-after the other doors use.
  • Counted apart from strangers: the per-address count for signed-in callers is kept separately from the stranger count at the same address. That way an office behind one address can still hold several people's tabs, and strangers there cannot use up the signed-in share.
  • How the account is found: src/http/caller.ts gains callerAccount(request), which src/http/sse.ts uses in place of the isSignedIn flag. The account comes from the caller noted after auth, so every token and browser of one account counts as one.
  • Replays: carryCaller makes the replayed request on the idempotency path in src/http/server.ts the same caller. Before, a replay carried the signed-in flag but not the account, so it lost the account behind it.
  • Choice of numbers: 64 and 256 are judgement calls, meant to be roomy for many tabs plus an agent watching runs. I did not add a rate limit on opening streams, because the issue asks only for a cap on streams held open.

Test: a new case in test/strangers.test.ts checks the account cap across two tokens and two addresses: the third stream is refused while another account still connects. It also checks the per-address cap across accounts, and that a stranger at a full address is counted separately. It fails on main (a 200 where it expects a 429) and passes here.

Checks run: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts named 2632 test files because server.ts changed, so I ran the suites that cover streams and standing instead (strangers, sse, standing*, system-stream, thought-stream): 58 pass, 0 fail. The forge's check runs the whole suite.

To try it: with one token, open more than 64 streams to /events (curl -N -H 'authorization: Bearer …'). The 65th answers 429 "too many open streams", and a token for another account still connects.

No page changed, so there is no review block. The keep_plan and estimate tools the issue mentions were not available in this run, so no plan or estimate was recorded.

🤖 Generated with Claude Code

commented

Event streams are now capped per signed-in account and per signed-in address, so one account can no longer take most of the forge's 4096-stream pool. Before this, a signed-in caller counted only toward that shared pool.

  • Per account: one account may hold 64 streams, across all its tokens and browsers.
  • Per address: signed-in callers from one address may hold 256 together. That stops one address from filling the pool by creating many accounts. This count is kept separate from the 8-per-address limit for visitors who are not signed in, so an office behind one address still works.
  • What a refused caller gets: a 429 "too many open streams".

holdStream in src/http/strangers.ts now takes the caller's account, read from callerAccount in src/http/caller.ts, in place of a yes/no "stranger" flag. That made isSignedIn in src/http/limits.ts unused, which failed the dead-code check on the last push, so it is removed. The signedIn set behind it still decides how much of a request body is read.

bun x tsc --noEmit and test/unused-exports.test.ts with test/strangers.test.ts pass; bun scripts/gate.ts --fix exits clean. It printed one note, which didn't fail it: the bearer helper in the new test looks like the make helper in test/verify-recovery.test.ts.

To try it: open more than 64 streams to /events with one token (curl -N -H 'authorization: Bearer …'). The 65th answers 429, and another account's token still connects.

🤖 Generated with Claude Code

Approved

Signed-in streams now count per account (64) and per signed-in address (256), apart from strangers' per-address count. The account comes from the caller noted after auth and the address from clientBucket, never from a client-written header. A refusal is the same plain 429 with retry-after. The replay path carries the caller, and the now-unused isSignedIn is removed. The new test covers two tokens of one account, another account still connecting, the per-address cap and strangers counted apart. Per the pull, it fails on main. No page changed and no feature was added, so the terminal and docs items do not apply.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs