You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Among the history read ops, history.list has a per-connection cooldown (listCoolingDown, apps/hocuspocus.server/src/hocuspocus.server.ts:119). history.watch has a count cap (watchOverBudget, :128-141). The gate checks both at :314-317. history.revert carries its own separate cooldown (revertCooldown, :111 and :171).
history.watch has a count cap, but no byte cap. Each call reads one row and base64-encodes the whole document (apps/hocuspocus.server/src/lib/history-stateless.ts:181-193, encoder at apps/hocuspocus.server/src/lib/history-stateless.ts:92).
That encode is synchronous work on the shared process event loop. The Throttle extension only covers onConnect, so no per-frame cap stands behind it (apps/hocuspocus.server/src/hocuspocus.server.ts:110). A client that loops over versions meets a count cap, but no byte cap.
What to do
Add a cost cap to the watch arm. Shape it as a bytes-per-connection budget, not as a cooldown.
The count cap at apps/hocuspocus.server/src/hocuspocus.server.ts:126-141 already refuses a tight loop, and its comment says the client now stops on a refusal. Add the byte budget beside that cap. Do not add a time cooldown.
Acceptance
A client that requests every version in a tight loop is refused once its budget is spent.
A single normal watch still returns the snapshot.
Notes
The cost of one watch encode is not measured. Size the budget against a real document before you pick a number.
The count cap from 2acb4613d now exists, and the Problem section names it. The count cap (WATCH_MAX = 8 per WATCH_WINDOW_MS = 10_000) does not bound the bytes per window on a large document. Two changes cap the cost of history.watch.
Add a byte budget per connection per window, beside the existing watchTimes map, with the same rate-limited refusal. Set it to about 20 MB, just below three frames of the largest stored head. The budget is provisional; Find out whether the ws package on Bun repeats large frames on amd64 #602 may change it.
Drop the "same-version skip" idea. The client keeps no snapshot cache, so a skipped reply would leave it with no data.
Acceptance items.
Move the budget check and watchOverBudget into a pure module under apps/hocuspocus.server/src/lib/, so bun test can reach it. hocuspocus.server.ts imports lib/queue.ts, which opens Redis at import, so no test can import that file.
A bun test case: a connection that passes the byte budget inside the window gets rate-limited, while its count stays under WATCH_MAX. It runs on every pull request.
Remove the budget locally, and see the test fail. Restore it.
Built and committed on local main. Awaits the maintainer's final push.
Remaining gate: the backend deploy. Measured after #198: the watch read now takes about 2.2 to 3.3 ms on the large test document, down from about 120 to 160 ms.
Shipped in d40b265b7 (changelog in 95c1b0acf). Each connection now has a 20 MiB byte budget per 10 s window, beside the count cap. A watch past the budget gets the same rate-limited refusal. After #198, the watch read blocks the loop for about 2.2 to 3.3 ms, down from about 120 to 160 ms.
Activity
HMarzban commentedon Oct 15, 2026
Related issues
history.watchfor it. The cap here must allow that new load.Cross-link review, 2026-10-15. Generated by Claude Code
HMarzban commentedon Oct 24, 2026
Fix, 2026-10-24
The count cap from
2acb4613dnow exists, and the Problem section names it. The count cap (WATCH_MAX = 8perWATCH_WINDOW_MS = 10_000) does not bound the bytes per window on a large document. Two changes cap the cost ofhistory.watch.watchTimesmap, with the samerate-limitedrefusal. Set it to about 20 MB, just below three frames of the largest stored head. The budget is provisional; Find out whether the ws package on Bun repeats large frames on amd64 #602 may change it.Drop the "same-version skip" idea. The client keeps no snapshot cache, so a skipped reply would leave it with no data.
Acceptance items.
watchOverBudgetinto a pure module underapps/hocuspocus.server/src/lib/, sobun testcan reach it.hocuspocus.server.tsimportslib/queue.ts, which opens Redis at import, so no test can import that file.bun testcase: a connection that passes the byte budget inside the window getsrate-limited, while its count stays underWATCH_MAX. It runs on every pull request.This issue now carries the
Securitylabel and sits in milestone v2.3.0, under #575. Step 2 can land now. Step 1 waits on #198.HMarzban commentedon Oct 25, 2026
Built and committed on local main. Awaits the maintainer's final push.
Remaining gate: the backend deploy. Measured after #198: the watch read now takes about 2.2 to 3.3 ms on the large test document, down from about 120 to 160 ms.
fix(hocuspocus): add a per-connection byte budget to history.watch
docs(changelog): add the v2.3.0 run entries held back from each issue…
HMarzban commentedon Nov 3, 2026
Shipped in
d40b265b7(changelog in95c1b0acf). Each connection now has a 20 MiB byte budget per 10 s window, beside the count cap. A watch past the budget gets the samerate-limitedrefusal. After #198, the watch read blocks the loop for about 2.2 to 3.3 ms, down from about 120 to 160 ms.