Repository navigation
pubsub: the embedded bus states its store, and streams reserve a share of it - #87
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical active issues remain: declared budgets can be silently skipped when capacity is zero, and replica-unaware share calculations can overcommit finite account limits and reject declarations.
2 open issues
What changed in this PR
This pull request makes embedded PubSub storage limits visible to JetStream and scales the EVENT and USAGE streams according to shared storage reservations.
Changes:
- Defines shared stream ceilings, storage shares, and sizing helpers.
- Applies account-aware limits to EVENT and USAGE stream declarations.
- Adds embedded-server budget parsing, account limit configuration, documentation, and regression tests.
| File | Description |
|---|---|
| sdk/bus/budget.go | Defines shared stream storage ceilings, shares, and reservation calculations. |
| sdk/bus/budget_test.go | Tests reservation arithmetic and aggregate storage fit. |
| internal/driver/ledger/bus.go | Sizes the USAGE stream from the reported account storage limit. |
| apps/pubsub/pubsub.go | Applies the embedded server's storage budget before exposing the bus. |
| apps/pubsub/doc.go | Documents the CLOUD_PUBSUB_MAX_STORE setting and constrained-store behavior. |
| apps/pubsub/budget.go | Parses storage budgets and configures embedded JetStream account limits. |
| apps/pubsub/budget_test.go | Tests budget calculation, restart stability, invalid values, and stream behavior. |
| apps/event/plane_test.go | Updates event stream limit assertions to use shared reservation constants. |
| apps/event/bus.go | Sizes the EVENT stream using the shared reservation policy and account limit. |
| apps/event/bus_test.go | Tests EVENT stream behavior on a constrained account store. |
Review effort: Lite
| if n == 0 { | ||
| return 0, nil | ||
| } |
| } | ||
| // In two parts, so a store of any size divides exactly and never overflows. | ||
| p := int64(r.Share) | ||
| return min(r.Ceiling, store/100*p+store%100*p/100) |
|
Added a fourth commit ( The volume still held USAGE at its old 1 GiB under an account limit of 1.36 GiB. EVENT was refused at its share, and where it existed it could not be resized either, because a resize is weighed against what the other streams hold. Its consumers went back to retrying every two seconds. A stream now asks for its share or for what the others leave, whichever is smaller ( Verified on that same runtime after the change: 0 refused declarations, EVENT at 1 GiB, USAGE resized to 204 MiB on a 2 GiB account. 🤖 Generated with Claude Code |
A stream that states MaxBytes reserves that many bytes when it is declared, and JetStream refuses a declaration that does not fit what is left (10047). The ceilings were written where each stream is declared, 8 GiB for EVENT and 1 GiB for USAGE, with nothing that made them fit one store together. Reservation is a stream's production ceiling and its share of a store too small to hold that; Events and Usage are the rows. Need and Reserved are what the embedded server reads to know when a store is too small for the ceilings. The package stays free of any bus client. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
EVENT read the account's file limit and halved it, which was right, and USAGE read nothing. Both now hold their ceiling or their row's share of the limit the bus reports (bus.Events, bus.Usage). On an account that reports no limit the ceiling stands, as before. That is the case the next commit closes for the embedded server, which never reported one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The embedded server's file store is the free space under its store directory when it boots, and its account stated no limit, so AccountInfo answered -1 whatever the server could hold. A stream that sizes itself from that answer asked for its production ceiling everywhere. Measured on a local runtime with 3.92 GB free: EVENT asked for 8 GiB, was refused with 10047, and its five consumers retried every two seconds, 38,086 refused requests in two hours. The server now states the limit in two cases: the deployment declares a budget (CLOUD_PUBSUB_MAX_STORE, bytes), or it declares none and the store cannot hold the ceilings together. A node with room for them and no budget is left exactly as it was, production included. The server counts an account's limit beside the reservations made under it, so the limit is bounded to what still fits with its own reservations; that is also what keeps it the same across a restart that restores last boot's streams. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t has The shares fit together only when every stream holds its share. A store carried over from a build with other sizes does not: measured on a local runtime whose volume kept USAGE at its old 1 GiB under an account limit of 1.36 GiB, EVENT was refused at its share (10047), and where it existed it could not be resized either, since a resize is weighed against what the others hold. Its consumers went back to retrying every two seconds. A stream now asks for its share or for what the others leave, whichever is smaller (Reservation.Within), and takes its share again once they have taken theirs. When no size is taken at all, a stream that already exists is kept as it is: a refused resize is no reason to stop using it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tream shares by replicas Address PR hanzoai#87 review findings: - Reject a declared CLOUD_PUBSUB_MAX_STORE budget when limit() resolves to zero (exhausted reservations or zero server capacity) instead of silently skipping UpdateJetStreamLimits and leaving MaxStore unlimited. - Make Reservation.Of, Reservation.Within, Need, and embedded limit calculations replica-aware so un-tiered account MaxStore limits (charged by JetStream as MaxBytes * Replicas) fit cleanly at both replicas=1 and replicas=3 without triggering 10047. Co-Authored-By: Denis Issoupov <denis@averlon.io>
…and quiet missing-token drain - Check Forge repo Mirror / Actions metadata in gateOpen before writing the fork error status, so fork PRs against mirror or non-Actions repos are never stamped with a bogus hanzo/ci error while still never fetching or proposing fork branches on Forge. - Log once at Info instead of spamming Warn on every runner queue tick when FORGE_TRACKER_TOKEN@prod is unconfigured in local/standalone KMS.
cb7b3e1 to
e95c699
Compare
|
Rebased onto latest
|

What this fixes
On a node with a small store, every consumer of the event stream is refused by JetStream with
err_code=10047(insufficient storage resources available) and retries every two seconds. Measured on a local runtime with 3.92 GB free: 38,086 refused requests in two hours, from webhook, marketing, destination and triage.Cause
The embedded server's file store is the free space under its store directory when it boots, and its account states no limit.
AccountInfotherefore answersmax_storage: -1whatever the server can hold.apps/eventalready clamped the EVENT stream to half the account's limit, but with-1the clamp never engaged, so it asked for its 8 GiB production ceiling everywhere. USAGE (1 GiB) read nothing at all.Change
sdk/bus/budget.go: one table for the streams that reserve storage. AReservationis a production ceiling and a share of a store too small to hold it: EVENT 8 GiB / 50%, USAGE 1 GiB / 10%. The package still links no bus client.apps/event,internal/driver/ledger: both streams hold their ceiling or their share of the limit the bus reports.apps/pubsub/budget.go: the embedded server states its store on the account in two cases: the deployment declares a budget (CLOUD_PUBSUB_MAX_STORE, bytes), or it declares none and the store cannot hold the ceilings together.What does not change
A node whose store holds the ceilings and declares no budget is left exactly as it was: the account stays unlimited and the streams keep 8 GiB and 1 GiB. That is production.
One thing worth a reviewer's eye
The server counts an account's limit beside the reservations already made under it (
sufficientResources), and refuses a limit when the two exceed its store. So the limit is bounded to the part of the store whose own reservations still fit beside it (store × 100 / (100 + reserved share)). That bound is also what keeps the limit the same across a restart that restores last boot's streams; without it the streams would shrink on every boot.TestTheLimitHoldsAcrossARestartpins it.Verified
go vetand tests pass forsdk/bus,apps/pubsub,apps/event,internal/driver/ledger.TestADeclaredBudgetIsWhatTheAccountReports: on a 256 MiB budget the account reports 256 MiB, every reserving stream fits at its share, a stream with no ceiling is taken, and the 8 GiB ceiling is refused with 10047.Not verified: a production-sized node. The no-change path there is covered by unit tests of
limit()only.The branch is cut from
c7268d3f; the files it touches are unchanged between that commit andmain.🤖 Generated with Claude Code