Bug #16: Edit Risk Model — Auto-Proceed with Backup
Status: RESOLVED in v3.15.1; behavior refined in v4.5.x Category: Risk Model / Agentic Workflow Severity: High (wasted token round-trips on every moderate edit) Resolution Date: 2026-03-02
Problem
Section titled “Problem”When an edit changed more than 30% of a file, the server blocked the operation and asked the AI to retry with force: true. In agentic workflows this caused a wasteful extra round-trip for every moderate edit — even though the change was perfectly safe.
Root Cause
Section titled “Root Cause”Two issues in core/edit_operations.go:
- Wrong blocking condition:
EditFile()usedimpact.IsRisky && !forceto decide whether to block. SinceIsRiskyistruefor MEDIUM (>=30%), HIGH (>=50%), and CRITICAL (>=90%) at the time, any edit changing more than 30% of a file was blocked. - Backup created too late: The backup happened AFTER the blocking check, so blocked operations had no safety net.
Solution
Section titled “Solution”The model was changed so that no risk level blocks the edit. Instead, risk levels add progressively stronger warnings and always create an automatic backup first:
| Risk Level | Default % Change | Behavior |
|---|---|---|
| LOW | < 20% | Proceed silently |
| MEDIUM | >= 20% | Auto-backup + proceed + risk notice |
| HIGH | >= 75% | Auto-backup + proceed + prominent warning |
| CRITICAL | >= 90% | Auto-backup + proceed + VERIFY instruction |
Percentages are defaults; use --risk-threshold-medium and --risk-threshold-high to customize them. CRITICAL is fixed at >= 90%.
v4.5.x Refinement
Section titled “v4.5.x Refinement”In v4.5.10+ the accidental-rewrite guard was added: if new_text is more than 2x the size of old_text and covers more than 50% of the file, the edit is blocked unless allow_rewrite: true is set. In v4.5.17+ --auto-occ (off / warn / block) can reject edits when the file changed on disk between read and edit. These are independent safety guards, not part of the risk level itself.
Key Changes (v3.15.1)
Section titled “Key Changes (v3.15.1)”- Backup before any mutation: backups are created up-front for every risky edit.
- Auto-proceed for MEDIUM/HIGH/CRITICAL: no
force: trueneeded. - Clear risk notices: responses include the backup ID and a restore hint.
- VERIFY instruction: CRITICAL edits tell the caller to confirm the file is complete with
read_file(mode: "tail"). - Thresholds updated: MEDIUM lowered from 30% to 20%, HIGH raised from 50% to 75% to match real-world editing patterns.
multi_editparity: risk assessment, hooks, and per-edit status detail were added tomulti_edit.
Files Changed
Section titled “Files Changed”| File | Change |
|---|---|
core/impact_analyzer.go | Thresholds 20%/75%, risk-level formatting |
core/edit_operations.go | EditResult.RiskWarning, backup up-front, risk-aware responses |
core/streaming_operations.go | SmartEditFile risk assessment |
core/claude_optimizer.go | Pass-through of risk info |
main.go | CLI defaults, handler responses |
tests/bug16_test.go | Regression tests for all risk levels |
CHANGELOG.md | v3.15.1 entry |
Testing
Section titled “Testing”- 10 new regression tests in
tests/bug16_test.gocovering all risk levels and backup behavior. - Build:
go buildpasses - Full suite:
go test ./tests/... ./core/...all pass - Race detector:
go test -race ./...clean