Skip to content

id(web/collab): document step history grows without bound — no cap or compaction, and every joiner is sent a clone of the entire history #2969

Closed

Description

@dezren39

Problem

A collab document's step history grows without any bound for as long as the document lives, and every new joiner is sent a clone of the entire history. Any connected client — including an anonymous one, since collab auth is optional and failure proceeds as anonymous — can grow server memory and join-time catch-up cost without limit by sending Steps frames.

Evidence (main ed59bc6d, pkgs/id/src/web/collab.rs)

  • :217 / :250 — Document.steps: RwLock<Vec<(Step, serde_json::Value)>>, created empty; the module has no cap constant for it (contrast the encryption adapter, which bounds its held set by both count and bytes: MAX_HELD_MESSAGES / MAX_HELD_BYTES, pkgs/id/src/encryption/scheme.rs:66,72, enforced in Phase 4: held application messages need a bound #186 precisely so an unreadable-message flood cannot grow memory forever).
  • :1020-1028 — the only mutation site appends every step of every accepted Steps frame: doc_steps.push(...) per step. grep over the file shows no truncate, drain, remove, cap check, or compaction of steps anywhere; steps are never folded into the base document (Document.doc is the initial content, :211; the Init frame even hardcodes version: 0 as "base", :765 — see also id(web): image uploads can dispatch against a destroyed editor view #2799).
  • :1029-1033 — the version is just a counter (fetch_add(steps.len())); nothing ever resets it or the history when a save persists the document (notify_new_version, :352-375, only broadcasts and updates the stored hash).
  • :791-806 — on every join, the handler clones the whole history into a catch-up Update (steps.iter().map(|(step, _)| step.data.clone())), so join cost and allocation are O(total steps ever submitted) per joiner, forever.
  • :342-350 / cleanup in handle_collab_socket — a document is only removed after the last client has been gone for DOCUMENT_CLEANUP (1 hour, :185); a single client that stays connected (or reconnects within the hour) keeps the document — and its entire history — alive indefinitely.
  • The Steps path itself has no per-message bound either: CollabMessage::decode (:536-545) accepts a steps vector of any length the WebSocket frame carries, and the handler checks only the version before appending all of them.

Verification this run: code-read verification on current main — full-text search of collab.rs for every steps mutation/read site (append at :1023 is the only push; reads are the catch-up clone and tests), plus the absence of any cap constant or compaction call in the module.

Why it matters

This is an unbounded-memory / unbounded-work surface reachable by any peer that can open the collab socket (auth failure still proceeds as anonymous, :716-753). Long-lived shared documents — exactly the ones with the most history — become the most expensive to join and the largest memory residents, and a hostile or buggy client can accelerate that arbitrarily. The codebase's own precedent (#186) is that sets which grow on peer input get an explicit count+bytes bound with a refusal that neither poisons nor evicts; the collab history has neither a bound nor a compaction story.

Acceptance criteria

  • Triage pins the remedy shape: e.g. periodic compaction of applied steps into the base document (advancing the Init base version — interacts with id(web): image uploads can dispatch against a destroyed editor view #2799, coordinate there), and/or a hard cap on retained steps / total step bytes with an explicit desync/reconnect error (the Lagged path at :896-906 is the existing pattern) when the cap is hit.
  • After the fix, retained history per document is bounded by a named constant (count and/or bytes), whatever traffic a client sends.
  • Join-time catch-up no longer clones an ever-growing history: its size is bounded by the same constant, or by the compacted base + a bounded tail.
  • A test submits steps past the bound (or past a compaction threshold) and asserts the bound/compaction behaviour and that a fresh joiner still reconstructs the same document.
  • Normal editing below the bound is unchanged: Steps are Acked, broadcast, and replayed as before.

Dedup / related

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/normalOrdinary priority (the default)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 31, 2026
  2. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

  3. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: done (closed as duplicate)

  4. added and removed on Oct 31, 2026
  5. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    Correction to the closing note above: queue task 4265 could NOT be cancelled — it is already claimed by lane code-pilot-fix-2026-10-30-2256 (cancel refuses a claimed task). Holder: please stand down on this task/issue — it is a duplicate of #1965, whose comment #1965 (comment) now carries the only unique remainder. Fleet-monitor reconciliation should also close the task out against this closed issue.

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

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)meta/duplicateDuplicate of another issuepriority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus/duplicateAlready tracked elsewheretask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions