feat(collector): rotate oversized Polymarket reference tapes at a fail-closed size cap - #659
Conversation
…ize cap (#655) Tick-level recording pushed a single UTC-hour tape to 20-25 GiB, nearly deadlocking the 196 GiB spool disk during upload processing. The writer now tracks bytes written to the active tape and rotates through the exact same fail-closed path as the UTC-hour rotation (staged fsync, no-clobber rename, identity check, directory sync, sequence reset to 0) once the tape reaches tape_max_bytes. The cap defaults to 4 GiB, disables at 0, and fails closed in config validation for nonzero values below 1 MiB. Byte accounting survives crash recovery and rolls back with the existing write-error truncation path, so every rotated tape still starts at sequence 0 for the upload-side scan. Rotated names keep the microsecond timestamp format, so multiple rotations inside one second stay unique and upload-discoverable.
|
Warning Review limit reached
Next review available in: 5 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 535e39201f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The cap was checked once per write batch, so a single collection cycle's PendingUpdates replay could overshoot a tape near the 4 GiB cap by the whole cycle volume before rotating. The cap is now enforced inside the write loop: before writing each record, if appending it would exceed tape_max_bytes the writer rotates through the same fail-closed rotate() path and re-encodes the record at sequence 0 on the fresh tape. An empty tape always accepts its first record so an oversized single record cannot loop rotation. After a mid-batch rotation the write-error rollback anchor moves to the fresh segment, so a later failure can never truncate across the published rotation boundary. Refs #655
|
P1 addressed in |
Change contract
The reference-lane recorder (
polymarket-raw-ops collect-reference,polymarket_raw.rs) rotated tapes only on UTC-hour boundaries. This adds a configurable tape size cap (--tape-max-bytes, default 4 GiB,0disables, nonzero values below 1 MiB fail closed invalidate()): when the active tape exceeds the cap it rotates via the identical fail-closed path as the hour trigger (staged fsync, no-clobber rename, dev/ino identity check, directory sync,sequence = 0reset). Byte accounting is in-memory (restored fromvalid_byteson crash recovery, rolled back on the existing truncate-on-error path) — zero extra syscalls per record. Companion fix for the market-lane recorder in the sibling PR; together they bound per-tape upload transient (~1.6× tape size) so a spool disk cannot deadlock on oversized tapes.Issue relationship
Refs #655
Out of scope
new-ploy-runner,ploy-strategy-bundles/feed/recorded.rs) rotate-on-limit semantics — sibling PR (codex/market-recorder-rotate-on-cap).deployment/aliyun/polymarket-market-tape.toml: consumed bynew-ploy-runner(a different recorder); adding a key there would advertise an inert knob. The 4 GiB default applies with no deploy change.Dependencies and merge order
None
Focused validation
discover_rotated_tapes, each starting atsequence = 0), UTC-hour rotation still triggers below the cap,0disables size rotation, validation fails closed on a sub-1 MiB nonzero cap, and byte accounting survives crash recovery (counterexample: truncate-on-error rolls the counter back).cargo test -p hft-collector --locked: 285 lib passed / 0 failed;cargo clippy -p hft-collector --locked --all-targetsclean;git diff --checkclean; agent-worktree preflightverdict=ok.Rollout and rollback
No production change until a new
polymarket-raw-opsbinary is delivered via the collector cutover procedure; default 4 GiB applies on deploy,--tape-max-bytes 0restores hour-only rotation.Scope exception
None