Skip to content

feat(research): publish prediction MCTS checkpoint artifact - #204

Merged
proerror77 merged 2 commits into
mainfrom
codex/prediction-mcts-artifact-202
Jul 22, 2026
Merged

feat(research): publish prediction MCTS checkpoint artifact#204
proerror77 merged 2 commits into
mainfrom
codex/prediction-mcts-artifact-202

Conversation

@proerror77

@proerror77 proerror77 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Closes #202\n\n## Change contract\n\nPublish a versioned, read-only prediction-MCTS checkpoint artifact beside the official durable runner state. It exposes governed mission identity, checkpoint candidate lineage, training-only settlement observations, selection, and terminal phase without changing MCTS selection, reward, or checkpoint state.\n\n## Out of scope\n\nFormula Alpha Search migration (#203), collectors, snapshots, evaluator metrics, cloud result publication, Paper/Live, OMS, and RiskGate.\n\n## Dependency / merge order\n\nDepends on merged #187. This PR is independent of #203. #189 follows #202, #203, and parity evidence.\n\n## Focused validation\n\n- cargo test -p ploy-research prediction_mcts --no-default-features\n- cargo test -p ploy-research checked_in_btc_and_sol_templates_pin_current_brief_and_rust_policy --no-default-features\n- cargo clippy -p ploy-research --no-default-features --no-deps -- -D warnings\n- cargo fmt --check\n- git diff --check\n\nIncludes counterexamples for forged checkpoint identity and projection/state byte preservation on rejection.\n\n## Rollout / rollback impact\n\nAdditive artifact only. Rollback uses the prior image and stops publishing the new file; no collector, deployment, execution, or checkpoint-schema migration occurs.

Summary by CodeRabbit

  • New Features

    • Added durable, read-only research artifacts for prediction search checkpoints and runs.
    • Artifacts now include stable checkpoint details, search progress, candidate associations, and derived phase information.
    • Artifacts are generated during checkpointing and remain consistent when resuming a run.
  • Bug Fixes

    • Invalid or inconsistent checkpoint identities are rejected without overwriting the last valid artifact.
  • Configuration

    • Updated the search policy references used by the BTC and SOL five-minute research missions.

@coderabbitai

coderabbitai Bot commented Jul 22, 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: 32 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

Run ID: 711fb960-2d3b-4acc-bcb0-2025625fd985

📥 Commits

Reviewing files that changed from the base of the PR and between 1b96150 and 37b12e3.

📒 Files selected for processing (4)
  • rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json
  • rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json
  • rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs
📝 Walkthrough

Walkthrough

The PR adds validated, serializable read-only artifacts for prediction-MCTS checkpoints and run state, persists them during checkpointing, adds stability and identity validation tests, and updates policy snapshot hashes in two mission templates.

Changes

Prediction-MCTS artifacts

Layer / File(s) Summary
Checkpoint artifact projection
rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts.rs
Adds serializable checkpoint and node artifact types plus conversion of validated checkpoint data into the read-only representation.
Run artifact validation and persistence
rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs
Adds run artifact generation, identity and consistency checks, atomic artifact persistence, and tests covering resume stability and mismatched checkpoint identities.

Mission policy snapshot references

Layer / File(s) Summary
Mission snapshot pin updates
rust_hft/prediction-markets/config/research_missions/polymarket-*-5m.example.json
Updates the search_policy_snapshot_id values for the Bitcoin and Solana mission examples.

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

Sequence Diagram(s)

sequenceDiagram
  participant PredictionMctsRunState
  participant PredictionMctsCheckpoint
  participant ArtifactFile
  PredictionMctsRunState->>PredictionMctsCheckpoint: validate checkpoint identity
  PredictionMctsRunState->>PredictionMctsRunState: validate candidates and training records
  PredictionMctsRunState->>ArtifactFile: atomically write prediction-mcts-artifact.json
  PredictionMctsRunState->>ArtifactFile: preserve existing artifact on validation failure
Loading

Possibly related issues

  • proerror77/monday issue 202 — Directly covers publishing a versioned read-only prediction-MCTS checkpoint artifact.
  • proerror77/monday issue 188 — Connects read-only MCTS checkpoint and run projections with Alpha Search artifact derivation.
  • proerror77/monday issue 198 — Covers durable prediction-MCTS checkpoint artifact serialization and persistence.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: publishing a prediction MCTS checkpoint artifact.
Description check ✅ Passed The description covers the required contract, out-of-scope work, dependencies, validation, and rollout/rollback, with only a minor missing scope-exception line.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/prediction-mcts-artifact-202

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: 1b961502bd

ℹ️ 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".

})
.collect::<Result<Vec<_>, _>>()?;
for candidate in [&self.pending, &self.selected].into_iter().flatten() {
if candidate.identity != identity {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind the selected candidate to the training records

If the durable state is corrupted or tampered with so that selected retains the mission identity but contains an unobserved candidate ID or blend, this identity-only check accepts it and the new artifact publishes it as the selected result; a subsequent resume also skips recomputing selection and can evaluate that forged candidate on held-out data. Require selected to exactly match a candidate in the validated training records (and similarly cross-check pending against the checkpoint), with a same-identity counterexample test.

AGENTS.md reference: AGENTS.md:L93-L96

Useful? React with 👍 / 👎.

Comment on lines +164 to +165
} else if self.checkpoint.is_some() {
"training_ready"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Publish deadline exhaustion as a terminal phase

When the run deadline reaches zero before all candidates are trained, run_or_resume_prediction_mcts returns BudgetExhausted without updating state, but this projection continues to emit training_ready. Because the stored deadline is immutable, every resume immediately returns exhausted again, leaving the published artifact permanently describing an impossible resumable phase instead of the terminal outcome. Persist or derive a budget-exhausted phase before returning.

Useful? React with 👍 / 👎.

let artifact = state.read_only_artifact()?;
atomic_write_json(path, state)?;
atomic_write_json(
&path.with_file_name("prediction-mcts-artifact.json"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Publish evidence under immutable names

Every checkpoint replaces the same prediction-mcts-artifact.json, even though its payload contains candidate, training-evaluation, and policy evidence. This module's AGENTS.md requires following the root CLAUDE.md, whose engineering rule at line 34 requires that such evidence be content-addressed or append-only; the mutable file lets later checkpoints and resumes erase prior bytes—especially paused-state evidence—and provides no digest establishing which projection was reviewed. Publish content-addressed or append-only generations, with a separate mutable latest pointer if needed.

AGENTS.md reference: rust_hft/prediction-markets/AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

Comment on lines +133 to +134
|| record.evaluation.held_out_settlement.is_some()
|| record.evaluation.execution.is_some()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve valid auxiliary evaluation evidence

A PredictionMctsEvaluation explicitly permits held-out settlement and execution evidence to be returned for analysis while only training settlement affects reward, and the previous runner durably stored such responses. This new projection instead rejects either optional field: a compliant evaluator returning one now reaches engine.observe, then fails at checkpointing before the updated state is saved, so every resume repeats the same pending evaluation; existing version-1 states containing the fields also become unreadable. Omit the auxiliary fields from the training-only projection without rejecting the valid underlying evaluation.

Useful? React with 👍 / 👎.

@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/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs (1)

120-150: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rejection branches for training/candidate identity mismatch are untested.

read_only_artifact() explicitly fails closed when a training record carries held_out_settlement/execution, or when candidate/training_settlement identities mismatch, or when pending/selected identity mismatches the mission (Lines 133-134, 145-149). Only the checkpoint-identity-forgery path is covered by a test; these equally important fail-closed branches have no direct test exercising the Err path.

🤖 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-research/src/prediction_mcts_run.rs`
around lines 120 - 150, Add direct tests for read_only_artifact() covering each
fail-closed validation branch: mismatched training candidate identity,
mismatched training settlement identity or candidate/probability hash, present
held_out_settlement or execution, and mismatched pending or selected candidate
identity. Assert each malformed artifact returns Err while retaining the
existing valid and checkpoint-identity-forgery coverage.
🤖 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/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs`:
- Around line 444-450: Update checkpoint so it does not call read_only_artifact
for full-tree validation and digest recomputation on every write. Cache each
node’s probability_blend_sha256 when the node is inserted, then have checkpoint
reuse the maintained artifact or cached digests while preserving atomic writes
of both the run state and prediction-mcts-artifact.json.

---

Nitpick comments:
In `@rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs`:
- Around line 120-150: Add direct tests for read_only_artifact() covering each
fail-closed validation branch: mismatched training candidate identity,
mismatched training settlement identity or candidate/probability hash, present
held_out_settlement or execution, and mismatched pending or selected candidate
identity. Assert each malformed artifact returns Err while retaining the
existing valid and checkpoint-identity-forgery coverage.
🪄 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

Run ID: d91efeed-26a3-4086-8182-81f7b3915985

📥 Commits

Reviewing files that changed from the base of the PR and between b66b1d8 and 1b96150.

📒 Files selected for processing (4)
  • rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json
  • rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json
  • rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs

Comment on lines +444 to +450
fn checkpoint(path: &Path, state: &PredictionMctsRunState) -> Result<(), String> {
atomic_write_json(path, state)
let artifact = state.read_only_artifact()?;
atomic_write_json(path, state)?;
atomic_write_json(
&path.with_file_name("prediction-mcts-artifact.json"),
&artifact,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm how often checkpoint() is invoked relative to MCTS iterations
rg -n 'checkpoint\(' rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs -B3 -A3

Repository: proerror77/monday

Length of output: 3081


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE='rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs'

echo '== checkpoint call sites =='
rg -n 'checkpoint\(' "$FILE" -B2 -A4

echo
echo '== read_only_artifact definitions =='
rg -n 'read_only_artifact' rust_hft/prediction-markets/crates/ploy-research/src -n -A4 -B4

echo
echo '== checkpoint-related structs/usages =='
rg -n 'PredictionMctsCheckpoint|probability_blend_sha256|sha256' rust_hft/prediction-markets/crates/ploy-research/src -n -A3 -B3

Repository: proerror77/monday

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the main control flow around the checkpoint calls.
sed -n '200,380p' rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs

echo
echo '---'
# Show the checkpoint helper itself.
sed -n '440,470p' rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts_run.rs

Repository: proerror77/monday

Length of output: 7226


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '277,385p' rust_hft/prediction-markets/crates/ploy-research/src/prediction_mcts.rs

Repository: proerror77/monday

Length of output: 5143


Avoid re-validating the full tree on every checkpoint write. checkpoint() runs after each candidate proposal and evaluation, so state.read_only_artifact() recomputes validation and every node’s probability_blend_sha256 on a hot path. That makes the cumulative cost grow quadratically with tree size; caching the digest when a node is inserted would keep writes cheap.

🤖 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-research/src/prediction_mcts_run.rs`
around lines 444 - 450, Update checkpoint so it does not call read_only_artifact
for full-tree validation and digest recomputation on every write. Cache each
node’s probability_blend_sha256 when the node is inserted, then have checkpoint
reuse the maintained artifact or cached digests while preserving atomic writes
of both the run state and prediction-mcts-artifact.json.

@proerror77
proerror77 merged commit 228ec21 into main Jul 22, 2026
26 checks passed
@proerror77
proerror77 deleted the codex/prediction-mcts-artifact-202 branch July 24, 2026 08: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.

Publish read-only prediction MCTS checkpoint artifact

1 participant