Skip to content

fix: increment revision on updateMarks to preserve CAS invariant#9

Open
tmchow wants to merge 1 commit intoEveryInc:mainfrom
tmchow:fix/update-marks-revision-bump
Open

fix: increment revision on updateMarks to preserve CAS invariant#9
tmchow wants to merge 1 commit intoEveryInc:mainfrom
tmchow:fix/update-marks-revision-bump

Conversation

@tmchow
Copy link

@tmchow tmchow commented Mar 12, 2026

Bug

updateMarks in server/db.ts updated marks and updated_at but never incremented revision:

-- before
SET marks = ?, updated_at = ?

-- after
SET marks = ?, updated_at = ?, revision = revision + 1

Every other write path (updateDocumentAtomic, updateDocumentAtomicByRevision) increments revision. updateMarks did not.

Impact

The edit/v2 endpoint uses baseRevision as a CAS lock via updateDocumentAtomicByRevision. Because marks mutations left revision unchanged, an agent could:

  1. Read the document at revision = N
  2. A marks mutation fires — document still at revision = N
  3. Agent calls edit/v2 with baseRevision = N — CAS check passes on a stale base
  4. Agent write silently clobbers the mark anchors

Fix

Added revision = revision + 1 to the updateMarks SQL in server/db.ts, consistent with all other write paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
densign01 added a commit to densign01/proof-sdk that referenced this pull request Mar 16, 2026
Port PR EveryInc#23: set terminalCloseReason in authenticationFailed handler so
expired collab tokens (5 min TTL) trigger auto-reconnect instead of
silently dropping agent edits.

Port PR EveryInc#9: increment revision in setMarks SQL so marks updates maintain
the compare-and-swap invariant for concurrent agent edits.
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