Skip to content

Add governed GP and immutable CEX Factor Bank core - #645

Merged
proerror77 merged 2 commits into
mainfrom
codex/agent-cex-gp-factor-bank-core-599
Aug 3, 2026
Merged

Add governed GP and immutable CEX Factor Bank core#645
proerror77 merged 2 commits into
mainfrom
codex/agent-cex-gp-factor-bank-core-599

Conversation

@proerror77

@proerror77 proerror77 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Change contract

Add the typed governed-GP policy, immutable CEX Factor Bank invariants, and auditable GP-attempt persistence required by the Agent-led research pipeline, while preserving fitness-guided behavior for generic GP.

Issue relationship

Refs #599

Out of scope

Mission-execute wiring and Factor Bank publication; MCTS subset search; continuous tuning; sealed-holdout opening; Paper, Shadow, LiveSmall, deployment, or runtime activation; new databases or services; prediction-market evaluation; RL or multi-agent runtime behavior.

Dependencies and merge order

Depends on closed Issue #598. Merge in order: this Core PR #645, Determinism PR #647, Evidence PR #648, then Mission PR #646.

Focused validation

  • cargo +1.91 test -p alpha-domain -p alpha-engine --locked — 46 domain and 80 engine tests passed; one credential-dependent LLM test ignored as designed.
  • generic_gp_remains_fitness_guided — red before the fix, green after it.
  • governed_gp_does_not_observe_evaluation_scores — passed.
  • cargo +1.91 clippy -p alpha-domain -p alpha-engine --all-targets --locked -- -D warnings — passed.
  • Exact-file Rustfmt check, git diff --check, and agent-worktree preflight — passed.
  • Standards and Spec reviews — zero blocking findings.

Rollout and rollback

Research-domain and engine code only; no runtime mutation. Roll back by reverting this PR before its dependent Mission PR.

Scope exception

None. This layer changes 3 files with 744 additions and is below the repository split threshold.

Summary by CodeRabbit

  • New Features

    • Added governed genetic programming with configurable operators, data windows, fields, and candidate namespaces.
    • Added factor screening, versioned factor-bank revisions, policy validation, and candidate admission checks.
    • Added semantic identity tracking and source-feature extraction for factors.
  • Bug Fixes

    • Preserved rejected duplicate GP candidates in mission lineage for improved traceability.
    • Strengthened validation to reject unauthorized fields and operators while maintaining existing generic behavior.

@coderabbitai

coderabbitai Bot commented Aug 3, 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 Plus

Run ID: 2d3457c7-77ad-4891-a5a7-7f825d4529bb

📥 Commits

Reviewing files that changed from the base of the PR and between be73d64 and f1c5d6c.

📒 Files selected for processing (3)
  • rust_hft/alpha-harness/domain/src/lib.rs
  • rust_hft/alpha-harness/engine/src/engines/gp.rs
  • rust_hft/alpha-harness/engine/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • rust_hft/alpha-harness/engine/src/lib.rs
  • rust_hft/alpha-harness/engine/src/engines/gp.rs
  • rust_hft/alpha-harness/domain/src/lib.rs

📝 Walkthrough

Walkthrough

The domain adds governed GP policies and factor-bank revisions. The GP engine applies policy-driven candidate generation and retention. Mission lineage persists duplicate GP candidate artifacts and records duplicate proposals.

Changes

Governed GP and Factor Bank

Layer / File(s) Summary
Policy and factor-bank contracts
rust_hft/alpha-harness/domain/src/lib.rs
The domain adds policy validation, candidate admission checks, factor-bank revisions, semantic hashing, source-feature extraction, and integrity tests.
Governed GP execution
rust_hft/alpha-harness/engine/src/engines/gp.rs
GeneticProgrammingEngine gains governed construction, policy-based candidate validation, configurable operators and windows, score-independent retention, and governed proposal behavior.
Duplicate GP candidate persistence
rust_hft/alpha-harness/engine/src/lib.rs
Duplicate Genetic Programming candidates remain queryable, with regression coverage for persisted artifacts and duplicate records.

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

Sequence Diagram(s)

sequenceDiagram
  participant GeneticProgrammingEngine
  participant CexGpPolicyV1
  participant MissionLineage
  GeneticProgrammingEngine->>CexGpPolicyV1: Validate generated candidate
  CexGpPolicyV1-->>GeneticProgrammingEngine: Return admission result
  GeneticProgrammingEngine->>MissionLineage: Submit governed candidate
  MissionLineage-->>GeneticProgrammingEngine: Record candidate or duplicate result
Loading

Possibly related issues

Possibly related PRs

  • proerror77/monday#12 — Modifies related GP proposal context and GeneticProgrammingEngine behavior.
  • proerror77/monday#67 — Extends related Factor DSL governance and candidate validation in domain/src/lib.rs.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the addition of governed GP support and immutable CEX Factor Bank functionality.
Description check ✅ Passed The description covers all required sections with clear scope, dependencies, validation, rollout, rollback, and issue relationship details.
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/agent-cex-gp-factor-bank-core-599

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: 2

🧹 Nitpick comments (5)
rust_hft/alpha-harness/domain/src/lib.rs (3)

1387-1397: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider deduplicating admitted_fields in controlled_v1.

sort() does not remove duplicates. If a caller passes the same field twice, validate() fails with "governed v1 fields, grammar, limits, or budget drifted". The failure is safe, but the message does not identify the real cause. A dedup() call makes the constructor accept normalized input.

♻️ Proposed change
         admitted_fields.sort();
+        admitted_fields.dedup();
🤖 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/alpha-harness/domain/src/lib.rs` around lines 1387 - 1397, Update
controlled_v1 to call dedup on admitted_fields immediately after sorting it, so
duplicate field names are normalized before constructing and validating the
policy.

1700-1707: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

expected_revision_id deep-clones the whole revision on every call.

The clone copies all attempts, ASTs, and evaluations to blank one String field. validate() calls this method on every invocation, and new() calls it twice in total. For a bank with many attempts the copy dominates the hashing cost.

A serializable borrowed view, or serializing to a serde_json::Value and removing revision_id, avoids the deep clone. The current behavior is correct, so treat this as an optimization.

🤖 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/alpha-harness/domain/src/lib.rs` around lines 1700 - 1707, Optimize
expected_revision_id by avoiding the deep clone of the entire revision solely to
clear revision_id. Build a borrowed serializable view or remove revision_id from
a serialized representation before calling canonical_json_hash, while preserving
the current hash input and resulting revision ID behavior.

3962-3991: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider covering the remaining validate_candidate rejection paths.

The test covers unadmitted fields and unadmitted operators. Two governed limits stay untested: the constant rejection path, and the max_ast_depth / max_ast_nodes limit. Governed v1 sets constants to empty, so any FactorTerminal::Constant must be rejected. Add both assertions to lock the governed grammar.

As per coding guidelines: "Run the focused package tests with cargo test -p alpha-domain --locked".

🤖 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/alpha-harness/domain/src/lib.rs` around lines 3962 - 3991, Extend
governed_gp_policy_rejects_unadmitted_fields_and_operators to assert that a
FactorTerminal::Constant candidate is rejected, and add a candidate exceeding
the policy’s max_ast_depth or max_ast_nodes limit that validate_candidate also
rejects. Keep the existing field and operator assertions, then run cargo test -p
alpha-domain --locked.

Source: Coding guidelines

rust_hft/alpha-harness/engine/src/lib.rs (1)

1545-1583: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add the negative case for the new persistence branch.

The test proves that a GP duplicate is persisted. It does not prove that a non-GP duplicate is still discarded. The new condition at lines 457-461 has two halves, and only one is covered.

Add a second run that uses FixedFormulaEngine with kind: EngineKind::ManualSeed and asserts lineage.candidates.len() == 1 with lineage.iterations[1].candidate_artifact_id.is_none().

As per coding guidelines: "Run the focused package tests with ... cargo test -p alpha-engine --locked".

🤖 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/alpha-harness/engine/src/lib.rs` around lines 1545 - 1583, Add a
companion test for the non-GP duplicate path using FixedFormulaEngine configured
with EngineKind::ManualSeed, then assert the resulting mission lineage contains
one candidate and iterations[1].candidate_artifact_id is None. Keep the existing
GP persistence test unchanged, and run the focused package tests with cargo test
-p alpha-engine --locked.

Source: Coding guidelines

rust_hft/alpha-harness/engine/src/engines/gp.rs (1)

239-262: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Share the evaluation test fixture instead of copying it.

This helper is identical to the evaluation helpers in rust_hft/alpha-harness/engine/src/engines/mcts.rs and rust_hft/alpha-harness/engine/src/engines/bayesian.rs. rust_hft/alpha-harness/engine/src/engines/mod.rs already hosts the shared test_dataset helper. Move evaluation there and import it in all three test modules. A future change to CandidateEvaluation then needs one edit, not three.

🤖 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/alpha-harness/engine/src/engines/gp.rs` around lines 239 - 262, Move
the duplicated evaluation test fixture from gp.rs, mcts.rs, and bayesian.rs into
the shared test helpers in engines/mod.rs, alongside test_dataset. Remove the
local evaluation definitions and import the shared evaluation helper in all
three engine test modules, preserving its current behavior and signature.
🤖 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/alpha-harness/domain/src/lib.rs`:
- Around line 1581-1592: Update CexFactorBankRevisionV1::validate to track
entry.factor_id values with a set and reject duplicate factor identities before
the final entry-binding check, returning DomainError::InvalidCexFactorBank with
an appropriate message. Preserve the existing candidate-id and entry-binding
validation.

In `@rust_hft/alpha-harness/engine/src/lib.rs`:
- Around line 457-461: The candidate-artifact uniqueness assumption must no
longer apply universally to GeneticProgramming engines. Update the branch around
persist_candidate to document that uniqueness is guaranteed only by the generic
GeneticProgrammingEngine’s seen-set filtering, or adjust
gp_resume_restores_history_and_keeps_candidate_artifacts_unique so its
uniqueness assertion applies only to generic GP and not governed GP.

---

Nitpick comments:
In `@rust_hft/alpha-harness/domain/src/lib.rs`:
- Around line 1387-1397: Update controlled_v1 to call dedup on admitted_fields
immediately after sorting it, so duplicate field names are normalized before
constructing and validating the policy.
- Around line 1700-1707: Optimize expected_revision_id by avoiding the deep
clone of the entire revision solely to clear revision_id. Build a borrowed
serializable view or remove revision_id from a serialized representation before
calling canonical_json_hash, while preserving the current hash input and
resulting revision ID behavior.
- Around line 3962-3991: Extend
governed_gp_policy_rejects_unadmitted_fields_and_operators to assert that a
FactorTerminal::Constant candidate is rejected, and add a candidate exceeding
the policy’s max_ast_depth or max_ast_nodes limit that validate_candidate also
rejects. Keep the existing field and operator assertions, then run cargo test -p
alpha-domain --locked.

In `@rust_hft/alpha-harness/engine/src/engines/gp.rs`:
- Around line 239-262: Move the duplicated evaluation test fixture from gp.rs,
mcts.rs, and bayesian.rs into the shared test helpers in engines/mod.rs,
alongside test_dataset. Remove the local evaluation definitions and import the
shared evaluation helper in all three engine test modules, preserving its
current behavior and signature.

In `@rust_hft/alpha-harness/engine/src/lib.rs`:
- Around line 1545-1583: Add a companion test for the non-GP duplicate path
using FixedFormulaEngine configured with EngineKind::ManualSeed, then assert the
resulting mission lineage contains one candidate and
iterations[1].candidate_artifact_id is None. Keep the existing GP persistence
test unchanged, and run the focused package tests with cargo test -p
alpha-engine --locked.
🪄 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: 2acbc0ea-11aa-4fd3-bd20-6522a04506f3

📥 Commits

Reviewing files that changed from the base of the PR and between 1067325 and be73d64.

📒 Files selected for processing (3)
  • rust_hft/alpha-harness/domain/src/lib.rs
  • rust_hft/alpha-harness/engine/src/engines/gp.rs
  • rust_hft/alpha-harness/engine/src/lib.rs

Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/engine/src/lib.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: be73d6461b

ℹ️ 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 rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/engine/src/engines/gp.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
Comment thread rust_hft/alpha-harness/domain/src/lib.rs
@proerror77
proerror77 force-pushed the codex/agent-cex-gp-factor-bank-core-599 branch from be73d64 to f1c5d6c Compare August 3, 2026 06:56
@proerror77
proerror77 merged commit 4aa43ef into main Aug 3, 2026
47 checks passed
@proerror77
proerror77 deleted the codex/agent-cex-gp-factor-bank-core-599 branch August 3, 2026 07:07
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