Skip to content

fix(pm-tape): survive tick-level load without restart-looping - #582

Merged
proerror77 merged 4 commits into
mainfrom
codex/pm-tape-lag
Aug 1, 2026
Merged

fix(pm-tape): survive tick-level load without restart-looping#582
proerror77 merged 4 commits into
mainfrom
codex/pm-tape-lag

Conversation

@proerror77

@proerror77 proerror77 commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Change contract

Make polymarket-market-tape survive tick-level recording (quote_sample_ms = 0, kinds + spot_price/agg_trade/l2) without restart-looping, while keeping fail-closed lag semantics for trading runtimes.

Root cause (host-verified): 50% of cgroup CPU periods throttled under CPUQuota=30%, memory pinned at MemoryHigh=384M, the consumer lagged the 8192-message broadcast ring, and LiveFeed's fail-closed lag handling killed the process on every burst (13 restarts in ~25 min).

Changes:

  • LiveFeed gains LagPolicy: fail_closed (default, unchanged) / skip_and_continue (warn-logged gap, keeps consuming). New tests cover both policies + serde names.
  • New runtime config keys feed_broadcast_capacity (default 8192) and feed_lag_policy (default fail_closed), wired in ploy-strategy-runtime.
  • Tape config: feed_broadcast_capacity = 65536, feed_lag_policy = "skip_and_continue".
  • Tape unit: CPUQuota 30%→100%, MemoryHigh 384M→768M, MemoryMax 512M→1G (host: 7.4G total, 5.1G available).
  • Contract test pins the new keys and quota headroom.

Issue relationship

Refs #581

Out of scope

Dependencies and merge order

None. A matching resource drop-in is already live on the host as interim mitigation (0 restarts since); this PR makes it official and adds the lag-policy/capacity knobs, which take effect on the next recorder release.

Focused validation

  • cargo test -p ploy-strategy-bundles --lib — 242 passed, 0 failed (incl. 3 new lag-policy tests, with a fail-closed counterexample preserved).
  • cargo check -p ploy-strategy-runtime — clean.
  • cargo test --test workspace_runtime_retirement monday_polymarket_data_service — pass.
  • Host interim evidence: after quota bump, NRestarts=0 and nr_throttled 0.3% (was 50%); memory plateaued at ~805M under the new 1G cap.

Rollout and rollback

Scope exception

None

Refs #581

The tick-level tape config (quote_sample_ms=0, +spot_price/agg_trade/l2)
pushed the recorder past its CPU/memory quota: 50% of cgroup periods
throttled, memory pinned at MemoryHigh, consumer lagged the 8192-message
broadcast ring, and LiveFeed's fail-closed lag handling killed the
process on every burst (13 restarts in ~25 minutes).

- Add LagPolicy to LiveFeed: fail_closed (default, unchanged for trading)
  or skip_and_continue for pure recorders, where a restart loses more
  tape than a bounded, warn-logged gap.
- Add feed_broadcast_capacity / feed_lag_policy runtime config keys.
- Tape config: capacity 65536, lag policy skip_and_continue.
- Tape unit: CPUQuota 30%->100%, MemoryHigh 384M->768M, MemoryMax 512M->1G
  (host has 5.1G available).
- Contract test pins the new tape config keys and quota headroom.
@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: 6 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: 60cee513-7236-4cd4-a7d5-5e728eb406b1

📥 Commits

Reviewing files that changed from the base of the PR and between 1afe58f and 1eaf974.

📒 Files selected for processing (5)
  • deployment/aliyun/polymarket-market-tape.service
  • deployment/aliyun/polymarket-market-tape.toml
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/config.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs
  • rust_hft/prediction-markets/tests/workspace_runtime_retirement.rs
📝 Walkthrough

Walkthrough

The PR adds configurable live-feed lag handling and broadcast capacity. The runtime applies these settings to live feeds and channels. The market-tape deployment increases feed capacity and systemd resource limits. Tests verify the configuration.

Changes

Live feed configuration

Layer / File(s) Summary
Lag policy behavior
rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/live.rs, rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/mod.rs
Adds serializable LagPolicy modes. LiveFeed can skip lagged updates or terminate on lag. Tests cover defaults, deserialization, and update delivery.
Runtime configuration and wiring
rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/config.rs, rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs
Adds feed capacity and lag-policy configuration. The runtime uses the configured channel capacity and lag policy for recording and non-recording feeds.
Deployment settings and validation
deployment/aliyun/polymarket-market-tape.toml, deployment/aliyun/polymarket-market-tape.service, rust_hft/prediction-markets/tests/workspace_runtime_retirement.rs
Sets capacity to 65536, enables skip_and_continue, increases CPU and memory limits, and verifies the deployment values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • proerror77/monday#9 — Shares changes to the market-tape service, TOML configuration, live-feed handling, runtime configuration, and retirement tests.

Sequence Diagram(s)

sequenceDiagram
  participant RuntimeConfig
  participant LiveRuntime
  participant BroadcastChannel
  participant LiveFeed
  RuntimeConfig->>LiveRuntime: provide feed capacity and lag policy
  LiveRuntime->>BroadcastChannel: create channel with configured capacity
  LiveRuntime->>LiveFeed: construct with configured lag policy
  BroadcastChannel->>LiveFeed: deliver market updates
  LiveFeed->>LiveFeed: skip lagged updates or terminate
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: preventing restart loops during tick-level tape recording.
Description check ✅ Passed The description completes all template sections and provides clear behavior, rationale, validation, rollout, rollback, and scope details.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pm-tape-lag

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.

@proerror77
proerror77 enabled auto-merge (squash) August 1, 2026 16:45

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs (1)

647-660: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep trading feeds fail-closed.

Both branches apply config.feed_lag_policy() without checking the runtime role. A live trading configuration can select skip_and_continue, and LiveFeed will then evaluate after dropped market updates.

Select SkipAndContinue only for the approved recorder workflow. Reject or override it for trading feeds. Add a test that a trading configuration remains FailClosed when the config requests skip_and_continue.

🤖 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/prediction-markets/crates/ploy-strategy-runtime/src/live.rs` around
lines 647 - 660, Ensure the LiveFeed construction in the live trading path never
uses SkipAndContinue: allow that lag policy only for the approved recorder
workflow, while rejecting or overriding it for trading feeds so they remain
FailClosed. Update the relevant runtime-role/configuration handling around
LiveFeed::with_lag_policy and add a test verifying a trading configuration
requesting skip_and_continue resolves to FailClosed.
🤖 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.

Outside diff comments:
In `@rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs`:
- Around line 647-660: Ensure the LiveFeed construction in the live trading path
never uses SkipAndContinue: allow that lag policy only for the approved recorder
workflow, while rejecting or overriding it for trading feeds so they remain
FailClosed. Update the relevant runtime-role/configuration handling around
LiveFeed::with_lag_policy and add a test verifying a trading configuration
requesting skip_and_continue resolves to FailClosed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: baea27da-b1bf-48d0-b1a9-ad90b4899163

📥 Commits

Reviewing files that changed from the base of the PR and between 657b616 and 1afe58f.

📒 Files selected for processing (7)
  • deployment/aliyun/polymarket-market-tape.service
  • deployment/aliyun/polymarket-market-tape.toml
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/config.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/live.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-bundles/src/feed/mod.rs
  • rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs
  • rust_hft/prediction-markets/tests/workspace_runtime_retirement.rs

@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: 1afe58f475

ℹ️ 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 deployment/aliyun/polymarket-market-tape.service Outdated
Comment thread rust_hft/prediction-markets/crates/ploy-strategy-runtime/src/live.rs Outdated
Comment thread deployment/aliyun/polymarket-market-tape.toml
Comment thread deployment/aliyun/polymarket-market-tape.toml Outdated
Sonic Shih added 2 commits August 2, 2026 01:30
Address review on #582:

- Refuse feed_lag_policy = skip_and_continue unless the config is a pure
  noop dry-run recorder (feed_lag_policy_allowed); trading runtimes stay
  fail-closed by construction, with counterexample tests.
- Reject feed_broadcast_capacity = 0 at startup via
  validated_feed_broadcast_capacity instead of panicking in tokio.
- Bound the ring's worst-case byte footprint: capacity 32768 (4x, not
  8x) plus MemoryHigh=1G / MemoryMax=1536M. Ring memory is backlog-only;
  worst case ~200-640MB on top of the ~770M observed working set stays
  under the cap.
@proerror77
proerror77 merged commit 7adcbe8 into main Aug 1, 2026
43 checks passed
@proerror77
proerror77 deleted the codex/pm-tape-lag branch August 1, 2026 17:44
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