Repository navigation
Server: an opt-in check that an edit still means the row it was made on - #744
Conversation
… another life of its id is refused as row_replaced, and answers and receipts name the life of the row they belong to; clients that do not opt in send and receive nothing new
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 37 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…laced never reaches a caller that did not opt in, even on a replay; a put-back of a gone row is not_found in any batch that sends lives; expectedLife is not counted toward the op size; a page in the trash meets the trash first; a literal opt-in for the new reason; the Dart client regenerated; tests for each, and a cost scenario that fails if an op with lives reads more
…k, and a gone row's put-back is not_found in any batch that sends lives; tests for replays after trash and purge, content on a page in the trash, and every op kind pinned; the doc says when a replay carries the row and why the old reason stays
No picture: this is a server change, and no client turns it on yet.
What a player can lose today
The server identifies a row (an item, a lineup, a page, the strategy itself) by its id and a revision number. Sometimes the same id gets a brand-new row:
An edit a player made to the old row is then still accepted, because "revision 1" matches the new row's revision 1. A player who comes back online with a queued edit can overwrite, move or delete something a teammate made since, without anyone being asked.
What this PR does
It adds an option that the coming cloud store client will turn on. A client that sends
sendsLives: trueonops:applyBatchputs, on each op, the creation time of the row it was edited against (expectedLife). If the row there now was created at a different time, the server refuses the op asrow_replacedand sends back the row as it is now, so the player is asked instead of the edit landing on someone else's work."Life" is the row's
createdAt. The server already sets it on every insert of the five row kinds, never changes it (bringing an item back, restoring a page, moving an item and copying all keep or create it correctly), and already sends it on every row.Old clients send nothing new and get nothing new. Every shipped desktop build and the live web build: without
sendsLives, the server does no extra lookup, checks nothing new, writes no new field, and returns exactly what it returns today. AnexpectedLifesent withoutsendsLivesis ignored.Schema: one optional field on
operationEvents(appliedLife), written only for opted-in batches. No backfill. Old rows simply lack it.What merging triggers: the Deploy Server workflow deploys
convex/to production, as everyconvex/change on main does. Nothing else changes for players until a client release turns the option on.Evidence
Live, on a preview deployment made from this branch (
confident-marten-490; never production or the shared dev deployment):maintenance:backfillAssetReferencesfrom the CLI, because purges wait for that backfill.npx convex run --identitywith the preview's deploy key. The output, trimmed:The last line is today's behaviour, and what this option prevents: the old edit lands on the new row.
Today's clients, live on the same preview: today's shipped sync, through the desktop driver build on Linux, two test accounts (jules@ and mika@test.icarusstrats.com),
shape-opacity-cloudandtag-color-cloudeach with its teammate script. All four instances endedCLEAN, with 0 failed steps.In
convex/rowLives.test.ts(18 tests):Byte for byte: a five-batch sequence is run with and without
sendsLives. Without it, neither the answers nor the receipts contain any life field. With the life fields taken out, the opted-in answers, receipts and row equal the plain ones exactly.Inside the shipped contract: one op of every kind, each outcome and its fields pinned:
revision_mismatch);ELEMENT_TYPE_PAYLOAD_KIND_MISMATCH);row_replacedwith it.Every answer is in fields and reasons shipped clients know. The replay comes back
revision_mismatchand writes no second receipt. The shipped-clients check cannot see replays, so this test is the guard for them.Refused on the earlier life: a write and a delete authored on the earlier life of an element are refused as
row_replaced, and the replacement is untouched. The same write without lives, or withexpectedLifebut nosendsLives, lands on it, as today. An op on its own life goes as before and its answer names the life.A resent op id after its row's id was reused returns the first answer's revision and life, leaves the replacement alone, and writes no second receipt.
Three creation times: a strategy, its page and the page's settings each have a different creation time. A strategy patch, a page patch and a settings patch each accept only the life of the row whose revision they check.
Put-backs: in a batch that sends lives, an add that names an expected revision or an expected life is a put-back. A put-back of an element or a lineup group that is gone is
not_foundand adds nothing; tested for both kinds with a revision, a life, and both. Without lives it adds the row again, as today.Trash first: a life mismatch on a page in the trash, or on an element or a lineup group on one, meets the trash (
PAGE_DELETED) exactly as today. A firstrow_replacedanswer therefore carries the row.Replays read the row fresh: a
row_replacedsent again comes back with the row while the row is live, and without it once the page is in the trash or purged, the receipt still there. That is how every replayed refusal works on main.A page with two settings rows fails only its own op (
INVALID_PAGE_CONTENT_COUNT), and the rest of the batch applies.The size limit: an op exactly at the limit fits with and without a life, with and without
sendsLives. One byte more does not.expectedLifeis not counted.A strategy made again under the same id: a deleted strategy uploaded again, and an abandoned move made again. An op authored on the old strategy is refused as
row_replaced, the new strategy is untouched, and without lives the op applies as today. The community replace path makes a snapshot under a new id, so it never re-creates an id.Reads, counted: a new cost scenario,
storeLivesReads, sends one op of each kind with and without lives on two strategies made alike. It fails if an op with lives reads more documents than the same op without. The life is taken from the row each apply already holds, so there are no extra reads:Cost tool (
node tool/convex_cost/run.mjs, checked against the committed budgets; only the new scenario's budget was written):soloSessionStoreread 96% of its recorded figure. That scenario sends no lives, so the 4% is run-to-run variance, as on the previous head.Contract:
convex/function_spec.jsonis current, and the Dart client is regenerated (lib/collab/generated, exactly as the generator writes it).tool/convex_opt_in_results.jsonas sent only withargs.sendsLives. The new reason is declared by its value ("literal": "row_replaced"), not by its path, so the next new reason on that path is reported until someone decides about it. The shipped-clients check gains a test for that.node tool/check_convex_shipped_clients.mjsandnode tool/check_convex_deploy.mjsreport no incompatibilities.npx tsc --noEmitandnpm run test:convex(582 tests) pass, as do the Dart client gauntlet and codegen tests, and the comments check.Rules, for the client that turns this on
expectedLifenames the row whose revision the op checks: the strategy for a page add, delete or reorder and for a strategy patch; the page, the page settings, the item or the lineup otherwise.not_found, because the row it names is not there. A delete whose row is gone stays a no-op. A patch whose row is gone staysnot_found.row_replacedanswer carries the row as it is now. A replayed one carries it only while the row is live; the client treats arow_replacedwithout the row like any refusal without one.revision_mismatch, and acts as on any stale edit. That needs both builds sharing stored ops, which no build does. Look at it again before one does.expectedLifedoes not count toward the op size limit.docs/collaborative-editing.mdgains a section, "Which row an edit means", that says the same.ci: convex contract cost analyze test
Summary by CodeRabbit