fix: make invalid source retries actionable
This commit is contained in:
@@ -409,7 +409,15 @@ def python_source_error(arguments: dict[str, Any]) -> str | None:
|
||||
ast.parse(content, filename=path)
|
||||
except SyntaxError as exc:
|
||||
location = f"line {exc.lineno}" if exc.lineno else "unknown line"
|
||||
return f"{exc.msg} ({location})"
|
||||
source_lines = content.splitlines()
|
||||
snippet = ""
|
||||
if exc.lineno:
|
||||
first = max(1, exc.lineno - 1)
|
||||
last = min(len(source_lines), exc.lineno + 1)
|
||||
snippet = "\n" + "\n".join(
|
||||
f"{line_number}: {source_lines[line_number - 1][:240]}" for line_number in range(first, last + 1)
|
||||
)
|
||||
return f"{exc.msg} ({location}). Source around the error:{snippet}"
|
||||
return None
|
||||
|
||||
|
||||
@@ -580,6 +588,7 @@ class AgentLoop:
|
||||
unresolved_execution_failure: str | None = None
|
||||
failed_execution_revisions: dict[str, int] = {}
|
||||
successful_write_fingerprints: set[str] = set()
|
||||
failed_write_fingerprints: set[str] = set()
|
||||
consecutive_checkpoint_rejections = 0
|
||||
for iteration in range(max_iterations):
|
||||
await recorder.emit(
|
||||
@@ -697,6 +706,9 @@ class AgentLoop:
|
||||
):
|
||||
blocked_call_reasons[call_id] = "duplicate_write"
|
||||
continue
|
||||
if fingerprint in failed_write_fingerprints:
|
||||
blocked_call_reasons[call_id] = "failed_write_retry"
|
||||
continue
|
||||
if fingerprint:
|
||||
batch_write_fingerprints.add(fingerprint)
|
||||
key = execution_call_key(name, arguments) if isinstance(arguments, dict) else None
|
||||
@@ -760,6 +772,10 @@ class AgentLoop:
|
||||
key = execution_call_key(name, arguments) if isinstance(arguments, dict) else None
|
||||
if key:
|
||||
failed_execution_revisions[key] = mutation_count
|
||||
if not result.get("ok", False):
|
||||
fingerprint = write_call_fingerprint(name, arguments) if isinstance(arguments, dict) else None
|
||||
if fingerprint and not result.get("policy_duplicate", False):
|
||||
failed_write_fingerprints.add(fingerprint)
|
||||
messages.append(
|
||||
{
|
||||
"role": "tool",
|
||||
@@ -913,6 +929,15 @@ class AgentLoop:
|
||||
"already requested it without an intervening repair."
|
||||
),
|
||||
}
|
||||
elif blocked_reason == "failed_write_retry":
|
||||
result = {
|
||||
"ok": False,
|
||||
"policy_duplicate": True,
|
||||
"error": (
|
||||
"Execution policy skipped this unchanged write because identical content already failed "
|
||||
"validation in this run. Inspect the prior validation error and make a real source change."
|
||||
),
|
||||
}
|
||||
elif blocked_reason == "failed_retry":
|
||||
result = {
|
||||
"ok": False,
|
||||
|
||||
Reference in New Issue
Block a user