Skip to content

The cloud store's sender uses the server's window: a late unchecked edit is refused and sent again checked - #729

Merged
SunkenInTime merged 2 commits into
mainfrom
t3/sender-live-basis
Nov 24, 2026
Merged

SunkenInTime merged 2 commits into
mainfrom
t3/sender-live-basis

Conversation

@SunkenInTime

@SunkenInTime SunkenInTime commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

The #714 reproduction, run with the new sender (Linux driver builds, two test accounts, a preview deployment; the owner's network cut both ways by an nftables rule on its own systemd scope, the teammate online):

owner     16:36:45.7  answer to a warm-up edit: server time 1795469805693 held for session 2
harness   16:36:54.2  cut: nothing leaves or reaches the owner
owner     16:36:54.4  delete o1 committed
owner     16:36:56.6  sending attempt 3: unchecked <delete> on basis 1795469805693
teammate  16:36:56.7  move o1 committed, whole row over revision 1
teammate  16:36:57.2  attempt 1: applied at revision 2
harness   16:37:57.7  restored
owner     16:37:57.4  attempt 3: no answer (timeout)
server    16:37:58.336 ops:applyBatch ERROR UNCHECKED_OUTSIDE_WINDOW "The batch arrived too long after its live basis"
owner     16:38:27.9  sending attempt 4 in session 3: every op checked
owner     16:38:27.9  attempt 4: <delete> rejected (revision_mismatch)
owner     16:38:28.1  needs you: <delete>, RejectedByServer(revision_mismatch)
owner               takes the cloud's version, then AllSaved
teammate            expectItem o1: there, with its move; both stores equal to the server, as left and after reopening

The server line is from the preview's own function log, captured for the run. Before this, the same sequence on today's sync deleted the teammate's item 71 s after it was made (#714). Now the late call is refused before the server looks at the strategy, the checked resend sees the teammate's move, and the owner is asked.

Why

The first send of a field edit or a delete goes unchecked, so people editing together converge on the last arrival. The transport can deliver such a call long after it was made. The server refuses an unchecked batch that arrives more than 30 s after a server time the caller attaches (#715). The queue decides which ops may go unchecked and on which basis (#727), and the adapter can carry it (#723). This PR connects the sender to both, so the store's queue is fixed before it carries anyone's edits. Today's shipped sync is not patched (Dara's decision on #714).

What changes in the sender

  • A monotonic clock. The sender owns a Stopwatch (tests inject their own) and hands the claim a function that reads it. The queue calls it when the claim runs, inside the store's turn, so a claim held up behind an earlier write judges the basis's age as of that moment. The package owns no clock, and the wall clock plays no part in the decision.
  • The call opts in and carries the batch's basis. Every call asks for the server's time. The basis is the one the queue put on the claimed batch: the oldest among its unchecked ops, or none.
  • The answer's server time goes back to the queue, written in the same write as the answers (ServerTimeHeld), with the monotonic reading when the answer arrived and the session the call was sent in.
  • A late refusal is sent again checked. UNCHECKED_OUTSIDE_WINDOW becomes BatchRefused(uncheckedTooLate). The queue keeps the attempt on record, so the ops go out checked under the same op ids, with no retry wait. It also drops the server time it held, and the basis of every waiting op written on a server time no newer than the refused batch's. An edit made while the refused call was in flight goes checked, instead of being refused a second time.
  • UncheckedWithoutBasis. If the server refuses a batch for lateness when that batch had unchecked ops and no basis, the sender reports it, and the driver prints a problem line, so the run fails. The queue never builds such a batch; this is the alarm if it ever does.
  • The driver's log says the form of every send ("unchecked on basis N", or "every op checked") and every server time held.

Known differences from today

  • Two people who both start on the same item after 20 s of quiet are not merged: they race in checked form, and one of them is asked. Today they converge silently. Measured live below. The fix would be a call per open to fetch a fresh server time, and it was decided not to build it.
  • Web is not covered. The store's sender runs only in desktop driver builds (--cloud-store send). The web build doesn't send from the store.

Live proofs

Preview deployment agile-gazelle-877, made from main for these runs and deleted after them; never production or the shared dev deployment. Test accounts jules@ and mika@test.icarusstrats.com. On Linux the cut-network runs use tool/drive/linux-cloud-store-late.sh, new here: it cuts one instance's traffic both ways and leaves the companion online. The Windows PC took no network rules; it ran delivery and the two-person scenarios.

Scenario Platform Result
1. #714 reproduction (cloud-store-late-owner + -teammate) Linux clean. See the opening log: late call refused by the server, checked resend rejected, owner asked; teammate's move intact
2. A first send delayed past the window, no teammate (cloud-store-late-alone) Linux clean. Server log: the late unchecked call refused (UNCHECKED_OUTSIDE_WINDOW), 90 s after its basis. The checked resend applied 63 ms later, and the sender's next attempt was answered "already applied". Landed once, checked
A same-field edit right after a late refusal (cloud-store-late-refused) Linux clean. The network came back while the sender still waited, so the sender's own call came back refused as late (server log 16:32:20.4). An edit to the same field made then, with sending held, did not fold into the refused op. The resend and the new edit both went out checked and applied
A checked retry after a restart (cloud-store-late-restart-before, then -after on its store) Linux clean. An unchecked edit in flight into the cut network when the app was killed went out checked after the restart and applied; equal to the server in both passes
Plain delivery (cloud-store-send) Linux and Windows clean; equal as left and after reopening
3. Two people, different fields at once (cloud-store-fields-*) Linux and Windows clean. Both edits unchecked, both applied, nobody asked
4. Two people, same item at once, both active (cloud-store-race-*) Linux and Windows clean. Both unchecked, both applied, converged on the last arrival, nobody asked
4, after 30 s of quiet (cloud-store-race-quiet-*) Linux and Windows clean. Both checked. On both platforms the owner's applied and the teammate's was rejected (field_conflict), so the teammate was asked and took the cloud's version

After the review round, on preview reminiscent-lyrebird-247 with this head's code (Linux):

  • The restart pair, run as documented. cloud-store-late-restart-before.json through the wrapper:
    19:13:52.972 cut: nothing leaves or reaches the main instance (icarus-cloud-store-late-493677)
    19:13:58.516 the run ended where its script kills the app, with no step failed
    19:13:58.562 cleanup done; tables left: 0
    before exit 0
    
    Attempt 3 was sent unchecked into the cut network and the app was killed. cloud-store-late-restart-after.json with --hive-store sent it as attempt 4 in session 4, "every op checked", and it applied (SUMMARY steps=7 failed=0 ... CLEAN, exit 0).
  • cloud-store-late-refused.json: clean on the second run. Attempt 3 was sent unchecked at 19:15:30, refused as late at 19:15:57, and resent checked as attempt 4, which applied. The held edit went out checked as attempt 5 and applied. The first run failed. Its original was never delivered after the restore, so the sender's call timed out and the checked retry landed with no refusal to see. That outcome is correct, but the scenario did not happen. The cut original only qualifies for a refusal through TCP's seventh retransmit, about 25 s after the send, and that lands close to the call's timeout. The script's timing is unchanged in this PR.

Tests

New in cloud_sender_test.dart (group "the server's window for unchecked sends"):

  • the first edit after a quiet start goes checked; the next, within 20 s of an answer, goes unchecked on that answer's server time. Fails without the opt-in.
  • a batch refused as late is sent again at once, checked, under the same op id, and a same-field edit right after it goes checked too. The same-field edit is made while the resend is at the server, before its answer brings a new time. Fails without the opt-in, and fails with the late refusal recorded as a give-back.
  • a server time answered after the connection changed is not held, so the next edit goes checked. An end-to-end check. It does not fail with the call's session swapped for the current one, because the sender writes the answer in the same step as the call, before any later step can open a session. The rule itself (a time held only by the session that asked for it) is tested in the package (The queue sends unchecked only on a recent server time held when the edit was written, and resends checked after a late refusal #727).
  • a send in flight at a restart is retried checked. Fails without the opt-in.
  • a claim held up behind an earlier write judges its basis when it runs: held 21 s past a fresh answer, the edit goes checked. Fails when the sender takes its clock reading before the store's turn.
  • the answer's server time is held as of the moment the answer arrived. Fails when the answer's reading is delayed by 250 ms.
  • an unchecked call lost by the transport but landed inside the window is answered "applied when first received" to its checked retry, and lands once.
  • an unchecked call the transport delivers past the cutoff, before its checked retry, ... and ..., after its checked retry, ...: the server refuses the late original, and the edit lands once, through the retry.
  • no session opens while a call is awaited, so the session the call was sent in is the one bound when its answer arrives. Reading the bound session when the answer arrives cannot fail a test, because the two cannot differ: the sender's loop opens no session while a call is awaited. This test asserts exactly that, with a connection change made while the call is out.

New in the package (cloud_live_basis_test.dart):

  • the reading a claim judges its basis by is the one it takes when it runs, not one handed to it earlier. Fails when the event captures its reading when it is built.
  • a late refusal drops the basis of every op written on one no newer than the refused batch's, so an edit made while the refused one was in flight goes checked: one refusal, not two. Sol's two-edit sequence. Fails without the basis drop.

The test world's fake server now enforces the window with its own clock, judges what is unchecked from the wire form by its own rule, answers with its time when asked, and lets a test make the device sleep (time passes, the monotonic clock doesn't).

The full app suite passes (4,312, 28 skipped), and so does the app's sender model. The comments check passes, and there are no analyzer errors or warnings. The infos left are in older lines.

Cost

tool/convex_cost: every store scenario now opts in and sends the way the queue does. A field merge goes unchecked on a server time held from the last 20 s, otherwise checked with its fields' base.

Scenario Calls Read Arguments sent
soloSessionStore 105 (unchanged) 948.6 KB (+4%) 50.9 KB (+5%)
twoPeopleStore 45 (unchanged) 435.3 KB (+10%) 20.8 KB (+5%)
storeSoloSessionRetire 52 (unchanged) 300.2 KB (unchanged) 50.3 KB (+5%)
storeLiveBasis (new) 12 46.0 KB 11.8 KB
  • Why the existing scenarios grew. The extra reads are the checked sends after pauses, which compare their base. The extra argument bytes are the opt-in and the basis. Writes and call counts are unchanged.
  • storeLiveBasis: one checked move after a quiet start, nine unchecked ones, and one call held past the window. That call is refused before the strategy is read, then resent checked. That is 11 edits in 12 calls; the extra call is the refusal.
  • Server time is held per client, inside one scenario. Each scenario's held time is its own, so no scenario starts with one left by another.
  • What the scenarios cannot see. They measure what the server charges for a modelled sequence of requests. A change in how many calls the Dart sender makes is invisible to them; the call-count tests in cloud_sender_test.dart guard that. The tool's README says so.
  • Expected failures. The tool now lets a scenario name the failures it causes on purpose (expectedFailures), and any other count still fails it. Budgets rerun with --update for the four store scenarios; the full run passes.

Driver

  • New steps:
    • storeDelete: deletes an item through the store, and the queue picks the form;
    • storeSetField: a field merge of one data field;
    • waitStoreRefusedLate.
  • linux.dart run --main-scope UNIT starts the main instance in its own systemd scope.
  • tool/drive/linux-cloud-store-late.sh: the harness that cuts the main instance off both ways. A script whose last step is killNow ends on purpose before restore; the wrapper exits 0 when the log shows the kill and no step failed. The driver now saves its log before a killNow exits, so the kill line is in it.
  • New scripts:
    • cloud-store-late-owner / -teammate, -alone, -refused, -restart-before / -after;
    • cloud-store-fields-*, cloud-store-race-*, cloud-store-race-quiet-*.

ci: analyze test cost library

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c4bb7499-6be3-4f1e-9f5f-0b85942c5e99
Commits

Reviewing files that changed from the base of the PR and between 9d955e0 and e745177.

Files selected for processing: 31

  • lib/dev/drive/drive.dart
  • lib/dev/drive/drive_cloud_store.dart
  • lib/library_store/cloud_sender.dart
  • lib/library_store/sender_store.dart
  • packages/icarus_library/lib/src/cloud/events.dart
  • packages/icarus_library/lib/src/cloud/pending.dart
  • packages/icarus_library/lib/src/cloud/queue.dart
  • packages/icarus_library/test/cloud_live_basis_test.dart
  • packages/icarus_library/test/cloud_model_test.dart
  • packages/icarus_library/test/cloud_support.dart
  • test/library_store/cloud_sender_test.dart
  • test/library_store/sender_world.dart
  • tool/convex_cost/README.md
  • tool/convex_cost/budgets.json
  • tool/convex_cost/lib/scenarios.mjs
  • tool/convex_cost/lib/sessions.mjs
  • tool/drive/README.md
  • tool/drive/linux-cloud-store-late.sh
  • tool/drive/linux.dart
  • tool/drive/scripts/cloud-store-fields-owner.json
  • tool/drive/scripts/cloud-store-fields-teammate.json
  • tool/drive/scripts/cloud-store-late-alone.json
  • tool/drive/scripts/cloud-store-late-owner.json
  • tool/drive/scripts/cloud-store-late-refused.json
  • tool/drive/scripts/cloud-store-late-restart-after.json
  • tool/drive/scripts/cloud-store-late-restart-before.json
  • tool/drive/scripts/cloud-store-late-teammate.json
  • tool/drive/scripts/cloud-store-race-owner.json
  • tool/drive/scripts/cloud-store-race-quiet-owner.json
  • tool/drive/scripts/cloud-store-race-quiet-teammate.json
  • tool/drive/scripts/cloud-store-race-teammate.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…: its monotonic clock at claim, the opt-in and the batch's basis on the call, the answer's server time written with the session it was sent in, and a late refusal sent again checked
…fusal drops every basis no newer than the refused one, the late wrapper knows a run that ends in killNow and the driver saves its log before the kill, checked-in probes for a delayed claim, the answer's reading and late deliveries, cost scenarios hold server time per client
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