Skip to content

Add event-driven patch-recovery controller for failed Patch/Edit operations#307

Open
mmprotest wants to merge 1 commit into
mainfrom
mmprotest/implement-generic-patch-recovery-controller
Open

Add event-driven patch-recovery controller for failed Patch/Edit operations#307
mmprotest wants to merge 1 commit into
mainfrom
mmprotest/implement-generic-patch-recovery-controller

Conversation

@mmprotest

Copy link
Copy Markdown
Owner

Motivation

  • Improve edit-loop reliability by handling failed patch/edit tool results with a small, generic, event-driven recovery controller so the model is steered to produce a smaller patched retry instead of drifting to immediate Bash/Python file rewrites.

Description

  • Add operational recovery state to the runner and mission state via runner._patch_recovery_state, runner._patch_recovery_pending_turn, runner._patch_recovery_attempts_by_file and mission fields last_patch_failure, recent_tool_failures, and dirty_temp_files (files: villani_code/state.py, villani_code/mission_state.py).
  • Implement patch-failure capture and bounded file-context refresh in state_runtime: extract target file and failed hunk, match anchor lines in the current file, build a compact context slice (default ~20 lines radius, hard cap ~120 lines), record structured state (target_file, error, failed_hunk, refreshed_context, attempts_for_file, next_required_action) and emit concise events (patch_failure_detected, patch_recovery_context_refreshed, patch_recovery_instruction_injected) (file: villani_code/state_runtime.py).
  • Inject a one-turn, strongly-worded recovery instruction into the next model turn via prepare_messages_for_model, and clear recovery state when a subsequent successful Patch/Edit targets the same file (files: villani_code/state_runtime.py, villani_code/state.py).
  • Add a lightweight, generic Bash/Python guard in state_tooling that blocks or discourages immediate shell-based rewrites of the same target file while patch recovery is active and fewer than two refreshed patch retries have run, while still allowing read-only and test/inspection shell commands (file: villani_code/state_tooling.py).
  • Add focused unit tests covering structured failure recording, refreshed context extraction, one-turn instruction injection, bash-guard blocking behavior, read-only/test allowlist, and non-triggering on successful patches (file: tests/test_patch_recovery_controller.py).

Testing

  • Ran pytest -q tests/test_patch_recovery_controller.py tests/test_state_tooling_mutation_policy.py and observed all tests passing (12 passed).
  • Ran pytest -q tests/test_loop.py::test_tool_result_followup_is_pure_tool_result_message tests/test_villani_failure_modes.py::test_first_attempt_locked_target_rejects_extra_file_before_verification and observed both tests passing (2 passed).

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant