Skip to content

Add a bounded re-read and re-plan update for records - #536

Open
dhruv8sh wants to merge 3 commits into
feat/kv-record-contractfrom
feat/record-update-retry
Open

dhruv8sh wants to merge 3 commits into
feat/kv-record-contractfrom
feat/record-update-retry

Conversation

@dhruv8sh

Copy link
Copy Markdown
Collaborator

Summary

  • A record write that loses its Add/CAS precondition wrote nothing, and today each application hand-writes the reload-and-retry loop. Trusted Server's after-response identity write needs exactly one bounded re-read and re-plan (Retry an after-response write that loses its CAS trusted-server#1553), and review asked for it as an explicit EdgeZero operation that returns Unsupported where a store cannot do it.
  • RecordHandle::update(key, attempts, plan) reads the record, asks the caller's planner for a replacement or a reason to skip, and writes it with IfGenerationMatch on the generation read, or Add after a miss. After a definitive precondition rejection it reads and plans again, up to attempts writes, so at most one replacement lands.
  • A lost precondition proves the record exists under another generation, so a re-read that returns the rejected generation or misses ends as StaleRead instead of planning on an eventually consistent read. Errors are not retried, MutationUncertain is never replayed, and the conflict count is reported even when the update fails. Application policy (what to re-plan, any fallback) stays with the caller.

Changes

Crate / File Change
crates/edgezero-core/src/record_store.rs New RecordHandle::update, RecordReplacement, RecordUpdateOutcome (Conflict, Skipped, StaleRead, Written) and RecordUpdate { conflicts, result }. Composed from lookup and insert, so a provider without record operations reports KvError::Unsupported. 13 unit tests over a scripted provider.
docs/guide/kv-records.md "Re-plan after a lost precondition" section with an example and the stale-read, error and Unsupported rules.
CHANGELOG.md Unreleased entry.

Closes

Closes #535

Stacked on #510 (feat/kv-record-contract). Parent: #468.

Test plan

  • cargo test --workspace --all-targets (Rust 1.98.1)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM builds: no adapter or target-specific code changed
  • examples/app-demo workspace: not affected
  • Docs build: cd docs && npm run lint && npm run format && npm run build
  • Manual testing via edgezero serve --adapter axum: no runtime wiring changed
  • Other: tests cover a first-attempt write, Add after a miss, a conflict then a successful re-plan, giving up at the attempt bound (2 and 1), a planner skip, stale re-reads (rejected generation, miss after lost CAS, miss after lost Add), a failed re-read keeping the conflict count, a store error and a MutationUncertain write not retried, and Unsupported from a provider without record operations
  • Other: mutation checks. Removing the stale-read stop fails 3 tests; an off-by-one in the attempt bound fails 2

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • Route params use {id} syntax (not :id) (no routes changed)
  • Types imported from edgezero_core (not http crate)
  • Store wiring goes through KvRegistry / ConfigRegistry / SecretRegistry (no wiring changed)
  • New code has tests
  • No secrets or credentials committed

RecordHandle::update reads a record, plans its replacement and writes it with IfGenerationMatch, or Add after a miss. After a lost precondition it reads and plans again up to the given attempts, stops on a stale re-read, never replays an uncertain mutation, and reports the conflict count. Providers without record operations report Unsupported.

Closes #535

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
@dhruv8sh dhruv8sh self-assigned this Nov 25, 2026
dhruv8sh added a commit to IABTechLab/trusted-server that referenced this pull request Nov 25, 2026
EcKvStore gains update, which RecordEcKvStore implements with EdgeZero's RecordHandle::update (IABTechLab/edgezero#536). KvIdentityGraph keeps the permit and the identity plan and makes one bounded update; a store without it reports Unsupported and the write falls back to last-write-wins. EdgeZero is pinned to the rc/identity commit 9d02d7b3 with #536 merged.

Signed-off-by: dhruv8sh <dhruv8sh@proton.me>
@aram356 aram356 linked an issue Nov 25, 2026 that may be closed by this pull request
3 tasks
Bring in PR #510's current head. It carries main's Fastly SDK 0.13.3,
Fastly CLI 17.2.0 and fixture download retry, the stack's Fastly SDK
0.13.3 and url 2.5.9 pins, Viceroy 0.22.0 with the readiness repair and
its atomic conditional KV insert, the early-response upload drain, the
production hosting port reservation and respawn fixes, the AWS emulator
proofs' readiness markers and the batch cutoff test fix. It merges
without conflicts.
…ection

Moving the entry below the first existing Unreleased section avoids a
merge conflict with the after-response entries at the top of the
integration branch. The entry's content is unchanged.
aram356 added a commit that referenced this pull request Nov 26, 2026
Take PR #536's head 601ae8d, which adds RecordHandle::update, the
bounded re-read and re-plan update for records, on PR #510's current
head. It merges without conflicts.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed 179f0f59 and 601ae8db, and this PR is now in rc/identity (459bd27d, a plain merge of 601ae8db), which IABTechLab/trusted-server#1660 needs for RecordHandle::update.

  • 179f0f59 merges Add portable conditional KV records across providers #510's current head a296a067. It brings EdgeZero main's Fastly SDK 0.13.3 upgrade, with the Fastly CLI 17.2.0 upgrade and the fixture download retry, the stack's Fastly SDK 0.13.3 and url 2.5.9 pins, Viceroy 0.22.0 with the readiness repair and its atomic conditional KV insert, the early-response upload drain on Axum, the production hosting port reservation and respawn fixes, the AWS emulator proofs' readiness markers and the batch cutoff test fix. It merges without conflicts.
  • 601ae8db moves this PR's ### Bounded record update (#535) CHANGELOG section below the Axum JSON section, the first existing Unreleased section, so rc/identity's merge of it is plain next to the after-response entries at the top. The entry's content is unchanged.

Checked on this head: the 13 update tests passed 50 of 50 runs, the core suite passed, and the Axum and Fastly record contracts passed, Fastly under the repaired Viceroy. A concurrent-update probe, 4 concurrent updates over 400 rounds, passed 400 of 400 with the atomic insert, against 62 of 400 lost updates without it.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. RecordHandle::update is a small composition of lookup and insert. It handles the cases I would expect:

  • it bounds writes rather than reads;
  • it never replays MutationUncertain;
  • it keeps the conflict count when the update fails;
  • it reports Unsupported for a provider without record operations.

The scripted tests cover each outcome. I swapped the write after a miss from Add to Overwrite, and two tests failed (update_adds_when_the_lookup_misses, update_stops_when_the_reread_misses_after_a_lost_add). They passed again with the code restored.

I also checked whether this changes the Fastly CAS-on-a-deleted-key concern from #510. It doesn't make it worse: update issues at most one acknowledged write and adds no new precondition path.

One non-blocking point is inline: the "a lost precondition proves the record exists" premise doesn't hold on celld for expired rows that haven't been swept yet.

Checks:

  • cargo +1.98.1 test -p edgezero-core --lib record_store: 13 passed.
  • Hosted checks at 601ae8db: 26 passed. The 3 failures look like infrastructure:
    • cli tests failed on a Docker registry "Data limit exceeded" while pulling the AppConfig agent image;
    • cargo test is the aggregate job reporting that failure;
    • cache-new-revision-smoke failed its compiler-cache reuse assertion.
    • None of them touch edgezero-core.

/// again; the update stops at the first acknowledged write, so at most one
/// replacement lands.
///
/// A lost precondition proves the record exists under another generation. A

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this premise doesn't hold on every provider that supports records.

The celld README says "Lookup/list use native expiry filtering. Physical existence and Add/CAS use the physical value until sweep."

So for a celld record that has expired but not yet been swept:

  1. lookup returns None.
  2. update plans and writes Add, which is rejected because the physical row still exists.
  3. The re-read misses again, so the update ends as StaleRead. This happens on every attempt until the sweep runs.

Nothing is written either way, so this is not a data-integrity problem. But the outcome and this doc describe it as an eventually consistent read. A caller deciding between "retry soon" and "give up" would get the reason wrong.

Suggestion: soften the claim, e.g. "...proves the record exists, or on providers whose lookups hide expired rows that still block Add/CAS (celld until sweep), that an expired row remains". Make the same change to the matching paragraph in docs/guide/kv-records.md.

aram356 added a commit that referenced this pull request Nov 27, 2026
PR #524 (outbound mTLS client identities, #523) belongs to no identity
epic, and PR #522 (portable DynamoDB and celld record providers on
Fastly, #474) is still a draft. #524 is stacked on #522, so both leave
together.

This commit reverts their net changes. Its tree is rc/identity as it
was before #522 (654f546) merged with the current tips of #519, #515,
#502, #469 and #536, the branch's remaining lines. #514 and #517 are
already inside them. The rebuild merges without conflicts, and the
change touches only the 113 paths that #522 and #524 changed against
#517.

Three files differed from a plain reverse of the two PRs because of the
conflict resolutions in 7616c85 and b3a45df. Each keeps the other
lines' code and drops only #522's or #524's:

- crates/edgezero-adapter-axum/src/cli.rs keeps the capability matrix
  test's lint expectation and drops #524's client identity test.
- crates/edgezero-adapter-fastly/src/request.rs keeps the after-response
  handle and wrapper and drops #522's deferred portable KV registry.
- crates/edgezero-store-aws/src/dynamodb_records_tests.rs drops imports
  used only by #522's tests.

Merging a later tip of #522 or #524 will not restore this code, because
git treats their earlier commits as already merged. Bringing them back
needs a revert of this commit first.

This branch has not been deployed

No deployments
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.

Add a bounded read, re-plan and conditional write operation for records

3 participants