Skip to content

fix(polymarket): disclose exact rescan mismatch values - #291

Merged
proerror77 merged 1 commit into
mainfrom
codex/polymarket-rescan-diagnostics-290
Jul 23, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/polymarket-rescan-diagnostics-290

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Change contract

When exact-main evidence import rejects a producer manifest field after bound-FD rescan, report the authenticated artifact file plus bounded producer and rescan JSON values without weakening validation.

A PRD is unnecessary because issue #290 specifies one small error-message-only behavior and the change was developed with a focused failing test.

Acceptance evidence

  • Focused counterexample now identifies the artifact file and field.
  • Producer and rescan values are each bounded to 512 Unicode characters plus a truncation marker.
  • Mismatch still fails closed through the existing bail! path; valid-input behavior is unchanged.
  • cargo test -p hft-collector passed.
  • cargo clippy -p hft-collector --all-targets --no-deps -- -D warnings passed.
  • Changed-file rustfmt check and git diff --check passed.
  • Matt two-axis code review: Standards PASS; Spec PASS.

Out of scope

Accepting a new manifest shape; changing quality calculations; collector deployment; data repacking; evidence, snapshot, or evaluator behavior.

Dependency / merge order

Independent diagnostic prerequisite for the next #270 cloud compile attempt. Merge this PR, publish one exact-main compiler image, then rerun #270.

Focused validation

TDD on the existing producer-rescan mismatch counterexample, bounded-value test, full hft-collector tests, strict Clippy, formatting, and two-axis code review.

Rollout / rollback impact

Error-message-only change in a fail-closed one-shot compiler. Rollback removes diagnostics but does not alter accepted data.

Closes #290

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages when rescan manifest values conflict with producer records.
    • Diagnostics now identify the affected artifact, field, and both conflicting values.
    • Long diagnostic values are safely shortened for clearer, bounded error output.
    • Updated validation coverage to verify detailed mismatch messages and truncation behavior.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

decompress_and_rescan now reports the mismatching artifact, field values, and bounded producer/rescan diagnostics. Tests validate the expanded rejection message and truncation behavior.

Changes

Rescan mismatch diagnostics

Layer / File(s) Summary
Bounded mismatch reporting and validation
rust_hft/tools/collector/src/polymarket_research_import.rs
Mismatch errors include the artifact and bounded producer/rescan values; tests verify diagnostic contents and truncation behavior.

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

Possibly related PRs

  • proerror77/monday#152: Adds related trade_completions parsing and validation in polymarket_research_import.rs.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the diagnostic mismatch-value change.
Description check ✅ Passed The description covers the required sections and includes contract, validation, scope, rollout, and merge-order details.
Linked Issues check ✅ Passed The PR meets #290 by naming the artifact and field, bounding producer/rescan values, and keeping mismatch handling fail-closed.
Out of Scope Changes check ✅ Passed The diff stays within diagnostic/error-message work and tests, with no evident unrelated feature or behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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/polymarket-rescan-diagnostics-290

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

🤖 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_research_import.rs`:
- Around line 549-564: Update bounded_rescan_value so truncated output,
including the "...<truncated>" marker, never exceeds
MAX_RESCAN_DIAGNOSTIC_CHARS: reserve the marker length when collecting the
prefix. Add an assertion that the final truncated diagnostic length equals
MAX_RESCAN_DIAGNOSTIC_CHARS, while preserving unchanged output for values within
the limit.
🪄 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: 86192d26-f8f2-4045-be89-a68ea997780f

📥 Commits

Reviewing files that changed from the base of the PR and between f5affe7 and 5c5185f.

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

Comment on lines +549 to +564
const MAX_RESCAN_DIAGNOSTIC_CHARS: usize = 512;

fn bounded_rescan_value(value: Option<&Value>) -> String {
let raw = value.map_or_else(|| "<missing>".to_owned(), Value::to_string);
let mut chars = raw.chars();
let prefix = chars
.by_ref()
.take(MAX_RESCAN_DIAGNOSTIC_CHARS)
.collect::<String>();
if chars.next().is_some() {
format!("{prefix}...<truncated>")
} else {
raw
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the truncation marker inside the 512-character limit.

The helper currently emits 512 value characters plus ...<truncated>, so truncated diagnostics exceed the stated maximum. Reserve the marker’s length from the prefix budget, and assert that the final diagnostic length equals MAX_RESCAN_DIAGNOSTIC_CHARS.

Proposed fix
 const MAX_RESCAN_DIAGNOSTIC_CHARS: usize = 512;
 
 fn bounded_rescan_value(value: Option<&Value>) -> String {
     let raw = value.map_or_else(|| "<missing>".to_owned(), Value::to_string);
+    let marker = "...<truncated>";
+    let value_limit = MAX_RESCAN_DIAGNOSTIC_CHARS.saturating_sub(marker.chars().count());
     let mut chars = raw.chars();
     let prefix = chars
         .by_ref()
-        .take(MAX_RESCAN_DIAGNOSTIC_CHARS)
+        .take(value_limit)
         .collect::<String>();
     if chars.next().is_some() {
-        format!("{prefix}...<truncated>")
+        format!("{prefix}{marker}")
     } else {
         raw
     }
 }
-            MAX_RESCAN_DIAGNOSTIC_CHARS + "...<truncated>".chars().count()
+            MAX_RESCAN_DIAGNOSTIC_CHARS

Also applies to: 1767-1775

🤖 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_research_import.rs` around lines 549
- 564, Update bounded_rescan_value so truncated output, including the
"...<truncated>" marker, never exceeds MAX_RESCAN_DIAGNOSTIC_CHARS: reserve the
marker length when collecting the prefix. Add an assertion that the final
truncated diagnostic length equals MAX_RESCAN_DIAGNOSTIC_CHARS, while preserving
unchanged output for values within the limit.

@proerror77
proerror77 merged commit 4201492 into main Jul 23, 2026
19 of 20 checks passed

@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: 5c5185fa6a

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

const MAX_RESCAN_DIAGNOSTIC_CHARS: usize = 512;

fn bounded_rescan_value(value: Option<&Value>) -> String {
let raw = value.map_or_else(|| "<missing>".to_owned(), Value::to_string);

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 Apply the limit while serializing rescan values

When a mismatch involves a large scan-derived collection such as trade_completions, Value::to_string materializes the entire JSON value before the iterator keeps 512 characters. Because rescans can derive these collections from multi-gigabyte tapes, the error path can allocate a very large temporary buffer or be OOM-killed instead of returning the intended bounded diagnostic; serialize into a size-limited writer rather than truncating only after full serialization.

Useful? React with 👍 / 👎.

bail!("manifest field {field} does not match producer rescan");
bail!(
"manifest {} field {field} does not match producer rescan: producer={}; rescan={}",
artifact.identity.file,

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 Include a unique artifact identity in mismatch errors

When validation receives multiple supported reference segments, including consecutive hours or same-hour fragments, the producer convention gives every segment the same basename such as market-updates.crypto_expiry_reference.ndjson.zst. Reporting only artifact.identity.file therefore produces the same label for every reference and does not identify which content-addressed artifact mismatched; include authenticated partition and digest information so an operator can locate the offending input.

Useful? React with 👍 / 👎.

@proerror77
proerror77 deleted the codex/polymarket-rescan-diagnostics-290 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.

Disclose the exact Polymarket rescan mismatch artifact and values

1 participant