feat(harness): gate prediction dispatch on admission - #369
Conversation
📝 WalkthroughWalkthroughPrediction dispatch now validates submissions, admits snapshots through a bounded sibling process, renders admitted data, and threads explicit kubectl paths through submit, reconciliation, and status operations. Manifests include admission-derived identity annotations, with expanded protocol and timeout tests. ChangesSnapshot admission dispatch
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant Dispatcher
participant Validator
participant SnapshotAdmission
participant Kubectl
participant Kubernetes
Dispatcher->>Validator: validate submission
Validator-->>Dispatcher: validated submission
Dispatcher->>SnapshotAdmission: submit typed admission request
SnapshotAdmission-->>Dispatcher: admitted or rejected response
alt admitted
Dispatcher->>Dispatcher: render admitted submission
Dispatcher->>Kubectl: create or reconcile resources
Kubectl->>Kubernetes: apply resource operations
else rejected
Dispatcher->>Dispatcher: print JSON rejection and return error
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
rust_hft/alpha-harness/app/src/prediction_dispatch.rs (4)
240-243: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the sibling resolution into one helper.
The env var name and default binary name are duplicated in
renderandsubmit; a singlesnapshot_admission_sibling()keeps the two entry points from drifting.Also applies to: 261-264
🤖 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/app/src/prediction_dispatch.rs` around lines 240 - 243, Extract the duplicated configured sibling resolution from render and submit into a shared snapshot_admission_sibling() helper, using the same MONDAY_PREDICTION_SNAPSHOT_BIN environment variable and monday-prediction-snapshot default. Update both entry points to call this helper while preserving their existing error propagation and behavior.
686-698: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueBreak out of the loop once the bound is exceeded.
Once
exceededis set the remaining bytes are discarded anyway, but the loop keeps draining until EOF. Returning immediately closes the pipe and fails faster.🤖 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/app/src/prediction_dispatch.rs` around lines 686 - 698, Update the response-reading loop in prediction_dispatch.rs to return the existing size-limit error immediately when the copied data causes exceeded to become true, rather than continuing to read until EOF. Preserve the current bounded buffering and error message behavior.
1395-1416: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest does not actually assert the sibling was killed.
It only checks the error message. Have the stub write a sentinel after
sleepand assert the sentinel is absent, so a regression where the child is left running is caught.💚 Suggested strengthening
- std::fs::write(&sibling, "#!/bin/sh\ncat >/dev/null\nsleep 1\n") - .expect("write stalled sibling"); + let survived = root.path().join("sibling-survived"); + std::fs::write( + &sibling, + format!("#!/bin/sh\ncat >/dev/null\nsleep 1\ntouch '{}'\n", survived.display()), + ) + .expect("write stalled sibling"); @@ assert!(error.to_string().contains("timed out")); + std::thread::sleep(Duration::from_millis(1500)); + assert!(!survived.exists(), "stalled sibling must be terminated");🤖 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/app/src/prediction_dispatch.rs` around lines 1395 - 1416, Strengthen admission_timeout_kills_a_stalled_sibling by having the executable sibling write a sentinel file after its sleep completes, then assert that sentinel is absent after admit_submission_with_timeout returns the timeout error. Keep the existing timeout-message assertion and ensure the sentinel path is available to the stub and test.
777-790: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCollapse the two identical-signature render functions.
render_admitted_submissionadds only the namespace check before delegating torender_validated_submission, which has the same signature and no other callers. Inline the check.🤖 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/app/src/prediction_dispatch.rs` around lines 777 - 790, Remove the redundant render_admitted_submission wrapper and move its validate_dns_label("namespace", namespace)? check into render_validated_submission before processing admitted. Preserve the existing rendering behavior and function signature while eliminating the delegation.
🤖 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/app/src/prediction_dispatch.rs`:
- Around line 659-668: Update the snapshot admission sibling cleanup around
reader.join and child.wait so the child exit wait remains bounded after stdout
is consumed, including when the reader returns Disconnected. Ensure the child is
terminated before waiting if needed, and always join the reader in every branch
to avoid leaving it running while preserving the existing unsuccessful-exit
handling.
- Around line 723-753: Update validate_submission to validate
submission.task_capability before the sibling admission call, requiring it to be
non-empty and restricted to the manifest’s identifier character set. Keep the
existing echoed-value comparison in the SnapshotAdmissionResponse::Admitted
branch, but ensure malformed capabilities are rejected during submission
validation rather than reaching manifest generation or kubectl create.
- Around line 590-603: Strengthen the artifact-path validation in the
request-building flow around read_catalog_partition_artifact so paths are
non-empty, relative, and restricted to simple catalog-partition JSON filenames
matching the expected catalog-partition-*.json form. Reject absolute paths,
traversal components, separators, and other malformed names before serializing
or sending the request, while preserving the existing control-character and size
checks.
---
Nitpick comments:
In `@rust_hft/alpha-harness/app/src/prediction_dispatch.rs`:
- Around line 240-243: Extract the duplicated configured sibling resolution from
render and submit into a shared snapshot_admission_sibling() helper, using the
same MONDAY_PREDICTION_SNAPSHOT_BIN environment variable and
monday-prediction-snapshot default. Update both entry points to call this helper
while preserving their existing error propagation and behavior.
- Around line 686-698: Update the response-reading loop in
prediction_dispatch.rs to return the existing size-limit error immediately when
the copied data causes exceeded to become true, rather than continuing to read
until EOF. Preserve the current bounded buffering and error message behavior.
- Around line 1395-1416: Strengthen admission_timeout_kills_a_stalled_sibling by
having the executable sibling write a sentinel file after its sleep completes,
then assert that sentinel is absent after admit_submission_with_timeout returns
the timeout error. Keep the existing timeout-message assertion and ensure the
sentinel path is available to the stub and test.
- Around line 777-790: Remove the redundant render_admitted_submission wrapper
and move its validate_dns_label("namespace", namespace)? check into
render_validated_submission before processing admitted. Preserve the existing
rendering behavior and function signature while eliminating the delegation.
🪄 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: d739be25-ae31-46f8-9d6e-9a06d5ecf7b2
📒 Files selected for processing (1)
rust_hft/alpha-harness/app/src/prediction_dispatch.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06383ff79e
ℹ️ 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".
Change contract
Gate every prediction Mission render/submit on the versioned #364 sibling admission response after submission syntax validation and before result lookup, manifest rendering, or Kubernetes interaction. A rejection emits typed JSON and exits nonzero; admitted contract, logical snapshot digest, partition, policy, capability, and image identities are bound through the Job and revalidated by the runner before research starts.
Acceptance evidence
cargo test -p alpha-harness(101 tests)cargo clippy -p alpha-harness --all-targets -- -D warningscargo fmt --check -p alpha-harnessandgit diff --checkOut of scope
Snapshot materialization, catalog/partition construction, evaluator/MCTS behavior, collector deployment, Kubernetes API behavior beyond the admission gate, schedulers, databases, Paper/Shadow/Live, or promotion.
Dependency / merge order
Depends on merged #320, #365, and #364; unblocks #323. The #364 response identities are the proof of admission; this PR deliberately does not recreate a constructible opaque handle.
Rollout / rollback impact
Prediction dispatch now fail-closes when sibling admission is absent, malformed, timed out, rejected, identity-mismatched, or inconsistent with the Mission/extracted snapshot manifest. Rollback removes the gate and its propagation; this PR performs no production mutation itself.