Skip to content

fix(pm-upload): tolerate bounded per-token quote source-time jitter - #585

Merged
proerror77 merged 3 commits into
mainfrom
codex/pm-upload-quote-jitter
Aug 1, 2026
Merged

proerror77 merged 3 commits into
mainfrom
codex/pm-upload-quote-jitter

Conversation

@proerror77

@proerror77 proerror77 commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Change contract

Let upload validation accept bounded per-token quote source-time jitter (WS/REST source mixing at tick level) while still rejecting true tape corruption. Refs #584.

The first tick-level hourly segment (7.7GB) was parked in failed_segments with line 2446560: quote source time moved backwards — REST-batch quotes (ts 3.7s older) interleaved with WS quotes for the same token. The 1s sampling era masked this by construction.

  • Tolerate per-token regressions up to 30s (8x headroom over observed 3.7s), anchored at max seen ts per token; larger regressions fail with the magnitude in the error message.
  • New manifest quality counter tolerated_quote_source_regressions.
  • recorded_at file-order monotonicity, sequence gaps, and future-skew checks unchanged.

Issue relationship

Refs #584

Out of scope

  • Per-source quote identity and per-source monotonicity (needs recorder schema change).
  • Recorder-side WS-over-REST dedup preference.
  • Reprocessing the parked segment (runtime follow-up after the fixed uploader ships).

Dependencies and merge order

None.

Focused validation

  • cargo test -p hft-collector polymarket_upload:: — 63 passed, 0 failed.
  • Counterexample tests: 3s jitter accepted with counter=1 and anchor recovery; 60s regression rejected with magnitude in the error.

Rollout and rollback

  • Validator-only change in polymarket-raw-ops; deploy via the standard raw-ops release path, then clear the parked segment's failed_segments entry and re-run upload.
  • Rollback = previous raw-ops release; parked segments stay parked (no partial state).

Scope exception

None

Summary by CodeRabbit

  • Bug Fixes
    • Improved quote timestamp validation to tolerate brief, isolated timing jitter.
    • Larger timestamp regressions continue to be rejected.
    • Manifest quality metadata now records tolerated timestamp regressions.
  • Tests
    • Added coverage distinguishing acceptable one-second jitter from invalid 60-second regressions.

Refs #584

Tick-level tapes mix WS hot-path and REST poll quotes for the same
token, so per-token source times legitimately regress by a few seconds
(observed ~3.7s). The strict monotonic check rejected the first
tick-level hourly segment (7.7GB) at upload time.

- Tolerate per-token quote source-time regressions up to 30s, anchored
  at the max seen ts per token; larger regressions still fail with the
  magnitude in the error.
- Count tolerated regressions into manifest quality
  (tolerated_quote_source_regressions).
- recorded_at file-order monotonicity and sequence-gap checks unchanged.

Tests: 3s jitter accepted (counter=1, anchor advances on recovery);
60s regression rejected.
@proerror77
proerror77 enabled auto-merge (squash) August 1, 2026 17:57
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 37 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: 27a3c389-3ec2-4172-a25a-639703906083

📥 Commits

Reviewing files that changed from the base of the PR and between b23a499 and 5235db5.

📒 Files selected for processing (1)
  • rust_hft/tools/collector/src/polymarket_upload.rs
📝 Walkthrough

Walkthrough

The Polymarket uploader now accepts per-token quote source timestamp regressions up to 30 seconds. It counts tolerated regressions in manifest quality metadata and rejects larger regressions with a measured error.

Changes

Quote timestamp tolerance

Layer / File(s) Summary
Timestamp validation and quality output
rust_hft/tools/collector/src/polymarket_upload.rs
The scanner permits regressions up to 30 seconds, counts tolerated regressions, and writes the count to manifest quality metadata.
Timestamp regression tests
rust_hft/tools/collector/src/polymarket_upload.rs
Tests reject a 60-second regression and accept one-second jitter with one tolerated regression reported.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related issues

  • proerror77/monday#584: The PR implements bounded per-token timestamp jitter tolerance, quality counting, and regression tests.

Possibly related PRs

  • proerror77/monday#238: This PR extends the Polymarket quote timestamp validation and manifest quality behavior introduced there.
  • proerror77/monday#155: Both PRs modify timestamp monotonicity validation to allow bounded regressions in different validators.
  • proerror77/monday#34: This PR modifies the Polymarket uploader introduced by that PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change: bounded per-token quote source-time jitter is tolerated during Polymarket upload.
Description check ✅ Passed The description covers the required sections and explains the behavior, reason, scope, validation, rollout, and rollback plan.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pm-upload-quote-jitter

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.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
rust_hft/tools/collector/src/polymarket_upload.rs (1)

2833-2859: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the jitter test verify anchor retention.

The sequence 2s -> 1s -> 3s does not detect backward anchor movement. Both the current implementation and an incorrect implementation that stores 1s report one tolerated regression.

Add an intermediate timestamp between 1s and 2s. Assert two tolerated regressions. Add a later forward sample to verify recovery.

Proposed test adjustment
-        third["update"]["ts"] = json!("2026-07-15T01:00:03Z");
+        third["update"]["ts"] = json!("2026-07-15T01:00:01.500Z");
+        let mut fourth = first.clone();
+        fourth["sequence"] = json!(3);
+        fourth["recorded_at"] = json!("2026-07-15T01:00:05Z");
+        fourth["update"]["ts"] = json!("2026-07-15T01:00:03Z");
...
-            &[first, second, third],
+            &[first, second, third, fourth],
...
-            json!(1)
+            json!(2)

As per coding guidelines, “Safety boundaries require a targeted counterexample test, not only workspace compilation.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rust_hft/tools/collector/src/polymarket_upload.rs` around lines 2833 - 2859,
The test tolerates_bounded_quote_source_time_jitter_per_token does not detect
backward movement of the retained timestamp anchor. Add an intermediate sample
timestamped between 1s and 2s so the sequence exercises the original anchor
after the regression, update the expected tolerated_quote_source_regressions to
2, and append a later forward sample to verify recovery after the jitter.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rust_hft/tools/collector/src/polymarket_upload.rs`:
- Around line 1296-1303: Update the regression check in the quote-source
validation block to compare the full `previous - source_at` duration against
`TimeDelta::milliseconds(MAX_QUOTE_SOURCE_REGRESSION_MS)` before converting
units. Keep `num_milliseconds()` only when constructing the `bail!` error
message, preserving the existing tolerated-regression counting behavior.

---

Nitpick comments:
In `@rust_hft/tools/collector/src/polymarket_upload.rs`:
- Around line 2833-2859: The test
tolerates_bounded_quote_source_time_jitter_per_token does not detect backward
movement of the retained timestamp anchor. Add an intermediate sample
timestamped between 1s and 2s so the sequence exercises the original anchor
after the regression, update the expected tolerated_quote_source_regressions to
2, and append a later forward sample to verify recovery after the jitter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e85a3b10-63a8-4d15-ad7d-6245f971dffe

📥 Commits

Reviewing files that changed from the base of the PR and between 7adcbe8 and b23a499.

📒 Files selected for processing (1)
  • rust_hft/tools/collector/src/polymarket_upload.rs

Comment thread rust_hft/tools/collector/src/polymarket_upload.rs
num_milliseconds() truncates, so 30s+1ns passed the bound. Compare the
TimeDelta directly and keep the millisecond conversion only for the
error message.
@proerror77
proerror77 merged commit 5522d15 into main Aug 1, 2026
51 checks passed
@proerror77
proerror77 deleted the codex/pm-upload-quote-jitter branch August 1, 2026 18:26
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