Skip to content

Reject a change the log refuses for itself, keeping the user's file, instead of stopping sync - #1309

Merged
callumalpass merged 4 commits into
mainfrom
native-append-refusal-rejects-head
Nov 28, 2026
Merged

callumalpass merged 4 commits into
mainfrom
native-append-refusal-rejects-head

Conversation

@callumalpass

@callumalpass callumalpass commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #1952

Rebased on b6393857a (#2021). A simple disk edit shares one literal between the observed document and its identical applied result. An edit that still exceeds the sealed-entry limit retains its local bytes and raises an edit_refused notice.

Replica timeout investigation

Both cancelled jobs in Actions run 46123120379 reached the cargo test step. GitHub recorded a 20-minute timeout for each and retained no per-test log. On the original head, the refusal test failed in 0.05 seconds and printed a 1,000,010-character assertion line. Literal sharing allowed its 1,000,000-byte edit to fit. The corrected test gives the edit a 64 KiB base, checks the confirmed and local bytes through restart, and bounds the assertion output.

The fake disk also compared every known path against a list of all paths and rehashed every file on every commit. It now updates the acknowledged paths and revisions, including moves and deletions. The two 4,000-file cases retain their original sizes and assertions. The 1,360-test replica library took 358.39 seconds before the test changes and 85.00 seconds afterward on the same builder. The cancelled jobs' individual blocking tests are unknown.

Verification on the rebased branch

  • All 1,448 replica and 567 daemon tests passed, including the two-daemon Private sync, refusal and correction scenario. Replica clippy, formatting, CLI request-path E2E and the final pnpm ci:local passed.
  • The regenerated SDK pin verified against the Actions-remapped WASM, SHA-256 a27b57d4cb9c978725922af25928bb4242eb9580fa502815ea75993bbe92fe20, 4,135,951 bytes. All three runtime method-contract tests passed.
  • The rebuilt WASM passed the Node SQLite ABI smoke. Chromium SQLite passed at 1,000, 5,000 and 20,000 rows, including readback and reopen.

Earlier implementation and verification

This closes the planning-time overwrite. A change the log refuses for itself (too_large item_bytes/refs) becomes a rejection plus a per-record refused fence that keeps the user's disk bytes. Before, it either stopped sync (an Integrity stop, terminal for the daemon and re-hit on every reopen) or let a later publish overwrite the user's file.

What changed

  • c521989 Reject a change the log refuses for itself instead of stopping sync. A refused multi-item batch sends its head row alone next (one-shot probe), so the refusal is pinned on one change. A refused single-item batch rejects that change through resolve_rejected with the log's code and reason. The files the rejected change touched are fenced (replica.refused meta, in the rejection's commit): materialize, restart reconciliation and attachment reconciliation publish nothing there. The next user edit lifts the fence and is planned from the local view. A confirmed remote change to a fenced record becomes a conflict hold (mine: the disk bytes). Planning-time rejections (sealed entry over 1 MiB) and disk edits the planner refuses are fenced the same way. The daemon shows each fenced file as an edit_refused notice.
  • 258f75a Narrow refused-change fencing per review; no breaker. Only too_large item_bytes/refs reject one change; every invalid reason still stops. The breaker is gone. One predicate (refused::fences(source, problem, has_files)) decides which rejected rows keep their bytes: disk edits always; an app's write only on a store with files and only when the change itself was refused. Revocation, access and conflict rejections revert as before. On a store without files (browser, hosted) the log's refusal of an app write still stops the append and the row stays pending (refused::rejects_log_refusal). Fence targets come from the change's own ops, never the planner's link rewrites. A fence keeps the refused change's base, and is released in the capture's or acknowledgement's own commit.
  • c08c79e Hold a re-edit over a snapshot-installed version; fence resource edits. A disk edit of a fenced record whose confirmed version is no longer the refused change's base (snapshot or lost-tail rollback) becomes a conflict hold instead of being planned over. Resource disk edits (api writes) refused for item reasons now fence the resource path.
  • 60c31a2 replica: an own write ends a refused fence and reaches disk. An app's corrected write after a refused one now ends the fence for its targets and materializes, instead of becoming a conflict hold against the replica's own bytes. A hold resolution no longer leaves a stale fence.
  • dec203c replica: an app write ends only an app's refused fence. Each fence records whether its bytes came from an app submission or a disk capture (persisted; older meta reads as a disk capture). An own write ends only app fences; a user's fenced bytes still become a conflict hold (record) or stay fenced (path, resource). A hold resolution ends the fence explicitly when queued.
  • a31ce3f replica: an app's refusal or setup write never ends a user's refused fence. An app write refused at a path the user's refused disk edit already fences no longer replaces that fence, and a validated resource write (collection setup) no longer releases a resource fence at capture. Per the independent re-review of 6505de3e3 (now dec203c). Adds an_app_refusal_over_a_refused_disk_edit_keeps_the_users_fence.
  • f339ff8 sdk: repin the app runtime WASM. See below.
  • d3d9bfd merge origin/main (fix(portal): stop reading native storage on the 15-second refresh #1302, Wake hosted and escrow copies when their collection ends (idle-cap phase 1) #1307, Follow the collection's validation level at submit; let a write set its own #1308); the only conflicts were the SDK pin files. 4bf67fd sets the validation: None field Follow the collection's validation level at submit; let a write set its own #1308 added to SubmitParams in this branch's three new disk tests. 62ec124 re-pins the runtime WASM on the merged tree. 3c2041f merges main again (Report stale Private setup reviews as one clear refusal (#1293) #1306; pin files only conflicted) and 421a26d re-pins on that tree.
  • aea8116 replica: record whether a pending change was an app's submission. From an independent re-review of a31ce3f. Since Follow the collection's validation level at submit; let a write set its own #1308 a submit carries its own validation level, or the collection's, so validated_at == Error no longer marks an app's submission. An app writing at warn or off counted as the user's edit. Its refused write replaced a fence over the user's refused disk edit (the user's bytes left the hold), and its corrected write after its own refusal became a spurious conflict hold (files and resources stayed fenced). PendingRow now records submitted: device-local, never on the wire, and appended to the row's local bytes only when true. It is set by submit, app attachment uploads, collection setup and API unindexed captures, and false for disk captures, resource observations, hold resolutions and native moves. Older rows read as captured, as older fence meta does. refused_targets and release_refused take it instead of reading validated_at. Adds a_warn_level_app_refusal_over_a_refused_disk_edit_keeps_the_users_fence and a_warn_level_app_fix_after_its_refusal_reaches_disk plus codec round-trips. 28dbb77 updates the legacy-bytes codec test to use a captured row. d4c585c re-pins.
  • 4d8e2fb replica: persist an app's submission provenance only on stores with files. From the re-review of 28dbb77 (rollback). Only a store with files fences an app's refused write, so submitted is set only there (&& self.store.has_files() at the five app-row sites). Browser and hosted pending rows, and their retained copies, keep byte-identical encodings, so a hosted Worker rollback or an app pinned back to an older SDK WASM never meets an unreadable row. Adds a_submitted_row_without_files_keeps_its_earlier_bytes, restores the attachment codec test to its earlier form (its store has no files) and corrects the PendingRow::submitted doc. e318037 re-pins.

Integrity sites that still stop sync

These planning-time refusal sites are unchanged and still raise an Integrity stop:

  • native_move_restore_held
  • API hold resolution
  • resource ingest
  • disk.rs unencodable

Written notes, not code

Under Callum's stop rule these narrow crash or race cases stay as notes:

  • An apply fault can skip refused_applied until restart.
  • Stored text that doesn't hash to the disk bytes causes a resubmit.
  • Remote resource changes over a fenced resource: resources have no hold.
  • Files and unindexed entries stay fenced rather than held.
  • The mirror import submits old-mirror edits as Api/Error; this loses nothing.
  • Path-key inconsistency at the refused.rs owner lookup (cosmetic).
  • Fence metadata decode accepts exactly 7 or 8 fields.

Release channel

  • Daemon and native replica: the continuous desktop release (desktop-release.yml).
  • Browser replicas: mdbn-replica is compiled into app-runtime.wasm, so this ships in the SDK via publish-sdk-npm.yml and the weekly app repins. The pin is refreshed in this PR.
  • Hosted replicas: affected. mdbn-hosted-worker depends on mdbn-replica and runs its append path, so the too_large batch handling changes there: a refused multi-item batch now probes the head row once instead of setting max_items = 1 for good. Fencing itself doesn't reach hosted (no files; rejects_log_refusal keeps the stop for app writes). It ships with the next integrated Workers release (release-workers.yml).
  • Rollback: a native daemon downgraded past this release decodes a pending row an app submitted (the submitted flag, set only on stores with files) as corrupt, until that row is appended or resolved. Captured rows, and every hosted and browser pending row, keep their earlier bytes, so Worker rollbacks and older SDK WASM pins are unaffected.

Why the pin was built locally

The builder VM has no Node, and rcargo doesn't forward env or node_modules, so the pin can't be produced there. As in #1303, cargo xtask wasm-app ran locally at the pinned 1.94.0 toolchain with the publication workflow's path remapping (checkout -> /source, cargo home -> /cargo, local rust-src -> /rustc/4a4ef493e3a1488c6e321570238084b38948f6db, needed because the local toolchain has rust-src and CI's doesn't), then node scripts/sdk-publication.mjs pin-runtime.

New runtime pin (main a87dd0a merged, with the provenance fix): sha256 50d2489a0dc7a0e09e37a5e31188a7ff5f28e4e85c7cb8eea27cbdaea9fced56, 3840909 bytes. If main moves before merge and "Publish source-built SDK / build" fails on a byte mismatch, merge main in and re-pin.

Tests

Run with main a87dd0a merged in and the provenance fix (head e318037):

  • rcargo test -p mdbn-replica: all binaries ok, 1266 passed, 0 failed (lib: test result: ok. 1182 passed; 0 failed). Disk tests: 78 passed, including a_warn_level_app_refusal_over_a_refused_disk_edit_keeps_the_users_fence, a_warn_level_app_fix_after_its_refusal_reaches_disk and an_app_refusal_over_a_refused_disk_edit_keeps_the_users_fence; engine includes a_submitted_row_without_files_keeps_its_earlier_bytes; --test interfaces covers the codec round-trips.
  • rcargo test -p mdbn-store-file: 129 passed.
  • rcargo test -p mdbn-daemon --no-fail-fast: 555 passed, 3 failed: a_foreign_registration_is_never_opened, runtimes_follow_the_paired_account (account_runtime) and localhost_link (link), all path must be shorter than SUN_LEN from the builder's long socket path. CI's "native tests (daemon)" runs and passes them.
  • rcargo clippy -p mdbn-replica -p mdbn-daemon --all-targets -- -D warnings: clean. cargo fmt --check: clean.

@callumalpass
callumalpass force-pushed the native-append-refusal-rejects-head branch from cab7ad8 to 4c0c5dc Compare November 28, 2026 11:28
@callumalpass
callumalpass added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit b723b6c Nov 28, 2026
46 checks passed
@callumalpass
callumalpass deleted the native-append-refusal-rejects-head branch November 28, 2026 11:58
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