Repository navigation
feat: implement issue #1103 — [Phase 2] Prefetch shared PR context once and persist it to SHA-bound files (flag-gated, byte-identical when off) - #1161
Conversation
…ce and persist it to SHA-bound files (flag-gated, byte-identical when off)
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 15 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 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.
Code Review
This pull request introduces a shared PR-context prefetch script (scripts/lib/pr-context-prefetch.sh) that persists the full PR diff and a superset metadata JSON to SHA-bound files, gated behind the PREFETCH_CONTEXT_ENABLED flag. It integrates this prefetch logic into scripts/review-one-pr.sh and adds comprehensive unit tests in tests/test_prefetch_context.bats. The review feedback suggests adding robust error handling and a portable template path to mktemp in the prefetch script, as well as utilizing $BATS_TEST_TMPDIR for temporary directory creation in the BATS tests to ensure automatic cleanup.
There was a problem hiding this comment.
Pull request overview
Implements Phase 2 of issue #1103 by adding a default-off prefetch step in review-one-pr.sh that persists a SHA-stamped, full (untruncated) PR diff and a superset PR-metadata JSON to stable /tmp/cascade files for downstream agentic tiers—without changing tier prompts while the flag is off.
Changes:
- Add
PREFETCH_CONTEXT_ENABLED(default-off) plumbing to persist and exportPR_CONTEXT_DIFF_FILE/PR_CONTEXT_METADATA_FILEfor agentic tiers. - Reuse the already-fetched full diff on disk (including the >300-file REST assembly fallback) to avoid additional
gh pr diffcalls; perform one additionalgh pr viewfor superset metadata. - Add Bats coverage for flag-off and flag-on behaviors and wire the new test into
lint.yml.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
scripts/review-one-pr.sh |
Adds gated prefetch invocation reusing the on-disk full diff and exporting SHA-bound context file paths. |
scripts/lib/pr-context-prefetch.sh |
Introduces the shared helper that writes SHA-stamped diff + superset metadata and exports paths for tiers. |
tests/test_prefetch_context.bats |
Adds unit tests validating off/on behavior, SHA-stamping, and fetch volume/rate-limit handling. |
.github/workflows/lint.yml |
Adds the new Bats test to the lint workflow’s test list. |
Dev-Lead — review-changes (applied)Changes committed and pushed. |
Dev-Lead — review-changes (applied)Changes committed and pushed. |
Dev-Lead — review-changes (no-changes)No changes were needed for this PR. |
Superseded by automated re-review at
|
Superseded by automated re-review at
|
|
Dev-Lead — review-changes (no-changes)No changes were needed for this PR. |
donpetry-bot
left a comment
There was a problem hiding this comment.
Automated review — APPROVED ✓
Risk: MEDIUM
Reviewed commit: ebc50bd67811e816e1637e6baf29bae79ad78ac6
Review mode: triage-approved (single reviewer)
Summary
Adds a flag-gated (PREFETCH_CONTEXT_ENABLED, default-off) shared PR-context prefetch: scripts/lib/pr-context-prefetch.sh persists the full untruncated diff and a superset metadata JSON to SHA-stamped files under /tmp/cascade and exports PR_CONTEXT_DIFF_FILE / PR_CONTEXT_METADATA_FILE for the agentic tiers. review-one-pr.sh wires it in after the diff fetch, reusing the already-fetched full diff (including the >300-file REST-assembly fallback) with exactly one additional gh pr view. Plumbing only — no tier prompt changes. 195-line bats suite covers off/on, SHA stamping, truncation, fetch volume, and rate-limit degradation; wired into lint.yml. All three prior bot findings were fixed at the current head and their threads resolved.
Linked issue analysis
Closes #1103 ([Phase 2] prefetch shared PR context once, flag-gated). All 6 acceptance criteria are met: (1) default-off is a byte-identical no-op — zero files, zero exports, zero gh calls (bats-asserted); (2) full non-truncated diff + superset metadata (headRepository/headRepositoryOwner/repository and full files array) written to stable exported paths; (3) both artifacts stamped with PR_HEAD_SHA (.pr_head_sha top-level field / header line) for Story 5 freshness checks; (4) diff reused from triage's untruncated on-disk copy with exactly one extra gh pr view for the superset metadata (bats asserts fetch volume); (5) gh rate-limit degrades to the existing exit-100 skip sentinel, other metadata failures degrade to a no-op, and the 406 >300-file case reuses the upstream REST assembly; (6) bats coverage added and wired into lint.yml.
Findings
No blocking findings.
Resolved prior findings (verified fixed at ebc50bd):
- gemini: mktemp without error handling — now
mktemp "${TMPDIR:-/tmp}/pr-context-meta.XXXXXX" || { ...; return 1; }(correctlyreturn, notexit, in a sourced function). - gemini: bats stub dir outside BATS_TEST_TMPDIR — now
mktemp -d "$BATS_TEST_TMPDIR/stub.XXXXXX". - copilot: unstamped metadata could be exported when jq fails — now guarded by
meta_stamped; the file is removed and PR_CONTEXT_METADATA_FILE is only exported when the SHA stamp was applied.
Notes (non-blocking):
- The common cleanup now uses
rm -f ... "${_fallback_tmp:-}", which is safe when the fallback branch was not taken (empty operand is ignored byrm -f). - Secret scan: the run_secret_scanning MCP tool was not available in this session; the gitleaks CI check passed (green).
CI status
All required checks green: shellcheck/ShellCheck, bats, unit-tests, Lint, CodeQL (actions + python), SonarCloud, gitleaks secret scan, agent-shield, gh-aw-compile, validate-fixtures, holdout-guard, and stub/permission guards all SUCCESS. Skipped jobs are conditional dependency audits (npm/pnpm/pip/cargo/govulncheck) and dependabot-automerge — expected for this change. CodeRabbit review: APPROVED.
Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.



Closes #1103
Implemented by dev-lead agent. Please review.