fix(snapshot): fail closed when git check-ignore errors#8
Conversation
Ported from upstream anomalyco#36357.
|
Warning Review limit reached
Next review available in: 47 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: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe snapshot ignore logic now warns on unexpected ChangesSnapshot ignore handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
@coderabbitai full review |
✅ Action performedFull review finished. Your plan includes PR reviews subject to rate limits. More reviews will be available in 47 minutes. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/opencode/src/snapshot/index.ts (1)
93-99: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
git()should not mask spawn failures as exit code 1.ignore()treats1as a normal “none ignored” result, so a failedappProcess.runstill falls through as an empty ignored set and bypasses the new fail-closed path. Surface the error or use a distinct sentinel for execution failures.🤖 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 `@packages/opencode/src/snapshot/index.ts` around lines 93 - 99, Update the error handling in git() so failures from appProcess.run are not represented by ChildProcessSpawner.ExitCode(1), which ignore() interprets as a successful empty result. Surface the spawn error or return a distinct execution-failure sentinel, while preserving normal exit-code handling for actual git results.
🧹 Nitpick comments (2)
packages/opencode/src/snapshot/index.ts (2)
126-132: 🩺 Stability & Availability | 🔵 TrivialConsider the blast radius of fail-closed across
add/patch/diffFull.Since
ignore()is shared byadd(),patch(), anddiffFull(), a persistent unexpectedcheck-ignoreexit code won't just hide ignored files —add()will stop staging any candidates andpatch()/diffFull()will silently show empty output, with only a warning-level log as a signal. Worth ensuring this warning is surfaced/alerted on in production observability so a persistently failingcheck-ignore(e.g., misconfigured git binary) doesn't look like "nothing changed" to users.🤖 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 `@packages/opencode/src/snapshot/index.ts` around lines 126 - 132, Update the unexpected check-ignore failure handling in ignore() so the warning is surfaced through production observability, not only a warning-level log. Ensure failures affecting add(), patch(), and diffFull() are clearly identifiable as check-ignore errors rather than appearing as empty or unchanged results.
126-132: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for the new fail-closed branch.
None of the provided snapshot tests exercise a non-0/1
check-ignoreexit code. Given this is a security-motivated change (preventing ignored-file leakage on git errors), a test that mocks/stubs an unexpected exit code and asserts all candidates end up in the returned set would directly protect this path from regression.🤖 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 `@packages/opencode/src/snapshot/index.ts` around lines 126 - 132, Add a snapshot test covering the `check.code !== 0 && check.code !== 1` branch in the snapshot filtering flow: stub `git check-ignore` to return an unexpected non-0/1 exit code, invoke the relevant snapshot function, and assert the returned set contains every candidate file.
🤖 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.
Outside diff comments:
In `@packages/opencode/src/snapshot/index.ts`:
- Around line 93-99: Update the error handling in git() so failures from
appProcess.run are not represented by ChildProcessSpawner.ExitCode(1), which
ignore() interprets as a successful empty result. Surface the spawn error or
return a distinct execution-failure sentinel, while preserving normal exit-code
handling for actual git results.
---
Nitpick comments:
In `@packages/opencode/src/snapshot/index.ts`:
- Around line 126-132: Update the unexpected check-ignore failure handling in
ignore() so the warning is surfaced through production observability, not only a
warning-level log. Ensure failures affecting add(), patch(), and diffFull() are
clearly identifiable as check-ignore errors rather than appearing as empty or
unchanged results.
- Around line 126-132: Add a snapshot test covering the `check.code !== 0 &&
check.code !== 1` branch in the snapshot filtering flow: stub `git check-ignore`
to return an unexpected non-0/1 exit code, invoke the relevant snapshot
function, and assert the returned set contains every candidate file.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5c19cf6-f2ba-466c-b29f-6cd861cab533
📒 Files selected for processing (1)
packages/opencode/src/snapshot/index.ts
Addresses CodeRabbit Major finding on the anomalyco#36357 port: spawn failures no longer masquerade as exit code 1, so check-ignore fail-closed cannot be bypassed by a failed git invocation.
|
Addressed findings:
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Port of upstream anomalyco/opencode#36357.
When
git check-ignoreexits with a code other than 0/1 (repo corruption, permission errors), the snapshot ignore-check now treats all candidate files as ignored instead of returning an empty set, preventing sensitive ignored files from being swept into snapshots on git failure.Verified:
bun test test/snapshot/(55 pass, 1 pre-existing skip) andbun typecheckfrom packages/opencode. Applied cleanly.Summary by CodeRabbit