Skip to content

fix(id/world): track retained admin-history bytes incrementally (#4633) - #4747

Merged
dezren39 merged 1 commit into
mainfrom
queue/6562-4633-admin-history-bytes
Nov 3, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/6562-4633-admin-history-bytes

Conversation

@dezren39

@dezren39 dezren39 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #4633. Queue task 6562.

What

record_admin_history called admin_history_bytes in its trim-loop condition on every accepted event, re-serializing the entire retained admin history each time — retained-history-sized synchronous work inside the serialized world actor (code introduced by PR #3998, now merged to main).

This change caches each retained event's encoded size once and maintains the byte total incrementally:

  • New AdminHistoryByteLedger in pkgs/id/src/world/core.rs: one cached size entry per retained event, a running serializable total, and a count of unserializable events.
  • record_admin_history tracks the new event's encoded size once, then trims against ledger.effective_bytes() — amortized O(1) in retained-history size per event.
  • Serialization failure is deliberate: an unserializable event counts as usize::MAX bytes, exactly as the previous rescan helper treated it, so it forces the retained history to trim rather than silently occupying unaccounted space.
  • restore_admin_history keeps its one-shot over-budget checkpoint rejection scan (acceptable per id(world): admin_history_bytes re-serializes the entire retained admin history on every accepted event (PR #3998) — track retained bytes incrementally #4633) and rebuilds the ledger from the restored events.
  • Event-count and byte-cap trim behavior and admin_history_complete semantics are unchanged.

Tests

  • cargo test --manifest-path pkgs/id/Cargo.toml world on the laptop: 479 passed, 0 failed.
  • New regression tests: admin_history_byte_ledger_counts_unserializable_as_max_until_trimmed, admin_history_byte_ledger_stays_in_sync_through_count_trim, admin_history_byte_cap_trims_even_a_single_oversized_event, admin_history_byte_ledger_stays_in_sync_through_restore — all pass.

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

record_admin_history re-serialized every retained admin-history event on every accepted event (and after each trim pop). Cache each event's encoded size once in AdminHistoryByteLedger and maintain the running total on push/pop, so recording is amortized O(1) in retained history size. Unserializable events count as usize::MAX, matching the legacy rescan semantics, so they force a trim instead of occupying unaccounted space. Restore keeps its one-shot over-budget scan and rebuilds the ledger. Regression tests cover the unserializable case, count-trim sync, byte-cap trim of a single oversized event, and restore sync.
@dezren39
dezren39 requested a review from a team as a code owner November 3, 2026 03:08
@coderabbitai

coderabbitai Bot commented Nov 3, 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 43 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: fe6a38d4-b84a-441d-9180-eec89ed2b16c
Commits

Reviewing files that changed from the base of the PR and between d05c22e and e9eae6c.

Files selected for processing: 3
  • pkgs/id/src/world/core.rs
  • pkgs/id/src/world/mod.rs
  • pkgs/id/src/world/tests.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T03:10:22.056905Z e9eae6c 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.

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.

id(world): admin_history_bytes re-serializes the entire retained admin history on every accepted event (PR #3998) — track retained bytes incrementally

1 participant