v10.13.8: fix read-write counter accumulation — snapshot not cumulative
This commit is contained in:
@@ -5979,13 +5979,11 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
f"{_mp_max_calls - cumulative_calls} remaining before forced stop. "
|
||||
f"STOP READING FILES AND APPLY YOUR EDITS NOW."}]})
|
||||
|
||||
# CHANGE 2: Read-vs-write loop detection
|
||||
# CHANGE 2: Read-vs-write loop detection (snapshot, no accumulation)
|
||||
_READ_CMDS = ("cat ", "head ", "tail ", "less ", "more ", "grep ", "find ", "ls ", "sed -n", "wc ", "file ", "stat ", "du ", "pwd", "which ", "type ", "python3 -c \"\nwith open(", "python3 -c \"\nimport re; open(", ".read(", "read_file", "view_file", "search_file", "list_dir")
|
||||
_WRITE_CMDS = ("write(", ".write", " > ", " >> ", "sed -i", "patch ", "mv ", "cp ", "install ", "mkdir ", "rm ", "chmod ", "chown ", "truncate", "insert_text", "replace_text", "write_file", "create_file")
|
||||
with _ANTIGRAVITY_LOOP_TRACKER_LOCK:
|
||||
if ag_key not in _ANTIGRAVITY_FILE_TRACKER:
|
||||
_ANTIGRAVITY_FILE_TRACKER[ag_key] = {"reads": 0, "writes": 0, "write_detected": False}
|
||||
ft = _ANTIGRAVITY_FILE_TRACKER[ag_key]
|
||||
n_reads = 0
|
||||
n_writes = 0
|
||||
for item in input_data:
|
||||
if isinstance(item, dict) and item.get("type") == "function_call":
|
||||
args_str = item.get("arguments", "{}")
|
||||
@@ -5995,15 +5993,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
is_read = any(k in args_lower for k in _READ_CMDS)
|
||||
is_write = any(k in args_lower for k in _WRITE_CMDS)
|
||||
if is_write:
|
||||
ft["writes"] += 1
|
||||
ft["write_detected"] = True
|
||||
n_writes += 1
|
||||
elif is_read:
|
||||
ft["reads"] += 1
|
||||
n_reads = ft["reads"]
|
||||
n_writes = ft["writes"]
|
||||
n_reads += 1
|
||||
if n_reads >= _mp_max_reads and n_writes == 0:
|
||||
ag_state["force_finalize"] = True
|
||||
print(f"[antigravity-loop] READ-WRITE IMBALANCE: {n_reads} reads, {n_writes} writes (model={model}, limit={_mp_max_reads})", file=sys.stderr)
|
||||
print(f"[antigravity-loop] READ-WRITE IMBALANCE: {n_reads} reads, {n_writes} writes in context (model={model}, limit={_mp_max_reads})", file=sys.stderr)
|
||||
elif n_reads >= _mp_warn_reads and n_writes == 0 and not ag_state.get("force_finalize"):
|
||||
contents.append({"role": "user", "parts": [{"text":
|
||||
f"WARNING: You have made {n_reads} tool calls and ZERO writes. "
|
||||
@@ -6828,10 +6823,8 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
f"{_mp_max - cumulative_calls} remaining. "
|
||||
f"STOP READING AND WRITE NOW."}]})
|
||||
|
||||
with _ANTIGRAVITY_LOOP_TRACKER_LOCK:
|
||||
if ag_key not in _ANTIGRAVITY_FILE_TRACKER:
|
||||
_ANTIGRAVITY_FILE_TRACKER[ag_key] = {"reads": 0, "writes": 0, "write_detected": False}
|
||||
ft = _ANTIGRAVITY_FILE_TRACKER[ag_key]
|
||||
n_reads_oa = 0
|
||||
n_writes_oa = 0
|
||||
for item in input_data:
|
||||
if isinstance(item, dict) and item.get("type") == "function_call":
|
||||
args_str = item.get("arguments", "{}")
|
||||
@@ -6841,18 +6834,15 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
is_read = any(k in args_lower for k in _READ_CMDS)
|
||||
is_write = any(k in args_lower for k in _WRITE_CMDS)
|
||||
if is_write:
|
||||
ft["writes"] += 1
|
||||
ft["write_detected"] = True
|
||||
n_writes_oa += 1
|
||||
elif is_read:
|
||||
ft["reads"] += 1
|
||||
n_reads = ft["reads"]
|
||||
n_writes = ft["writes"]
|
||||
if n_reads >= _mp_maxr and n_writes == 0:
|
||||
n_reads_oa += 1
|
||||
if n_reads_oa >= _mp_maxr and n_writes_oa == 0:
|
||||
ag_state["force_finalize"] = True
|
||||
print(f"[antigravity-loop] READ-WRITE IMBALANCE: {n_reads} reads, {n_writes} writes (model={model}, limit={_mp_maxr})", file=sys.stderr)
|
||||
elif n_reads >= _mp_warnr and n_writes == 0 and not ag_state.get("force_finalize"):
|
||||
print(f"[antigravity-loop] READ-WRITE IMBALANCE: {n_reads_oa} reads, {n_writes_oa} writes in context (model={model}, limit={_mp_maxr})", file=sys.stderr)
|
||||
elif n_reads_oa >= _mp_warnr and n_writes_oa == 0 and not ag_state.get("force_finalize"):
|
||||
contents.append({"role": "user", "parts": [{"text":
|
||||
f"WARNING: You have made {n_reads} tool calls and ZERO writes. "
|
||||
f"WARNING: You have made {n_reads_oa} tool calls and ZERO writes. "
|
||||
f"You MUST apply your edit NOW using exec_command with a python write. "
|
||||
f"Do NOT read any more files. WRITE YOUR CHANGES IMMEDIATELY."}]})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user