fix(mi355): harden exact-SHA evidence worker - #12
Merged
Conversation
Fail closed on fetch races and missing pinned images while preserving immutable, content-addressed evidence. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Reviewer's GuideHardens the MI355 evidence worker by enforcing exact approved SHAs throughout the workflow, making the compact evidence bundle content‑addressed and immutable, tightening sandbox execution to use the caller identity with least-privilege GPU access and no runtime pulls, and extending tests/docs to cover the new guarantees. Sequence diagram for MI355 PR processing with exact SHA enforcementsequenceDiagram
participant Worker as mi355_worker
participant GitHub as GitHubAPI
participant Repo as GitRepo
Worker->>GitHub: _authorize_pull(repo, pr_number, required_label)
GitHub-->>Worker: pull, head_sha, approval
Worker->>Repo: _run git fetch origin +pull/pr_number/head:fetch_ref
Worker->>Repo: _run git rev-parse fetch_ref^{commit}
Repo-->>Worker: fetched_sha
Worker->>Worker: require_exact_sha(fetched_sha, head_sha, source=current PR head)
Worker->>GitHub: _authorize_pull(repo, pr_number, required_label, expected_head_sha=head_sha)
GitHub-->>Worker: pull, head_sha (unchanged), approval
Worker->>Repo: _run git worktree add --detach candidate head_sha
Worker->>Worker: _run_validation(candidate, gpu, run_output)
Worker->>GitHub: _authorize_pull(repo, pr_number, required_label, expected_head_sha=head_sha)
GitHub-->>Worker: approval
Worker->>Worker: _copy_compact_bundle(run_output, evidence_root, pr_number, head_sha, controller_sha, approval, artifact_uri)
Worker-->>GitHub: _publish_check(repo, pr_number, head_sha, evidence)
Flow diagram for content-addressed immutable evidence bundle creationflowchart TD
A[collect provenance: pr, head_sha, controller_sha, approval] --> B[create staging directory in evidence_root]
B --> C[copy manifest.json, verdicts.json, summary.txt to staging]
C --> D[copy health-before.txt, health-after.txt if present]
D --> E[_bundle_digest staging and provenance]
E --> F[build destination path: pr-head_sha_sha256-digest]
F --> G{destination exists?}
G -->|yes| H[raise ValueError immutable evidence bundle already exists]
G -->|no| I[resolve artifact_uri to include destination.name]
I --> J[write EVIDENCE.yaml in staging]
J --> K[rename staging to destination]
K --> L[return destination, evidence]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_evolution.py" line_range="761-770" />
<code_context>
raise AssertionError(f"MI355 control-plane change accepted: {path}")
+def test_mi355_worker_rejects_fetched_sha_race():
+ from evolve.mi355_worker import require_exact_sha
+
+ approved = "a" * 40
+ require_exact_sha(approved, approved, source="test")
+ try:
+ require_exact_sha("b" * 40, approved, source="fetched PR head")
+ except ValueError as error:
+ assert "does not match approved SHA" in str(error)
+ else:
+ raise AssertionError("worker accepted a fetched SHA that was not approved")
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Strengthen `require_exact_sha` test by asserting the full error message and including the source label
This test only checks for the generic substring "does not match approved SHA". Since `require_exact_sha` includes the `source` in its error message, please also assert that the message contains the specific source (e.g. "fetched PR head"), and ideally the mismatching SHA values. This will better lock in the error contract and help detect regressions in the message structure or content.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
python3 tests/test_evolution.pyMade with Cursor
Summary by Sourcery
Harden the MI355 evidence worker by enforcing exact SHA approvals, making evidence bundles content-addressed and immutable, and tightening sandbox isolation and identity usage.
New Features:
Enhancements:
Tests: