A refetched compare-and-swap token authorizes the stale document
Situation: an editor Save returned 409 because another session had advanced the draft revision. The client refetched the workflow, copied the new revision into the save token, and left the canvas graph as the user had loaded it. The retry sent the new token with the old graph and the server accepted it, restoring the stale graph over the other editor.
The same shape showed up twice more. A repair proposal was built against revision N, then adoption fetched the workflow again and sent the latest revision, so a competing save between proposal and adopt authorized an older candidate. Two sessions both read revision N into memory and both marked their repair adopted; the last pointer write won.
What to check on a compare-and-swap draft: - Bind the expected revision to the document currently on screen. A 409 may refresh server state, but it must not replace the token until the user reloads or merges that document. - Adoption uses the revision captured with the proposal, not a later GET. - The pointer update is conditional: UPDATE ... SET revision = revision + 1 WHERE id = ? AND revision = ?. If the rowcount is not 1, do not mark the proposal adopted. An in-memory check of an object loaded before the other commit still says the old revision. - A row lock only helps if you refresh after acquiring it. On SQLite, FOR UPDATE is a no-op, so the conditional update is the check that actually serializes the two writers.
Sibling traps from the same review, all "a value captured earlier is reused after the world changed": - A retrieval cache that skips the access check on a hit keeps serving text after the member is denied. Revalidate on the hit and drop the cache when denied. - A KNN query that takes top_k and then filters to revision members lets a non-member consume the only slot. Filter membership before the limit. A JSON fallback that only scores unindexed rows will not recover the indexed member you just dropped. - With autoflush off, a query after delete still sees the pending deletes. Flush before hashing membership, and omit the deleted source. If sealed chunks are the same rows you reassign to the next version, deletion and reseal erase history. Copy version-owned chunks and leave the editable rows unmarked. - A sequence allocated from the in-memory head collides under two seals and rolls back a valid upload. Retry the seal in a savepoint after IntegrityError so the caller's new rows survive. - A validate endpoint whose default runner always defers never runs either graph, and a UI that treats any non-pass as permission to adopt unvalidated will ship the unvalidated graph by itself. Wire a real runner, and make unvalidated adoption a separate explicit action.