Skip to content

Show event-loop stalls on a panel and a non-paging rule, and measure cold-room reloads #729

Done

Description

@HMarzban

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 at for: 5m, and 0 from rest-api.

  • The only rule, slo-eventloop-lag (scripts/observability/grafana/provisioning/alerting/rules-app-slo.yml:132), reads nodejs_eventloop_lag_p99_seconds above 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.

  1. Agent in the repo. Add a panel: max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds[5m])).
  2. 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.
  3. Agent in the repo. Close codes: ws_disconnects_total{code}. Hocuspocus 3.4.4 onDisconnect carries no close code. So add a close listener on each socket through server.webSocketServer.on('connection') in hocuspocus.server.ts. Bind the code label to 1000, 1001, 1006, 1009 and other, seeded at 0.
  4. 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-api row. Add a normalized row: stalls over 1 s per 100 room loads of size_class 1to4m or larger (from Measure stored head size, save and load phases by pad size, and loaded room bytes #750).
  5. Maintainer. Run the 14-day backtest of the new rule and post its firing count. Done 2026-11-11 (Measured comment): 81 firings at for: 0s, 23 at for: 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).

  1. Route for the new rule. severity: warning already routes to telegram-ops-warnings with a 4 h repeat. Ruled: severity warning, no critical route.
  2. The rule's for value. It changes firings 3.5 times: 81 at for: 0s against 23 at for: 5m in the backtest. At for: 0s the warning channel gets about 6 a day. Ruled: for: 5m. A [5m] window holds one stall for about 5 minutes, so for: 5m hides most single stalls. The claim then says "repeated stalls", and the panel still shows every stall.

Acceptance criteria

Related

Activity

  1. added this to the v2.3.6 milestone on Nov 11, 2026
  2. added
    Performance
    on Nov 11, 2026
  3. HMarzban commented on Nov 11, 2026

    @HMarzban
    CollaboratorAuthor

    Correction, 2026-11-11: the migration path is off in production

    ENABLE_SCHEMA_MIGRATION is unset in every collab container: both hocuspocus-server replicas, a worker and a REST container (read with printenv on 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):

    • 57 % of WebSocket connections (435 of 767, 36 hours) opened a cold room. 161 room loads took over 1 s.
    • After the database moved to London (08:34Z to 09:24Z, n = 7 loads), 4 small-pad loads took under 50 ms. One big-pad load took 1 to 2.5 s, with a 0.973 s event-loop stall. The sample is small.
    • On a synthetic big pad, clearing the migration maps cut decode time by 65 % (183 ms to 65 ms).

    So the next steps for this issue change:

    1. Steps 4 and 5 stay: the panel and the non-paging rule.
    2. Add a measure-only histogram of the gap between a room's unload and its next load. It shows how many cold loads a short warm grace would avoid.
    3. The fix candidates (a warm-unload grace, clearing migration maps) go through a data-safety review first. They are not in this issue's scope yet.
  4. HMarzban commented on Nov 11, 2026

    @HMarzban
    CollaboratorAuthor

    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:

    1. Close codes. Count WebSocket closes by code, as ws_disconnects_total{code}. 57 % of connections open a cold room, and nobody knows why tabs reconnect so often.
    2. Unload-to-load gap. A histogram of the time from a room's unload to its next load. It shows how many cold loads a short grace would avoid.

    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.
    • A reconnect into a warm room fires no afterLoadDocument, so the other replica can stay stale until the next edit.
    • One 12.5 MB room costs about 289 MB of RSS. The WebSocket server peaked at 511 MB of 1 GiB in 7 days.

    The head cleanup in #738 is the first fix for the stalls. Measure stall-hours before and after it.

  5. changed the title [-]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[/+] on Nov 11, 2026
  6. HMarzban commented on Nov 11, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-11. rest-api row for the NYC1 before, and the 14-day backtest of the new rule (step 9).

    1. Stall-hours, NYC1 week

    • Source: production Prometheus, read-only.
    • Window: 2026-11-03 17:04Z to 2026-11-10 17:04Z (instant query at 2026-11-10 17:04Z).
    • Step: 1 h. n = 168 hourly samples per process (2026-11-03 18:00Z to 2026-11-10 17:00Z).
    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])
    

    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 on nodejs_eventloop_lag_p99_seconds. Room loads: sum by (job) (increase(document_load_duration_seconds_count[7d])).

    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
    • Room loads in the window: 1,420.3, all on hocuspocus-server.
    • count_over_time returns no series for rest-api, because no hour passed 1 s. The table shows that as 0.
    • The two rest-api hours over 0.5 s: 2026-11-05 15:00Z (0.715 s) and 2026-11-09 19:00Z (0.556 s).
    • The same query today reads 30 and 18 for the collab processes. The body says 29 and 16, from an earlier read with the same window and expression. The cause of the 1-hour and 2-hour gap is not known. This comment is the before of record: 30 and 18.

    2. Backtest of the new rule, 14 days

    • Expression: the step 4 panel expression above 1 s, per job.
    • Window: 2026-10-28 00:00Z to 2026-11-11 00:00Z. The database was in NYC1 for the whole window.
    • Step: 1 min, the Grafana evaluation interval. n = 20,161 samples per process, with no gaps.
    • A firing is one change from Normal to Firing. The rule has no for yet, so the count assumes for: 0s.
    max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[5m])) > 1
    
    Process Firings, for: 0s Minutes Firing Firings, for: 5m
    rest-api 0 0 0
    hocuspocus-server 53 286 5
    hocuspocus-worker 28 367 18
    Total 81 653 23

    Firings by day, for: 0s:

    Day hocuspocus-server hocuspocus-worker
    2026-10-28 to 2026-11-04 0 0
    2026-11-05 0 3
    2026-11-06 0 3
    2026-11-07 8 16
    2026-11-08 1 3
    2026-11-09 15 2
    2026-11-10 29 1
    • A [5m] window holds one stall for about 5 minutes. So for: 5m hides most single stalls, and for: 0s fires on each one.
    • Firings by hour (UTC) spread over the whole day. 13 of the 53 server firings fell from 00:00Z to 03:59Z.

    What this means for the pass rule

    • rest-api had 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.
    • The backtest count for the pass rule is 81 firings in 14 days at for: 0s, or 23 at for: 5m. That is about 6 a day at for: 0s, and 0 of them from rest-api.
    • Pages from the new rule stay 0 only if the rule routes as 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.
    • Raw responses: 729-*.json beside this file.
  7. HMarzban commented on Nov 14, 2026

    @HMarzban
    CollaboratorAuthor

    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.

  8. modified the milestones: v2.3.6, v2.3.7 on Nov 14, 2026
  9. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-16

    Answered by the maintainer in the 2026-11-16 working session; posted by the agent.

  10. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Review, 2026-11-16 (maintainer approved).

  11. HMarzban commented on Nov 17, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-17. Steps 4, 5 and 6, in ea4f8f81b (counter) and 05f733521 (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

    • Source: the repo at 5aa56e1d1 (before) and the working tree (after). Exact counts by grep of the expression.
    • Before: git show HEAD:<file> | grep -c nodejs_eventloop_lag_max_seconds over each dashboard and each rule expr.
    • After: the same grep on the working tree.
    Metric Before After
    Panels that show max lag 0 1 (panel 82, "Event Loop Max Lag by Job (5m)")
    Rules that fire on a 1 s stall 0 1 (slo-eventloop-stall)
    Rules on a critical route from this change 0 0 (severity: warning, routes to telegram-ops-warnings, 4 h repeat)
    slo-eventloop-lag loads yes yes
    • Rule expression, the step 4 expression above 1 s, for: 5m (Decision 2):
      max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[5m])) > 1
    • rules-realtime.yml names the metric in a summary only. No rule expr read it before.
    • The backtest of record stays the 2026-11-11 comment: 23 firings in 14 days at for: 5m, 0 from rest-api.

    Provisioning load

    • Condition: 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.
    • Result: 67 of 67 rules loaded (n = 1). slo-eventloop-stall and slo-eventloop-lag both read back with for: 5m and severity: warning.
    • Dashboard docsplus-app-performance loaded. Panel ids: 0 duplicates. Grid cells: 0 overlaps.
    • Panel 44 moved from w: 24 to w: 12. Panel 82 sits beside it at x: 12, y: 134. No panel changed x or y.

    ws_disconnects_total{code}

    • Condition: local, Bun 1.4.4, the ws module that Hocuspocus 3.4.4 uses, wired like Server.ts. n = 3 runs, same result each time.
    • At start, all five series read 0: 1000, 1001, 1006, 1009, other.
    • Each run: one client close each with 1000, 1001 and 4408, one oversized message, and one dropped TCP socket.
    Close Code on the server's close event Label counted
    Client close(1000) 1000 1000
    Client close(1001) 1001 1001
    Message over maxPayload 1006 1009
    Client close(4408) 4408 other
    TCP drop, no close frame 1006 1006

    Not done here

  12. HMarzban commented on Nov 24, 2026

    @HMarzban
    CollaboratorAuthor

    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.

  13. HMarzban commented on Nov 24, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-24: live panel, non-paging rule, and ws_disconnects_total

    Question: Are the max-lag panel, non-paging stall rule, slo-eventloop-lag, and ws_disconnects_total{code} all live in production?

    Setup. Production Grafana API and Prometheus, read-only, 2026-11-24 07:15Z.

    Result:

    • Dashboard panel: "Event Loop Max Lag by Job (5m)" live on docsplus-app-performance (max by (job) (max_over_time(nodejs_eventloop_lag_max_seconds{job=~"rest-api|hocuspocus-server|hocuspocus-worker"}[5m]))).
    • Alert rules: slo-eventloop-stall (state=inactive, health=ok, severity: warning, for: 5m) and slo-eventloop-lag (state=inactive, health=ok) both load cleanly. In Grafana alert annotations (2026-11-16..2026-11-24), slo-eventloop-stall moved cleanly through 3 warning transitions (0 pages).
    • ws_disconnects_total{code} live on current containers: 1000=0, 1001=74, 1006=143, 1009=0, other=87.
    • Step 8 (the London stall-hour before read) moved to Clear y-tiptap position-migration maps on the server, so big pads load faster #738 per the 2026-11-24 maintainer ruling.

    Verdict: All #729 acceptance criteria pass; closing #729.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DevOpsPerformance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions