Skip to content

feat(runner): add git safety guardrails to prevent destructive operations#1225

Open
ambient-code[bot] wants to merge 1 commit intomainfrom
ambient/session-b2234b52-e53a-4bcf-8c1b-8cbb6960fe41
Open

feat(runner): add git safety guardrails to prevent destructive operations#1225
ambient-code[bot] wants to merge 1 commit intomainfrom
ambient/session-b2234b52-e53a-4bcf-8c1b-8cbb6960fe41

Conversation

@ambient-code
Copy link
Copy Markdown
Contributor

@ambient-code ambient-code bot commented Apr 6, 2026

Summary

  • Add git_guardrails.py module with regex-based command validation that detects 11 blocked patterns (ref deletion, force push, API ref manipulation, reset --hard, clean -fd, etc.) and 3 warning patterns (rebase, --force-with-lease, --amend)
  • Inject a Git Safety Guardrails section into the system prompt whenever repos are configured, with 6 hard rules and an escalation protocol for failed git operations
  • Add token redaction utilities to prevent PATs from appearing in command logs
  • 46 unit tests for the guardrails module + 2 prompt integration tests (all passing)

Addresses every recommendation from #1111:

  1. Hard block on DELETE ref operations
  2. Prohibit direct GitHub API ref manipulation
  3. Never modify the user's default/main branch
  4. Create backup branches before any rebase/reset
  5. Consent gates at escalation boundaries (escalation protocol)
  6. Redact tokens from commands

Test plan

  • All 46 test_git_guardrails.py tests pass
  • All 8 existing test_auto_push.py tests pass (including 2 new guardrail prompt tests)
  • CI pipeline passes

Closes #1111

🤖 Generated with Claude Code

…ions

Add comprehensive git guardrails to the runner to prevent AI agents from
performing irreversible git operations without user authorization. This
addresses incidents where agents deleted remote branches (permanently
closing PRs), force-pushed to user forks, and ran destructive local
operations without backups.

Changes:
- New git_guardrails.py module with command validation logic that detects
  dangerous operations (ref deletion, force push, API ref manipulation,
  reset --hard, clean -fd, etc.) and token exposure in commands
- System prompt now includes explicit Git Safety Guardrails section with
  hard rules and an escalation protocol when git operations fail
- 46 unit tests for the guardrails module + 2 prompt integration tests

Closes #1111

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ambient-code ambient-code bot added the ambient-code:managed PR managed by AI automation label Apr 6, 2026
@ambient-code ambient-code bot added this to the Review Queue milestone Apr 7, 2026
@ambient-code ambient-code bot added ambient-code:needs-human AI circuit breaker fired, needs human attention and removed ambient-code:managed PR managed by AI automation labels Apr 7, 2026
@ambient-code
Copy link
Copy Markdown
Contributor Author

ambient-code bot commented Apr 7, 2026

🔄 Circuit breaker reached (retry_count=3)

This PR has been checked 3 times by automated maintenance with no actionable issues found:

  • CI: All checks passing
  • Merge conflicts: None
  • Review comments: None received

The PR is healthy and ready for human review. Handing off to a human reviewer.

Labels updated: removed ambient-code:managed, added ambient-code:needs-human.

@Gkrumbach07
Copy link
Copy Markdown
Contributor

Im going to say hold on this, not sure if this type of guardrails is needed, i feel liek we should move to some sort of file rewind instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ambient-code:needs-human AI circuit breaker fired, needs human attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Amber Refactor] Fix Agents destroying workspaces

1 participant