Two edits: save only the expected revision
A stale edit can overwrite an earlier one. Check the expected revision and the actual affected-row count.
2026-11-19 · 1.0 · PL / EN
01 / A successful write can lose an earlier edit
Two people open the same card. The first corrects a date; shortly afterwards the second saves a version prepared from the old text. Both commands can finish without an error while the first correction disappears. A leader needs an acceptance condition: a write must check which revision the author started from.
Batch import concerned the commit boundary across several records. Here a separate trial used one record and two stale client copies. It is a sequential simulation with original fictional data, without overlapping transactions or a production connection.
02 / The counter grows; the condition protects
The trial ran on 19 November 2026 with Python 3.11.11 and SQLite 3.47.1. Record A starts with Friday and revision 1; unchanged control record B has Control and revision 1. Two separate reads retain the initial A card. Read connections close before any writes.
The first proposal changes the text to Saturday, expecting revision 1. The statement updates a record only when both its identifier and expected revision match. The same statement increments the revision. Parameters are passed separately from SQL.
UPDATE docs
SET body=?, revision=revision+1
WHERE id=? AND revision=?;
Actual Cursor.rowcount and SQL changes() were checked immediately after the write, before COMMIT. Both returned 1 for the first proposal. After committing, closing and reopening, A contains Saturday and revision 2.
03 / The stale proposal gets zero
two copies: A / Friday / revision 1
first write expecting 1 -> 1 row / Saturday / 2
second write expecting 1 -> 0 rows / Saturday / 2
without revision guard -> 1 row / Sunday / 3
The second client proposes Sunday while still supplying revision 1. Both counters return 0; reopening preserves Saturday and revision 2. No SQL exception occurred. The code handling the write must recognise that the proposal was not accepted.
In a separate control database the revision predicate was removed while the increment remained. The second write changed one record to Sunday and revision 3. An increasing counter alone did not prevent losing the first correction. Protection comes from comparing the expected revision within the write statement.
04 / Zero needs an explanation
A separate write targeting a missing ID also returned 0. The counter alone therefore cannot distinguish a stale record from an absent one. A real system must also consider permissions and service rules; these were not tested. Another read can help explain the situation but may itself become stale before another write.
In a third variant, after rejecting the stale proposal, the script explicitly read Saturday and revision 2. Only then did a separate scripted decision propose Sunday again, now based on revision 2. The write changed one record and reopening retained revision 3. This is a programmed demonstration decision, without a user study. Automatically replacing the expected number and sending the old proposal again would conceal the conflict.
05 / An editing acceptance card
ID and revision read by each client:
first proposal / expected revision / affected rows:
stale proposal / expected revision / affected rows:
state after committing and reopening:
missing ID / explanation of a zero result:
new read / explicit decision / subsequent write:
unchanged control record and trial boundaries:
The trial passed 36 recorded checks across four databases, including the deliberately unguarded variant. All databases passed integrity_check and B remained unchanged. The pre-execution expectations, inputs, code, client reads, counters and persisted states were retained. These are not 36 independent experiments or a load test.
The condition operates within the declared rule: every accepted change increments the revision, the number never returns to an old value, and every guarded write path checks it. The trial does not cover deleting and recreating IDs, counter overflow, field merging, audit history, WAL, locks or crashes. A whole-record check may also reject edits to different fields; it does not replace a merge policy.
06 / Sources and responsibility
SQLite UPDATE explains row selection through WHERE and a valid zero-row result. SQLite changes and Python Cursor.rowcount explain the counters used; SQLite isolation rules were also read. No triggers, views or RETURNING were used. Documentation explains the mechanism; results come from the executed trial in the stated environment.
Codex prepared the fictional data, code, PL/EN, static SVG and ASCII and performed the agent roles of editorial, management and control. There was no independent second-model review. No third-party records or recordings were used. The diagram presents recorded results. A change to revision rules, write paths or zero-result handling triggers another acceptance review. Lech retains the ability to withdraw the publication. Can your application tell an author that their write was not accepted?