feat(damage-control): allowlist clearing of orphaned git lockfiles (keep package locks protected) - #1836
Conversation
…eep package locks protected The *.lock readOnlyPath rightly blocks editing/deleting package locks, but it also blocked clearing git's OWN internal lockfiles (.git/config.lock, .git/index.lock). Those orphan as 0-byte sentinels when an interrupted config/index write dies before the atomic rename (killed cmd, closed session, OneDrive/AV holding the handle); while present they block every subsequent git config/index op (branch -D, push -u, worktree add, add/commit) and git cannot auto-clear them (can't tell a stale lock from a live one). The guard then forced agents to defer to the operator for a routine, safe cleanup. Add a new bashDeleteAllowlist (data + reason in patterns.yaml) checked AFTER the destructive-pattern block (recursive/force deletes still blocked) and AFTER zeroAccessPaths (never bypassed), BEFORE read-only/no-delete. The single entry is anchored to the WHOLE command, so only a bare delete of git's own lockfiles passes - package locks (yarn.lock/uv.lock/...), flagged deletes, and chained commands all stay blocked. Verified by test_gitlock_allowlist.py (10 cases: 4 allow, 6 block) + existing test_insight_edits.py still 10/10. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 36 minutes and 57 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesGit Lockfile rm Allowlist
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8fb4775503
ℹ️ 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".
|
Triage from chatgpt-codex-connector[bot]: No P0/P1 findings. P2: 1, P3: 0. P2 — .claude/hooks/damage-control/patterns.yaml:1053 / bash-tool-damage-control.py: re.search() with backtracking whitespace absorbs newlines in allowlist match; embedded-newline injection is correctly blocked today by the anchored pattern, but adding an explicit newline-rejection guard before the regex would strengthen defense-in-depth. |
Codex P2: the allowlist regex used \s* between operands, and \s matches a newline. A newline terminates a command in Bash, so `<del> .git/config.lock\n .git/index.lock` matched the pattern but Bash would execute the second line as its own command — breaking the "no chaining" guarantee. Restrict all separators to [ \t] (spaces/tabs) so any newline falls through to the read-only block. Added two newline-injection cases to test_gitlock_allowlist.py (now 12 cases, all pass): newline-as-separator and newline-then-command both blocked. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Adds a narrowly-scoped allowlist so the damage-control Bash guard permits clearing git's own orphaned internal lockfiles (
.git/config.lock,.git/index.lock), while keeping the*.lockread-only protection on package locks intact.Why
The
*.lockreadOnlyPathcorrectly blocks editing/deleting package locks (yarn.lock,uv.lock,Cargo.lock, …). But it also caught git's internal lockfiles, which are a different thing entirely:branch -D,push -u,worktree add,add/commit.The guard previously forced an agent to defer this routine, safe cleanup to the operator (manual shell
rm), even though no live git process held the lock.How
New
bashDeleteAllowlist(data + statedreasoninpatterns.yaml), evaluated:zeroAccessPaths(never bypassed),The single entry's regex is anchored to the whole command, so only a bare delete of git's own lockfiles passes. Adding a new exception is documented inline: anchor the command, keep it surgical, state a reason.
Safety / tests
test_gitlock_allowlist.py(new) — 10 cases:.git/config.lock,.git/index.lock, both,./-prefixedyarn.lock,uv.lock(package locks), recursive/force deletes (step 1), chained commands (&&,;)Existing
test_insight_edits.pystill 10/10 (no regression).patterns.yamlvalidates;*.lockread-only entry unchanged.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
.git/config.lockand.git/index.lock) that may block Git operations.Tests
rmcommands proceed while malformed operations remain blocked.