BoundaryML/baml · info · LspError

-32801

-32801

Error message

Content modified: {0}

What it means

LspError::ContentModified indicates the request's snapshot of a document became stale because an edit was applied while the request was queued or executing. It maps to the LSP ContentModified code -32801. This lets the client know the result would not reflect the current document state and should be re-issued against the newer version.

Source

Thrown at baml_language/crates/baml_lsp/src/error.rs:46

    /// `-32803`).
    #[error("LSP outbound frame exceeds the transport limit")]
    OutboundOversized,
    #[error("Invalid command arguments for command: {command}: {message}")]
    InvalidCommandArguments { command: String, message: String },
    #[error("File not found: {}", .0.display())]
    FileNotFound(PathBuf),
    #[error("Path is invalid: {}: {message}", path.display())]
    InvalidPath { path: PathBuf, message: String },
    /// The document's path is under no known source root.
    #[error("No source root contains {}", .0.display())]
    NoRootForPath(PathBuf),
    /// Cancellation claimed the response while the request was queued or
    /// running (LSP `RequestCanceled`, `-32800`).
    #[error("Request canceled: {0}")]
    RequestCanceled(String),
    /// The request's snapshot became stale under an applied source change
    /// (LSP `ContentModified`, `-32801`).
    #[error("Content modified: {0}")]
    ContentModified(String),
    /// A valid request that cannot be served right now (LSP `RequestFailed`,
    /// `-32803`).
    #[error("{0}")]
    RequestFailed(String),
    /// Violated invariants, panics, serialization (LSP `InternalError`,
    /// `-32603`).
    #[error("Internal error: {0}")]
    Internal(String),
    /// Malformed params, position, or range (LSP `InvalidParams`, `-32602`).
    #[error("Invalid params: {0}")]
    InvalidParams(String),
    /// A request before `initialize` completed (LSP `ServerNotInitialized`,
    /// `-32002`).
    #[error("Server not initialized: {0}")]
    ServerNotInitialized(String),
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Client should catch code -32801 and simply re-send the request with the current document version.
  2. Sequence requests so that a didChange invalidates/supersedes previously issued analysis requests.
  3. Avoid editing the document programmatically while awaiting dependent requests (formatters, code actions).
  4. Enable request debouncing/throttling in the client to reduce races with edits.

Example fix

// before
const edits = await request('textDocument/formatting', params);
// after
async function format(params) {
  try {
    return await request('textDocument/formatting', params);
  } catch (e) {
    if (e.code === -32801) return format(params); // retry on stale snapshot
    throw e;
  }
}
Defensive patterns

Strategy: retry

Type guard

function isContentModified(e) { return e?.code === -32801 || /Content modified/.test(e?.message ?? ''); }

Try / catch

async function withStaleRetry(fn, retries = 2) {
  try { return await fn(); }
  catch (e) {
    if (isContentModified(e) && retries > 0) return withStaleRetry(fn, retries - 1);
    throw e;
  }
}

Prevention

When it happens

Trigger: A didChange notification arrives between when a request (completion, code action, formatting) was received and when its result is computed; the document version the request was based on no longer matches the server's current version.

Common situations: Fast typing during completion/compute-diagnostics; auto-save or format-on-save racing an in-flight request; batch tooling editing files while analysis requests are pending.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/910427680900eb94. Report an issue: GitHub.