Skip to content

fix(workspaces): stop checkpointing inside the AI edit turn - #785

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdocuments-stop-checkpointing-inside-548d54
Draft

fix(workspaces): stop checkpointing inside the AI edit turn#785
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdocuments-stop-checkpointing-inside-548d54

Conversation

@posthog

@posthog posthog Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Problem

  • AI document edits fail mid-turn for real users — 54 hits across 54 people in the last 30 days, in the core workspace_edit_item flow.
  • DocumentSession.applyEdits committed the Yjs update and edit receipt to Durable Object storage, then awaited the Postgres checkpoint in the same turn.
  • commitWorkspaceDocumentCheckpoint takes a select ... for update on the workspace row. Under lock contention the storage writes stayed open across that round trip, so Cloudflare reset the object (storage operation exceeded timeout which caused object to be reset).
  • The reset surfaced as a raw RPC failure back to the model — not something it could retry or explain.

Changes

  • Take the checkpoint off the edit turn. applyEdits (and undoDocumentEditReceipt) now commit their storage transaction and return. The document mutation already schedules the debounced onSave, which is the single path that checkpoints to Postgres — now off the user-facing turn.
  • Retry a transient reset. A new classifier matches the caused object to be reset message (the sandbox runtime's isPlatformTransientError only matches the startup variant) and retries the edit RPC with a fresh session stub. The operation id keeps the replay idempotent, so a blip no longer fails the edit.

Notes

  • The Yjs update stays durable in DO storage inside the same transaction, so no content is lost if a checkpoint is delayed; onLoad re-drives it.
  • undoDocumentEditReceipt no longer reports not_found when the item was deleted concurrently; the deferred checkpoint still purges a discarded item.

Test plan

  • New unit tests for the transient classifier and retry wrapper (document-session-transient.test.ts).
  • pnpm check (format + typecheck + lint) passes; workspace document and operation suites pass.

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

DocumentSession.applyEdits committed the Yjs update and edit receipt to
Durable Object storage, then awaited the Postgres checkpoint in the same turn.
That checkpoint takes a contended workspace row lock, so the storage writes
stayed open across a slow round trip and Cloudflare reset the object, failing
the user's AI edit.

- Drop the inline checkpoint from applyEdits and undoDocumentEditReceipt. The
  document mutation already schedules the debounced onSave, which checkpoints
  to Postgres off the edit turn.
- Classify the "caused object to be reset" error as transient and retry the
  edit RPC with a fresh session stub. The operation id keeps the replay
  idempotent.

Generated-By: PostHog Desktop
Task-Id: cb7529ed-3ab7-451d-ab42-ce81a3ced4ce
@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 7f9d93f.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants