feat: implement Causal Blast Radius Estimator for proactive impact analysis#91
feat: implement Causal Blast Radius Estimator for proactive impact analysis#91SHAURYASANYAL3 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds causal impact analysis to the safety engine by introducing a refactored BlastRadiusEstimator that detects dangerous database operations (missing WHERE clauses, UPDATE/DELETE patterns, critical table modifications), destructive filesystem commands, and production resource access, then integrates this estimator into SafetyEngine to escalate policy decisions when high-impact operations are detected. ChangesCausal Blast Radius Estimation and Safety Escalation
Sequence DiagramsequenceDiagram
participant Engine as SafetyEngine
participant Estimator as BlastRadiusEstimator
participant Policy as Policy Evaluator
participant Data as SafetyCheckData
Engine->>Estimator: estimate(event)
Estimator->>Estimator: pattern match & heuristics
Estimator-->>Engine: BlastRadius{score, is_critical_resource, explanation}
Engine->>Data: attach blast_radius
Engine->>Policy: evaluate policies & DSL
Policy-->>Engine: requires_approval, reasons
Engine->>Engine: check Causal Override
alt blast_radius.requires_approval && !already_approved
Engine->>Engine: force requires_approval=true
Engine->>Engine: append ESCALATED reason
end
Engine-->>Data: finalized SafetyCheckData
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 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)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
agentwatch/core/blast_radius.py (1)
137-141: 💤 Low valueConsider using regex for critical path detection.
The exact substring match
f"rm -rf {path}" in rawwon't catch variations likerm -rf /etc(double space) orrm -r -f /etc. These would still get score 95 from the base pattern (above approval threshold), so this isn't a bypass—just a minor gap in the 95→100 elevation.Proposed regex-based approach
- for path in critical_paths: - if f"rm -rf {path}" in raw or f"rm -rf {path}/" in raw: + for path in critical_paths: + # Match rm with -r and -f flags (in any order/format) followed by the critical path + escaped_path = re.escape(path) + if re.search(rf"\brm\s+(-[rf]+\s+)*-[rf]+\s+{escaped_path}(?:/|$|\s)", raw):🤖 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 `@agentwatch/core/blast_radius.py` around lines 137 - 141, Replace the brittle substring checks in the loop over critical_paths with a regex-based match against raw that allows variable whitespace and flag order (e.g., multiple spaces, flags like -r and -f in either order, combined flags), and ensure you escape the path and allow an optional trailing slash; when the regex matches, set radius.is_critical_resource = True, radius.score = max(radius.score, 100), and radius.affected_file_count = 50000 as before. Use the existing critical_paths list, the raw input string, and the radius object (radius.is_critical_resource, radius.score, radius.affected_file_count) so the logic location remains the same. Ensure you use a single regex search per path and avoid changing other scoring logic.
🤖 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.
Nitpick comments:
In `@agentwatch/core/blast_radius.py`:
- Around line 137-141: Replace the brittle substring checks in the loop over
critical_paths with a regex-based match against raw that allows variable
whitespace and flag order (e.g., multiple spaces, flags like -r and -f in either
order, combined flags), and ensure you escape the path and allow an optional
trailing slash; when the regex matches, set radius.is_critical_resource = True,
radius.score = max(radius.score, 100), and radius.affected_file_count = 50000 as
before. Use the existing critical_paths list, the raw input string, and the
radius object (radius.is_critical_resource, radius.score,
radius.affected_file_count) so the logic location remains the same. Ensure you
use a single regex search per path and avoid changing other scoring logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 182e5179-c90d-4a98-b1ea-1c23a2751db6
📒 Files selected for processing (4)
agentwatch/core/blast_radius.pyagentwatch/core/safety.pyagentwatch/core/schema.pytests/test_blast_radius_causal.py
sreerevanth
left a comment
There was a problem hiding this comment.
This is a valuable feature and the implementation direction looks reasonable. However, because it changes core safety-engine decision making and can automatically escalate actions, additional regression coverage is required before merge.
Please add tests demonstrating:
Safe SQL operations are not incorrectly escalated.
Normal filesystem operations are not incorrectly escalated.
Existing safety-engine behavior remains unchanged for low-risk actions.
Backward compatibility of current safety checks.
Once regression coverage is expanded, this should be ready for another review.
Summary
This PR introduces the Causal Blast Radius Estimator (SAF-010), enhancing AgentWatch's safety analysis by estimating the potential impact of an action rather than relying solely on static pattern matching.
The new estimator evaluates contextual risk signals across SQL and filesystem operations and automatically escalates actions that could affect critical resources or large amounts of data.
What Changed
Blast Radius Estimation Engine
Refactored
agentwatch/core/blast_radius.pyto implement causal impact heuristics.Added support for:
WHEREclauses, access to critical tables).Safety Engine Integration
agentwatch/core/safety.py.Schema Enhancements
SafetyCheckDatainagentwatch/core/schema.py.Validation
Added
tests/test_blast_radius_causal.pycovering:DELETEoperations without aWHEREclause.SafetyEngine.All 28 safety-related tests pass with this change.
Summary by CodeRabbit
New Features
Tests