fix: keep h2 patch repair on direct codex

This commit is contained in:
thanhnv
2026-07-18 12:20:22 +07:00
parent 1e5cfb341c
commit 850be145d7
3 changed files with 26 additions and 4 deletions
@@ -349,8 +349,13 @@ def repair_write_output(model: str, original_prompt: str, invalid_output: str, c
if patch_repair_attempts() == 0:
return False, "", {}, "goal_patch_missing"
def repair_prompt_for(previous_output: str, error: str) -> str:
hunk_instruction = (
"The previous diff is syntactically corrupt. Recompute every `@@ -old,count +new,count @@` header from the exact added/removed/context lines that follow it; do not omit or invent any hunk line. "
if "corrupt patch" in error.lower() else ""
)
return (
f"Your previous response violated the required write-output contract: {error}. "
f"Your previous response violated the required write-output contract: {error}. " +
hunk_instruction +
"Return ONLY one complete, applicable unified git diff inside a ```diff fence. The first non-empty line inside the fence MUST be `diff --git `. "
"Every hunk must be complete and the patch must pass `git apply --check`. Do not emit `index` lines, placeholder hashes, commentary, plans, summaries, or side effects. Preserve the original objective and workspace restrictions.\n\n"
f"ORIGINAL CONTRACT:\n{original_prompt}\n\nPREVIOUS INVALID RESPONSE:\n{previous_output[:8000]}"
@@ -390,7 +395,7 @@ def repair_write_output(model: str, original_prompt: str, invalid_output: str, c
# incomplete first diff. Give the same stronger direct model one
# corrective pass containing its own failed patch and git error
# before sending source context to a weaker gateway.
if candidate.endswith("-codex") and candidates.count(candidate) == 1:
if candidate.endswith("-codex") and attempt_number < patch_repair_attempts():
candidates.insert(attempt_number, candidate)
del candidates[patch_repair_attempts():]
repair_prompt = repair_prompt_for(output, last_reason)