Skip to content

fix(prediction): preserve token-side factor identity - #149

Merged
proerror77 merged 5 commits into
mainfrom
codex/polymarket-side-aware-alpha-zoo
Jul 22, 2026
Merged

proerror77 merged 5 commits into
mainfrom
codex/polymarket-side-aware-alpha-zoo

Conversation

@proerror77

@proerror77 proerror77 commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Change contract

Persist AutoFactor registry identity as (dsl_hash, target, horizon, optional review_side) and export Alpha Zoo snapshots for one exact target × optional side, while quarantining side-bound rows from every legacy Research Manager input.

Out of scope

  • Candidate-replay typed root parsing or side-aware durable linkage
  • Research Manager identity-aware replay de-duplication
  • Side-bound evaluator persistence/resume CLI
  • Historical repricing-row backfill
  • Collector, ECS, full-update-tick, execution, risk, or live-trading changes

Dependency / merge order

Depends on merged PR #147. Merge this registry/Zoo layer before the candidate-replay identity layer. Legacy replay/runtime queries remain restricted to pooled artifacts (review_side IS NULL or no side-bearing artifact root) until that later layer is merged.

Focused validation

  • git diff --check
  • rustfmt --edition 2021 --check for both modified Rust examples
  • Scope at current head: 7 files, 641 insertions / 41 deletions; below the 25-file / 750-line split threshold
  • CI runs both modified Rust examples plus PostgreSQL 15 counterexamples proving:
    • pooled, Up, and Down registry rows keep three distinct IDs and upsert idempotently
    • pooled trace/evaluation evidence remains visible to the legacy manager while side-bound evidence is excluded
  • No local Cargo, database, or build execution; Linux/PostgreSQL validation is delegated to this PR CI

Counterexamples covered:

  • legacy pooled repricing preview is rejected
  • v2 missing/wrong target horizon is rejected
  • v2 envelope/factor side mismatch is rejected
  • Up Zoo excludes Down and pooled rows
  • repricing Zoo requires an explicit side
  • side-bound traces, handoffs, candidate replay artifacts, and rejected evaluations are quarantined from legacy manager inputs

Rollout / rollback impact

Migration 051 is a forward-only identity widening for the manual Research OS writer; these examples are not a rolling service deployment. It adds nullable review_side, validates up|down, creates the four-column unique index with NULLS NOT DISTINCT, then removes the old three-column conflict arbiter. Historical rows are not backfilled and remain pooled (NULL).

After migration 051, an older persist_research_trace binary deliberately fails closed because its three-column ON CONFLICT arbiter no longer exists. Do not perform a binary-only rollback. Restoring an older writer requires a coordinated database rollback that first archives side-bound factor rows and dependent evaluations/traces, then restores the old three-column index. No rollback step may silently discard or pool Up/Down identity.

Summary by CodeRabbit

  • New Features

    • Alpha Zoo exports now support explicit UP/DOWN “review-side” snapshots.
    • Side-specific factor identities are tracked distinctly from pooled results.
    • Export options and previews now validate target, horizon, version, and review-side consistency.
  • Bug Fixes

    • Prevented importing mismatched or ambiguously pooled factor previews.
    • Legacy replay and runtime planning now exclude side-bound research artifacts.
  • Documentation

    • Updated Alpha Zoo export guidance and CI/research runbook details for side-isolated workflows.
  • Tests

    • Added integration coverage to ensure side-bound data is excluded from generated planning outputs.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06448711-9c2f-4800-9588-83e6cf6f6c7a

📥 Commits

Reviewing files that changed from the base of the PR and between 5220e0a and 54fc037.

📒 Files selected for processing (1)
  • rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs
💤 Files with no reviewable changes (1)
  • rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs

📝 Walkthrough

Walkthrough

The change adds optional UP/DOWN review-side identity to factor previews and registry rows, validates side-bound exports, separates database uniqueness, filters legacy runtime consumers to pooled rows, and updates Alpha Zoo exports, tests, CI, and documentation.

Changes

Side-aware research artifact identity

Layer / File(s) Summary
Identity contracts and preview validation
rust_hft/prediction-markets/crates/ploy-research/examples/persist_research_trace.rs, rust_hft/prediction-markets/migrations/051_factor_registry_review_side.sql
CLI parsing, preview validation, factor row shapes, and the database schema now support nullable review_side values for pooled, UP, and DOWN identities.
Side-aware persistence and Alpha Zoo export
rust_hft/prediction-markets/crates/ploy-research/examples/persist_research_trace.rs
Registry upserts and Alpha Zoo snapshot grouping/export now preserve and filter by review_side, emitting the corresponding snapshot version.
Legacy runtime query filtering
rust_hft/prediction-markets/crates/ploy-research/examples/persist_research_trace.rs, rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs
Replay lookups and research planning queries now exclude side-bound rows and select only pooled identities for legacy consumers.
Validation, CI, and operational documentation
rust_hft/prediction-markets/crates/ploy-research/examples/persist_research_trace.rs, rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs, .github/workflows/ploy-ci.yml, rust_hft/prediction-markets/docs/..., rust_hft/prediction-markets/tasks/todo.md
Tests cover side-specific parsing, export filtering, distinct registry identities, and legacy exclusion; CI and operational documentation describe the updated behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant persist_research_trace
  participant factor_registry
  participant AlphaZooSnapshot
  CLI->>persist_research_trace: provide optional UP/DOWN export side
  persist_research_trace->>factor_registry: persist review_side with factor identity
  persist_research_trace->>factor_registry: fetch rows including review_side
  factor_registry-->>persist_research_trace: return pooled and side-bound rows
  persist_research_trace->>AlphaZooSnapshot: group rows by target and review_side
  AlphaZooSnapshot-->>persist_research_trace: emit versioned snapshot
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving token-side factor identity.
Description check ✅ Passed The description covers the contract, out-of-scope work, dependency order, validation, and rollout details required by the template.
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/polymarket-side-aware-alpha-zoo

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/prediction-markets/migrations/051_factor_registry_review_side.sql`:
- Line 19: Update the DROP INDEX statement in migration
051_factor_registry_review_side.sql to use IF EXISTS, matching the existing
idempotent ADD COLUMN behavior and allowing safe partial or repeated migration
runs.
🪄 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: ef819d7c-df53-4716-91e4-aa15211aad7f

📥 Commits

Reviewing files that changed from the base of the PR and between 80bc542 and abbd28f.

📒 Files selected for processing (7)
  • .github/workflows/ploy-ci.yml
  • rust_hft/prediction-markets/crates/ploy-research/examples/persist_research_trace.rs
  • rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs
  • rust_hft/prediction-markets/docs/ALPHA_FACTOR_SEARCH_CICD.md
  • rust_hft/prediction-markets/docs/runbooks/strategy-research-cicd.md
  • rust_hft/prediction-markets/migrations/051_factor_registry_review_side.sql
  • rust_hft/prediction-markets/tasks/todo.md

@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: abbd28f2cc

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

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

🧹 Nitpick comments (1)
rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs (1)

808-960: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test exercises only the top-level side predicate; nested source_factor.side is uncovered. Each filtered query added two exclusion clauses (output_json->>'side' and output_json#>>'{source_factor,side}'), but the inserted traces only set a top-level side, so a regression in the nested-path predicate would pass unnoticed. Consider adding one side-bound row whose side lives only under source_factor.side.

Minor fidelity nit: the registry review_side uses "up" (matching the migration up|down check) while the trace output_json.side uses "Up". Aligning casing with the production ReviewSide serialization keeps the fixture representative.

🤖 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/examples/research_trace_plan.rs`
around lines 808 - 960, Extend
postgres_legacy_manager_excludes_side_bound_trace_and_evaluation to insert a
side-bound trace whose output_json contains source_factor.side without a
top-level side, so nested-path filtering is exercised; update assertions to
ensure its marker is excluded from latest runs and rejected patterns. Also align
the existing trace side value casing with the production ReviewSide
serialization while preserving the registry review_side value.
🤖 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.

Nitpick comments:
In
`@rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs`:
- Around line 808-960: Extend
postgres_legacy_manager_excludes_side_bound_trace_and_evaluation to insert a
side-bound trace whose output_json contains source_factor.side without a
top-level side, so nested-path filtering is exercised; update assertions to
ensure its marker is excluded from latest runs and rejected patterns. Also align
the existing trace side value casing with the production ReviewSide
serialization while preserving the registry review_side value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69079beb-5dc3-43fe-ab0b-0c0a653aa630

📥 Commits

Reviewing files that changed from the base of the PR and between abbd28f and 5220e0a.

📒 Files selected for processing (3)
  • .github/workflows/ploy-ci.yml
  • rust_hft/prediction-markets/crates/ploy-research/examples/research_trace_plan.rs
  • rust_hft/prediction-markets/migrations/051_factor_registry_review_side.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • rust_hft/prediction-markets/migrations/051_factor_registry_review_side.sql

@proerror77
proerror77 merged commit ac7f656 into main Jul 22, 2026
31 checks passed
@proerror77
proerror77 deleted the codex/polymarket-side-aware-alpha-zoo branch July 22, 2026 00:30
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