Skip to content

Sync doc revisions: keep the last 20 replaced versions per doc, list + restore - #7

Merged
collinrijock merged 1 commit into
mainfrom
feat/sync-doc-revisions
Oct 29, 2026
Merged

collinrijock merged 1 commit into
mainfrom
feat/sync-doc-revisions

Conversation

@collinrijock

Copy link
Copy Markdown
Contributor

Server guard for the Copper spaces-unfiling incident (cu-2th): the server can't read docs, so it keeps what each write replaced.

  • Migration 0015_sync_doc_revisions.sql: sync_doc_revisions (user_id, domain, version, device_id, client_build, updated_at, replaced_at, sealed payload) + nullable sync_docs.client_build. Additive; older clients unaffected.
  • Each overwrite archives the replaced row in the same transaction (row locked), prunes to the newest 20.
  • X-Copper-Build optional header stored per write.
  • GET /v1/sync/docs/{domain}/revisions (metadata), GET …/revisions/{version} (payload), POST …/revisions/{version}/restore (new version + doc event with device_id null so all devices pull).
  • CLI: copper-cloud admin docs revisions|restore --user --domain [--version].
  • features: doc_revisions; docs/api.md updated.
  • Test: tests/api.rs::sync_doc_revisions (archive, build header, stale write, restore + event, isolation, prune to 20, tabs 403, device delete, CLI restore).

…+ restore

Every accepted overwrite of a sync_docs row first copies the old row (sealed bytes, same AAD)
into sync_doc_revisions (migration 0015), newest 20 kept per (user, domain). Optional
X-Copper-Build header is stored with each write. New: GET /v1/sync/docs/{domain}/revisions,
GET .../revisions/{version}, POST .../revisions/{version}/restore (writes it back as a new
version, doc event with device_id null). CLI: copper-cloud admin docs revisions|restore.
features: doc_revisions. Device delete also drops its tabs revisions.

Server half of the spaces-unfiling incident (feads cu-y5o / cu-2th).
@collinrijock
collinrijock merged commit 0840bed into main Oct 29, 2026
2 checks passed
@collinrijock
collinrijock deleted the feat/sync-doc-revisions branch October 29, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant