#13788·outline

Documents within the text length limit can become unopenable, and the failure is reported as an authorization error

Author: chenniannian90Created Sep 18, 2026Updated Sep 18, 2026
Labelsbugcollaborative editing

Is there an existing issue for this?

  • I have searched the existing issues

This is not related to configuring Outline

  • The issue is not related to self-hosting config

Current Behavior

Outline enforces two document size limits that are numerically identical but measured in different units:

typescript
// shared/validations.ts
export const DocumentValidation = {
  /** The maximum size of the collaborative document state */
  maxStateLength: 1500 * 1024,   // bytes of Yjs state (BLOB)
  /** The maximum length of the document text content */
  maxLength: 1500 * 1024,        // characters of markdown (TEXT)
};

maxLength is a character count on text. maxStateLength is a byte size on the Yjs state. There is no fixed relationship between the two — the state runs substantially larger than the markdown it encodes — so a document can sit comfortably inside the documented text limit and still be permanently unopenable.

Nothing validates this at write time. maxStateLength is enforced only when the state is persisted, long after the document exists, and by then there is no way to repair it.

What we measured. On a self-hosted instance, octet_length(state) / length(text) — state bytes per markdown character — ranges roughly 1.7–7x. A document at the maxLength ceiling (1,572,864 characters) therefore produces on the order of 2.6–11 MB of state against a 1,572,864-byte limit; even the most favourable ratio we observed is ~1.7x over. The API is wider still — jsonLimit is 5 MB (server/routes/api/index.ts), so documents.create accepts payloads that cannot produce a valid state.

How it fails. One affected document on our instance:

measurement value
octet_length(content::text) (ProseMirror JSON) 3,444,622
octet_length(state) NULL
markdown length well under maxLength

state is NULL, so PersistenceExtension.onLoadDocument rebuilds it from content on every open. That rebuild is already a fresh, history-free encode — precisely what a flatten produces — and it lands ~71% over the limit. The write is rejected, onLoadDocument throws, and the connection closes. The document can no longer be opened or updated by anyone.

Auto-flatten (#10697) does not cover this class. There is no history to drop here; the content alone is over the limit. On our instance the overall state/content ratio is 0.70–0.89, so most documents carry little history and would not be helped either. Auto-flatten addresses documents that are history-bound; this is content-bound and needs a different answer.

The intended behavior already exists and is not wired. shared/collaboration/CloseEvents.ts defines the right event:

typescript
export const DocumentTooLarge = { code: 1009, reason: "Document Too Large" };

and app/scenes/Document/components/ConnectionStatus.tsx already maps it to the right copy — "This document has reached the maximum size and can no longer be edited". But DocumentTooLarge is never raised anywhere on the server; it appears only in its own definition and in the client handler. The only close event the server raises is TooManyConnections (server/collaboration/ConnectionLimitExtension.ts). The throw from onLoadDocument falls through to a generic mapping, and the user is shown the AuthorizationFailed copy — "You may have lost access to this document, try reloading" — which is both wrong and unactionable. Reloading cannot help, and "lost access" points people at their permissions rather than their document size.

That copy also describes a degradation the app already knows how to perform. Documents opened as an archived document, a revision, or a share link render from the stored content and never touch the collaboration layer at all:

typescript
// app/scenes/Document/components/Document.tsx
const multiplayerEditor =
  !document.isArchived && !document.isDeleted && !revision && !isShare;

With multiplayer={false} no Y.Doc is built, no websocket is opened, onLoadDocument never runs, and none of the per-document memory or Redis broadcast cost is incurred. That is why an archived copy of an oversized document still opens today. The switch is keyed on document state, not on size — and "can no longer be edited" reads like exactly this path, applied by size.

Expected Behavior

  1. Validate at write time — reject content that would exceed maxStateLength (the plain-text length gives a cheap upper bound), or derive maxLength from the state limit so the two are actually comparable.
  2. Raise DocumentTooLarge (1009) from the load and store paths when maxStateLength is the cause, so the existing correct copy is what users see.
  3. Degrade oversized documents the way archived documents already degrade — read-only, rendered from content, outside the collaboration layer — so a document that is too large stays readable instead of disappearing entirely.

Per #11197, the only remedy offered today is to recreate the document and paste the content across, which is impossible for a document that can no longer be opened.

Steps To Reproduce

  1. Create a document whose markdown is close to DocumentValidation.maxLength (1,572,864 characters). This passes validation.
  2. Its Yjs state exceeds maxStateLength — on our instance octet_length(state) / length(text) ranges 1.7–7x, so the state lands 1.7–7x over the limit.
  3. From that point the document can no longer be opened or updated: the state write is rejected, onLoadDocument throws, and every client is disconnected.
  4. The client reports an authorization error rather than a size error.

We measured steps 2–4 on production documents rather than constructing a minimal case — the 1.7x–7x range is a direct query against the documents table on that instance. state being NULL while content is 3.4 MB is likewise from production data.

Environment

markdown
- Outline: self-hosted, docker, tracking main
- Browser: any