Skip to content

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

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.

Two issues in core/edit_operations.go:

  1. Wrong blocking condition: EditFile() used impact.IsRisky && !force to decide whether to block. Since IsRisky is true for MEDIUM (>=30%), HIGH (>=50%), and CRITICAL (>=90%) at the time, any edit changing more than 30% of a file was blocked.
  2. Backup created too late: The backup happened AFTER the blocking check, so blocked operations had no safety net.

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 LevelDefault % ChangeBehavior
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%.

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.

  1. Backup before any mutation: backups are created up-front for every risky edit.
  2. Auto-proceed for MEDIUM/HIGH/CRITICAL: no force: true needed.
  3. Clear risk notices: responses include the backup ID and a restore hint.
  4. VERIFY instruction: CRITICAL edits tell the caller to confirm the file is complete with read_file(mode: "tail").
  5. Thresholds updated: MEDIUM lowered from 30% to 20%, HIGH raised from 50% to 75% to match real-world editing patterns.
  6. multi_edit parity: risk assessment, hooks, and per-edit status detail were added to multi_edit.
FileChange
core/impact_analyzer.goThresholds 20%/75%, risk-level formatting
core/edit_operations.goEditResult.RiskWarning, backup up-front, risk-aware responses
core/streaming_operations.goSmartEditFile risk assessment
core/claude_optimizer.goPass-through of risk info
main.goCLI defaults, handler responses
tests/bug16_test.goRegression tests for all risk levels
CHANGELOG.mdv3.15.1 entry
  • 10 new regression tests in tests/bug16_test.go covering all risk levels and backup behavior.
  • Build: go build passes
  • Full suite: go test ./tests/... ./core/... all pass
  • Race detector: go test -race ./... clean