Repository navigation
Description
Summary
The WebSocket server and the worker stall for 1 to 3.35 s, and no panel or alert shows it. A stall freezes every open pad on that replica. Cold room loads cause the stalls we can explain. This issue makes stalls visible on a panel and a non-paging rule, and counts WebSocket closes by code (#739 reads them). The head cleanup in #738 is the first fix for the stalls, so #738 owns the stall-hour after-read.
Benchmark
| Field | Value |
|---|---|
| Metric | This issue: panels that show max lag (count); rules that fire on a 1 s stall (count); firing count of a 14-day backtest of the new rule; pages from the new rule (count). Context for #738: stall-hours over 1 s per week per process; stalls over 1 s per 100 room loads of size_class 1to4m or larger (#750). Close codes: WebSocket closes by code over 7 days. |
| Before | Panels 0, rules 0, pages 0 (code-read at 0b302b222). Stall-hours, NYC1, 7 days to 2026-11-10 17:04Z: hocuspocus-server 30, hocuspocus-worker 18, rest-api 0 (longest 0.715 s) (Measured comment; Before reads). Backtest, 14 days: 81 firings at for: 0s, 23 at for: 5m, 0 from rest-api (same comment). London, per process with rest-api, over the one window that #738 owns (step 8): not measured yet: maintainer, before #738 ships. Longest WebSocket stall in London, 09:00Z to 12:00Z on 2026-11-11: 2.07 s (#750 read). Stalls per 100 room loads: not measured yet, it needs #750. Close codes: new series, so the before is its first 7 days. |
| After | not measured yet |
| Condition | Production at the deployed SHA, collab database in London on PostgreSQL 18.6. Stall-hours depend on traffic, so each read also states the room-load count for its window. |
| How to run | Stall-hours: the query below, 168 hourly samples per process. Backtest: evaluate the new rule's expression in Grafana Explore over the last 14 days. |
| Pass rule | Panels 0 -> 1. Rules that fire on a 1 s stall 0 -> 1. Pages from the new rule 0. slo-eventloop-lag still loads. The backtest count is posted before the rule ships. If the new rule pages, revert the rule commit and run the observability deploy. |
| Guard | The new rule routes as a warning only. The close-code series is seeded at 0. |
| Owner | Agent in the repo: panel, rule and metrics. Maintainer: reads, backtest post and the route ruling. |
| Claim | Ops, with Decision 2 ruled for: 5m: "Repeated stalls over 1 s now raise a warning, and every stall shows on a panel. Paging alerts from stalls: 0." |
count_over_time((max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[1h])) > 1)[7d:1h])
Before reads
7 days to 2026-11-10 17:04Z. The database was in NYC1.
Before of record: the Measured comment of 2026-11-11, window 2026-11-03 17:04Z to 2026-11-10 17:04Z.
| Process | Hours with a stall over 1 s | Hours over 0.5 s | Longest stall | Max of p99 lag |
|---|---|---|---|---|
rest-api |
0 | 2 | 0.71499 s | 0.011067 s |
hocuspocus-server |
30 | 64 | 1.9951 s | 0.021725 s |
hocuspocus-worker |
18 | 21 | 3.3497 s | 0.011731 s |
-
Backtest of the new rule, 14 days, 2026-10-28 00:00Z to 2026-11-11 00:00Z, NYC1. It counts 81 firings at
for: 0s(53 server, 28 worker), 23 atfor: 5m, and 0 fromrest-api. -
The only rule,
slo-eventloop-lag(scripts/observability/grafana/provisioning/alerting/rules-app-slo.yml:132), readsnodejs_eventloop_lag_p99_secondsabove 0.1 s. That value never passed 0.022 s, so no stall can fire it. -
No panel shows
nodejs_eventloop_lag_max_seconds, the only metric that sees a stall. The lag panel reads one sample per scrape. -
On 2026-11-09, from 01:00Z to 05:00Z, one replica stalled over 0.5 s 14 times. All 14 fell in a minute with a cold room load. Those 14 loads had a median of 1.95 s.
What to do
Steps 1 to 3 and 7 are dropped. The other step numbers stay, because #738 and #739 cite them.
- Agent in the repo. Add a panel:
max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds[5m])). - Agent in the repo. Keep
slo-eventloop-lag, which catches sustained lag. Add a new non-paging rule on the step 4 expression above 1 s. One night stall should not page anyone (SRE book, ch. 6). The route follows Decision 1. - Agent in the repo. Close codes:
ws_disconnects_total{code}. Hocuspocus 3.4.4onDisconnectcarries no close code. So add a close listener on each socket throughserver.webSocketServer.on('connection')inhocuspocus.server.ts. Bind thecodelabel to1000,1001,1006,1009andother, seeded at 0. - Maintainer. Read the London before over the one stall-hour window that Clear y-tiptap position-migration maps on the server, so big pads load faster #738 owns. Ruled 2026-11-16 (ruling): 7 days that end at the Clear y-tiptap position-migration maps on the server, so big pads load faster #738 deploy. They start after the later of the Measure stored head size, save and load phases by pad size, and loaded room bytes #750 and Take y-tiptap 3.3.0 with Tiptap 3.33.1 and drop the local y-tiptap patch #701 deploys. If the gap between deploys is shorter, state it in the claim. Post the days, the room-load count, and the count normalized to 7 days, with a
rest-apirow. Add a normalized row: stalls over 1 s per 100 room loads ofsize_class1to4mor larger (from Measure stored head size, save and load phases by pad size, and loaded room bytes #750). Maintainer. Run the 14-day backtest of the new rule and post its firing count.Done 2026-11-11 (Measured comment): 81 firings atfor: 0s, 23 atfor: 5m.
Out of scope: moving the decode to a worker thread. The warm-unload grace and other fixes wait for a data-safety review (2026-11-11 Added scope comment). The unload-to-load histogram (old step 7) moves to the issue that takes the grace fix, because no v2.3.7 issue reads it.
Decisions
Both are ruled (ruling 2026-11-16).
- Route for the new rule.
severity: warningalready routes totelegram-ops-warningswith a 4 h repeat. Ruled: severity warning, no critical route. - The rule's
forvalue. It changes firings 3.5 times: 81 atfor: 0sagainst 23 atfor: 5min the backtest. Atfor: 0sthe warning channel gets about 6 a day. Ruled:for: 5m. A[5m]window holds one stall for about 5 minutes, sofor: 5mhides most single stalls. The claim then says "repeated stalls", and the panel still shows every stall.
Acceptance criteria
- The panel shows max lag per process.
- The new rule exists and does not page;
slo-eventloop-lagstill loads. -
ws_disconnects_total{code}is live, seeded at 0. -
The London before is in aMoved step 8 to Clear y-tiptap position-migration maps on the server, so big pads load faster #738 perMeasuredcomment, with arest-apirow.2026-11-24maintainer ruling. - The NYC1
rest-apirow is posted (Measured comment). - The 14-day backtest count is posted (Measured comment).
- Decisions 1 and 2 are ruled before step 5 (2026-11-16).
Related
- Clear y-tiptap position-migration maps on the server, so big pads load faster #738: the head cleanup, and the stall-hour after-read.
- Measure stored head size, save and load phases by pad size, and loaded room bytes #750:
size_class, and the naming review for the new series. After the Measure stored head size, save and load phases by pad size, and loaded room bytes #750 deploy, compare windows on one side of it only, or compare exact means (_sum/_count). - Cut MCP write time on large pads and stop its four false alerts #726: Cause 4 covers other false alerts.
- Keep health checks out of the API error and latency alerts #710: the REST rules that read health checks.
- Send save confirmations and access frames to local connections only #758: owns the reconnect counter name (
ws_redis_subscriber_reconnects_total). Review the new series names with it.
Activity
HMarzban commentedon Nov 11, 2026
Correction, 2026-11-11: the migration path is off in production
ENABLE_SCHEMA_MIGRATIONis unset in every collab container: bothhocuspocus-serverreplicas, a worker and a REST container (read withprintenvon the host). So the double decode in "Cause to check first" does not run. Steps 1 to 3 need no action.The stalls come from the single decode of large heads. From the collab research of the same day (local Bun 1.4.4, synthetic pads, so read the times as ratios):
So the next steps for this issue change:
HMarzban commentedon Nov 11, 2026
Added scope, 2026-11-11: measure cold rooms before choosing a fix
A data-safety review of the collab research ruled that the warm-unload grace waits for data. Two measure-only steps come first, with no behaviour change:
ws_disconnects_total{code}. 57 % of connections open a cold room, and nobody knows why tabs reconnect so often.Why the grace waits:
DirectConnection.disconnect()waits for the unload, so a G-second grace adds G seconds to every cold MCP write. That undoes Cut MCP write time on large pads and stop its four false alerts #726.server.destroy()waits for every room to unload, so a large grace can trip the 25 s shutdown race on deploy.afterLoadDocument, so the other replica can stay stale until the next edit.The head cleanup in #738 is the first fix for the stalls. Measure stall-hours before and after it.
[-]Show event-loop stalls on a panel, and drop the cold-load migration decode if no pad needs it[/-][+]Show event-loop stalls on a panel and a non-paging rule, and measure cold-room reloads[/+]HMarzban commentedon Nov 11, 2026
Measured, 2026-11-11.
rest-apirow for the NYC1 before, and the 14-day backtest of the new rule (step 9).1. Stall-hours, NYC1 week
Longest stall:
max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[7d])). Max of p99: the same query onnodejs_eventloop_lag_p99_seconds. Room loads:sum by (job) (increase(document_load_duration_seconds_count[7d])).rest-apihocuspocus-serverhocuspocus-workerhocuspocus-server.count_over_timereturns no series forrest-api, because no hour passed 1 s. The table shows that as 0.rest-apihours over 0.5 s: 2026-11-05 15:00Z (0.715 s) and 2026-11-09 19:00Z (0.556 s).2. Backtest of the new rule, 14 days
job.foryet, so the count assumesfor: 0s.for: 0sfor: 5mrest-apihocuspocus-serverhocuspocus-workerFirings by day,
for: 0s:hocuspocus-serverhocuspocus-worker[5m]window holds one stall for about 5 minutes. Sofor: 5mhides most single stalls, andfor: 0sfires on each one.What this means for the pass rule
rest-apihad no stall over 1 s in the NYC1 week or in 14 days. Its before is 0 stall-hours, and its longest stall was 0.715 s.for: 0s, or 23 atfor: 5m. That is about 6 a day atfor: 0s, and 0 of them fromrest-api.severity: warning(Decision 1). At 81 firings in 14 days, the warning channel would get many messages. The 4 h repeat and alert grouping set the real message count.729-*.jsonbeside this file.HMarzban commentedon Nov 14, 2026
Moved to v2.3.7 at the v2.3.6 release audit. The NYC1 before and backtest are posted. The panel, rule, new series, London before and after are not done.
HMarzban commentedon Nov 16, 2026
Maintainer ruling, 2026-11-16
Answered by the maintainer in the 2026-11-16 working session; posted by the agent.
telegram-ops-warnings, 4 h repeat).for: 5m. The claim says "repeated stalls". The panel still shows every stall.HMarzban commentedon Nov 16, 2026
Review, 2026-11-16 (maintainer approved).
ws_disconnects_total{code}from step 6.<cap>placeholder and the dead "depends on Fail the observability deploy when Grafana or its provisioned rules do not load #753" lines.feat(hocuspocus): count websocket closes by close code
feat(observability): alert on a one-second event-loop stall
HMarzban commentedon Nov 17, 2026
Measured, 2026-11-17. Steps 4, 5 and 6, in
ea4f8f81b(counter) and05f733521(panel and rule). Both are deployed: the counter by(build): front back(run 44025904215), the panel and rule by(build): observability(run 44027220672). The numbers below are code-read and local runs.Panels and rules, code-read
5aa56e1d1(before) and the working tree (after). Exact counts by grep of the expression.git show HEAD:<file> | grep -c nodejs_eventloop_lag_max_secondsover each dashboard and each ruleexpr.slo-eventloop-stall)severity: warning, routes totelegram-ops-warnings, 4 h repeat)slo-eventloop-lagloadsfor: 5m(Decision 2):max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[5m])) > 1rules-realtime.ymlnames the metric in a summary only. No ruleexprread it before.for: 5m, 0 fromrest-api.Provisioning load
grafana/grafana:13.1.0, local Docker,--network none, alert execution off. This is the same check as the observability deploy step. Contact points used dummy values.slo-eventloop-stallandslo-eventloop-lagboth read back withfor: 5mandseverity: warning.docsplus-app-performanceloaded. Panel ids: 0 duplicates. Grid cells: 0 overlaps.w: 24tow: 12. Panel 82 sits beside it atx: 12, y: 134. No panel changedxory.ws_disconnects_total{code}wsmodule that Hocuspocus 3.4.4 uses, wired likeServer.ts. n = 3 runs, same result each time.1000,1001,1006,1009,other.close(1000)1000close(1001)1001maxPayload1009close(4408)other1006maxPayload. But it reports 1006 to the server's close event. The socketerrorcarriescode: WS_ERR_UNSUPPORTED_MESSAGE_LENGTH. The listener counts that close as1009. Without it, the1009series would always read 0, and Compress collab WebSocket frames with permessage-deflate, behind a flag #739 could not tell refusals from drops.Not done here
ws_disconnects_total{code}after run 44025904215 are the before for Compress collab WebSocket frames with permessage-deflate, behind a flag #739.HMarzban commentedon Nov 24, 2026
Maintainer ruling, 2026-11-24
Move step 8 (the London stall-hour before read) into #738, which owns the stall-hour before and after comparison.
#729 closes once the live check of AP 82 and
ws_disconnects_total{code}is posted. Next step: verify those live metrics and close #729.HMarzban commentedon Nov 24, 2026
Measured, 2026-11-24: live panel, non-paging rule, and
ws_disconnects_totalQuestion: Are the max-lag panel, non-paging stall rule,
slo-eventloop-lag, andws_disconnects_total{code}all live in production?Setup. Production Grafana API and Prometheus, read-only,
2026-11-24 07:15Z.Result:
"Event Loop Max Lag by Job (5m)"live ondocsplus-app-performance(max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[5m]))).slo-eventloop-stall(state=inactive,health=ok,severity: warning,for: 5m) andslo-eventloop-lag(state=inactive,health=ok) both load cleanly. In Grafana alert annotations (2026-11-16..2026-11-24),slo-eventloop-stallmoved cleanly through3warning transitions (0pages).ws_disconnects_total{code}live on current containers:1000=0,1001=74,1006=143,1009=0,other=87.beforeread) moved to Clear y-tiptap position-migration maps on the server, so big pads load faster #738 per the2026-11-24maintainer ruling.Verdict: All
#729acceptance criteria pass; closing#729.