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>
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