Skip to content

fix(id-events): DEVICE_OPS hardening — in-transaction writes, expiry cleanup, sync delivery, upgrade recovery (#8160) - #11283

Closed
dezren39 wants to merge 1 commit into
mainfrom
queue/20078-8160-device-ops
Closed

dezren39 wants to merge 1 commit into
mainfrom
queue/20078-8160-device-ops

Conversation

@dezren39

@dezren39 dezren39 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

#8160 — DEVICE_OPS hardening follow-ups from PR #8144 review (all four items)

All four items land here, each with tests covering the named scenario. Test evidence: cargo test -p id-events --lib ran the full pre-existing suite green (319 passed) on this implementation, and the 4 new tests below pass (323 total in the suite); a combined rerun was still queued behind the fleet build lock on the loaded laptop at ship time.

Item 3 — the device operation is now written in the ingest transaction. The op decoded from a verified group.event body is threaded through ingest_event / ingest_events_inner into settle, which writes the device_ops row in the same transaction as the decision, before the resolution reads the tables — on the stored, duplicate (late body), waiting and parked paths alike (waiting/parked only once the event is actually held, the #2916 rule the membership action already follows). A released event's op is re-derived from its stored verified body in drain, so the deciding transaction writes its row too. The old post-hoc record_device_op (its own transaction after commit) is gone: a crash or a failed second write can no longer lose a grant or a revocation.

Item 2 — rows no longer leak when held events expire or are dropped. Mirror::flush_expired removes the expiring events' device_ops rows in the same transaction as their waiting rows; a released event that is then refused or forks also drops its row in settle. Rows for stored events and for held events that are released are kept.

Item 1 — range sync delivers device operations. The sender already carried the stored body; the receiver's batch path (ingest_events_with_bodies) stored it but never folded it. It now decodes each body's device operation in its pre-pass — a body that claims to be a device operation and does not decode refuses its event in place, exactly as the production path refuses it — and the batch transaction records the row (item 3's mechanism), so a fresh peer's default view matches a directly-ingesting peer's.

Item 4 — recovery for upgraded stores. New EventStore::recover_device_ops: scans stored events, rebuilds any missing device_ops row from the verified body the store holds, and returns a DeviceOpsRecovery report — events whose headers commit to a body the store does not hold (or whose held body no longer decodes) are named unrecoverable instead of being passed over silently. It runs on every open (idempotent; a complete store scans clean), so an upgraded store's pre-change grants and revocations fold again without waiting for re-delivery.

Tests (new): waiting-path row written + removed on expiry; row kept and grant applied on release; range-sync batch records the op + claimed-but-bad device body refused in place; recovery rebuilds a deleted row and reports a header-only event unrecoverable.

Queue: task 20078, lane code-d.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…cleanup, sync delivery, upgrade recovery (#8160) (task 20078)
@dezren39
dezren39 requested a review from a team as a code owner November 17, 2026 12:27
@coderabbitai

coderabbitai Bot commented Nov 17, 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 17 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: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17baced1-1d9f-4ab6-8d86-10514ac28c46
Commits

Reviewing files that changed from the base of the PR and between fe8fb4a and c7e98fe.

Files selected for processing: 3

  • pkgs/id/crates/id-events/src/event_store/ingest.rs
  • pkgs/id/crates/id-events/src/event_store/mod.rs
  • pkgs/id/crates/id-events/src/event_store/waiting_rows.rs
  • 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

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T12:27:59.730653Z
We couldn’t complete this review. Comment @codex review to try again.
c7e98fe PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39

Copy link
Copy Markdown
Member Author

Follow-up filed as #11299: the startup recovery currently materializes all stored events, waiting rows, and recovered operations in vectors, so peak memory grows with the full persistent history. This is a separate bounded-memory acceptance requirement; #11299 links this PR and tracks a streaming/batched recovery shape. Please cross-reference it from the PR/issue as appropriate.

@dezren39

Copy link
Copy Markdown
Member Author

Closing as duplicate of #11265 (merged as 4fdbd89, with follow-ups d57a650 / 6a8ea29 / 3a9d1a6 / b5691b9 already on main).

Per queue protocol, diffed this branch (queue/20078-8160-device-ops @ c7e98fe) against the canonical merged work by reading both implementations. All four #8160 items are already landed and tested on main:

  • item 1 range-sync delivery: test_range_sync_ingests_device_operation_body_on_receiver
  • item 2 expiry cleanup: waiting_rows::drop_held removes the DEVICE_OPS row with the waiting row in the same txn; test_expiring_a_held_event_removes_its_device_operation_row
  • item 3 ingest atomicity: store_device_op writes inside the ingest transaction for stored/duplicate/waiting/park paths; test_a_device_operation_body_on_a_duplicate_attaches_in_the_same_transaction
  • item 4 upgrade recovery: recover_device_ops on open from retained verified bodies, warning when incomplete; test_open_recovers_device_operation_from_a_retained_verified_body, test_open_recovers_device_operation_for_a_held_event

The only differences are API shape (this branch exposes a public DeviceOpsRecovery report; main reports via warning + boolean) and test naming. Salvage note with the full comparison is on #11265; nothing unique required porting. Leaving the branch on the remote for reference.

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