Skip to content

feat(collector): rotate oversized Polymarket reference tapes at a fail-closed size cap - #659

Merged
proerror77 merged 3 commits into
mainfrom
codex/recorder-tape-size-cap
Aug 3, 2026
Merged

proerror77 merged 3 commits into
mainfrom
codex/recorder-tape-size-cap

Conversation

@proerror77

Copy link
Copy Markdown
Owner

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, 0 disables, nonzero values below 1 MiB fail closed in validate()): 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 = 0 reset). Byte accounting is in-memory (restored from valid_bytes on 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

Dependencies and merge order

None

Focused validation

  • 5 new tests: size-cap rotation within the same second (both tapes accepted by the uploader discover_rotated_tapes, each starting at sequence = 0), UTC-hour rotation still triggers below the cap, 0 disables 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-targets clean; git diff --check clean; agent-worktree preflight verdict=ok.

Rollout and rollback

No production change until a new polymarket-raw-ops binary is delivered via the collector cutover procedure; default 4 GiB applies on deploy, --tape-max-bytes 0 restores hour-only rotation.

Scope exception

None

…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.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@proerror77, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b9a952b9-fd3e-4eb3-bffc-224ac82bc961

📥 Commits

Reviewing files that changed from the base of the PR and between a9ed6f6 and 5f31c96.

📒 Files selected for processing (3)
  • rust_hft/tools/collector/src/bin/polymarket-raw-ops.rs
  • rust_hft/tools/collector/src/polymarket_raw.rs
  • rust_hft/tools/collector/src/polymarket_upload.rs

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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread rust_hft/tools/collector/src/polymarket_raw.rs Outdated
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
@proerror77

Copy link
Copy Markdown
Owner Author

P1 addressed in 7d48decd: cap enforcement moved into the write loop — each record is encoded and the tape rotates (same fail-closed rotate(now) path) as soon as the next record would exceed tape_max_bytes. After a mid-batch rotation the write-error rollback anchor is re-captured to the fresh segment, so a later batch failure cannot truncate across the rotation boundary. New test size_cap_rotates_mid_batch_without_losing_or_duplicating_records proves ordering and sequence = 0 on both sides. Note: a single batch needing two rotations (only possible with a misconfigured tiny cap) fails closed via the no-clobber rename instead of corrupting data.

@proerror77
proerror77 merged commit e73d940 into main Aug 3, 2026
45 checks passed
@proerror77
proerror77 deleted the codex/recorder-tape-size-cap branch August 3, 2026 12:01
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