0
Fork 0
mirror of https://github.com/zeronsh/comet.git synced 2026-11-16 18:57:19 +00:00
comet/edge/scripts/reset-check.mjs
wing-anara 88714bd966 Workspace room: retry initial join + an edge wedge-break for a bloated DO
Diagnosing why every device still showed offline after the fold fix
surfaced two more bugs that together wedged the per-user workspace room
permanently:

1. Engine never retried the FIRST join. crates/sync RoomClient only
   self-reconnects AFTER a successful join; an initial failure (a 500 from
   an overloaded workspace DO, a token racing a refresh, an edge deploy)
   ended workspace_host's join task with "staying offline" and the device
   stayed offline until an app restart — presence dead while the relay and
   per-chat rooms worked. Three engines restarting together reliably hit
   this: they hammered the cold DO at once, all got 500s, all gave up.
   Now join_room retries on a capped, jittered backoff (jitter so a
   simultaneous fleet restart doesn't resynchronize into a herd).

2. The DO was already wedged and no client-side retry could heal it. Its
   update log had grown huge (the pre-fix byte-only cap never tripped on
   tiny writes), so every cold `ensureDoc` replay exceeded the DO CPU
   limit and reset before any join finished — which also blocked the
   compaction that would have shrunk it. A solo join hung 50s+ and never
   landed. Add POST /workspace/:orgId/reset-log: it drops the persisted
   update log + snapshot WITHOUT calling ensureDoc (so it stays cheap
   enough to land on a wedged DO) and boots attached sockets. State is not
   lost — every engine re-uploads its full local workspace doc on the next
   join ("export everything the server lacks", room.rs:19), the same
   recovery as an ws-namespace bump but without client version skew.
   Verified against wrangler dev: 51 rows cleared to 0, empty room then
   accepts a fresh join + write.

The fold fix (row-count trigger) keeps a healthy room from re-bloating;
this pair recovers one that already did and stops a transient blip from
stranding a device.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-25 04:49:51 +03:00

68 lines
3 KiB