Skip to content

feat(harness): gate prediction dispatch on admission - #369

Merged
proerror77 merged 2 commits into
mainfrom
codex/prediction-dispatch-admission-334
Jul 26, 2026
Merged

feat(harness): gate prediction dispatch on admission#369
proerror77 merged 2 commits into
mainfrom
codex/prediction-dispatch-admission-334

Conversation

@proerror77

@proerror77 proerror77 commented Jul 26, 2026

Copy link
Copy Markdown
Owner

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)
  • Focused dispatcher and runner counterexamples: rejection/no kubectl, malformed/mutable/unsupported response, logical-contract mismatch/no evaluator start, sibling timeout and stdout-descendant timeout.
  • cargo clippy -p alpha-harness --all-targets -- -D warnings
  • cargo fmt --check -p alpha-harness and git diff --check
  • Independent standards/spec reviews: no remaining P0/P1; Expose a versioned authenticated snapshot admission sibling protocol #364 test-only digest assertion is tracked separately to avoid mixing contracts.

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

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Snapshot admission dispatch

Layer / File(s) Summary
Admission contracts and sibling protocol
rust_hft/alpha-harness/app/src/prediction_dispatch.rs
Typed admission requests, responses, identities, and decisions are added with strict single-line parsing, identity checks, and timeout-bounded sibling execution.
Admission-aware render and submit pipeline
rust_hft/alpha-harness/app/src/prediction_dispatch.rs
Render and submit now follow validation, admission, and rendering; rejected admissions are reported before Kubernetes operations, and manifests receive admitted snapshot annotations.
Explicit kubectl process wiring
rust_hft/alpha-harness/app/src/prediction_dispatch.rs
Submission, reconciliation, and status helpers use the resolved kubectl binary path explicitly.
Admission and rendering test coverage
rust_hft/alpha-harness/app/src/prediction_dispatch.rs
Tests cover admitted rendering, validation placement, rejection ordering, response schema and identity binding, extra output, and sibling timeout termination.

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

Possibly related issues

  • Issue 334 — The snapshot-admission gating requirements are implemented in the prediction dispatcher.

Possibly related PRs

  • proerror77/monday#247 — Both changes modify the prediction dispatcher’s render and submit flow, with this PR adding snapshot-admission gating and kubectl wiring.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: gating prediction dispatch on admission.
Description check ✅ Passed The description covers the change contract, out-of-scope, dependency, validation, and rollout details in a mostly complete template match.
✨ 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/prediction-dispatch-admission-334

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

🧹 Nitpick comments (4)
rust_hft/alpha-harness/app/src/prediction_dispatch.rs (4)

240-243: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the sibling resolution into one helper.

The env var name and default binary name are duplicated in render and submit; a single snapshot_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 value

Break out of the loop once the bound is exceeded.

Once exceeded is 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 win

Test does not actually assert the sibling was killed.

It only checks the error message. Have the stub write a sentinel after sleep and 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 value

Collapse the two identical-signature render functions.

render_admitted_submission adds only the namespace check before delegating to render_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

📥 Commits

Reviewing files that changed from the base of the PR and between f84cda3 and 06383ff.

📒 Files selected for processing (1)
  • rust_hft/alpha-harness/app/src/prediction_dispatch.rs

Comment thread rust_hft/alpha-harness/app/src/prediction_dispatch.rs Outdated
Comment thread rust_hft/alpha-harness/app/src/prediction_dispatch.rs
Comment thread rust_hft/alpha-harness/app/src/prediction_dispatch.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: 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".

Comment thread rust_hft/alpha-harness/app/src/prediction_dispatch.rs Outdated
Comment thread rust_hft/alpha-harness/app/src/prediction_dispatch.rs Outdated
@proerror77
proerror77 merged commit c9646f8 into main Jul 26, 2026
38 checks passed
@proerror77
proerror77 deleted the codex/prediction-dispatch-admission-334 branch July 26, 2026 06:58
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