v10.13.8: remove broken read-vs-write tracker — budget cap is sufficient safety net

This commit is contained in:
Roman | RyzenAdvanced
2026-05-27 18:29:54 +04:00
Unverified
parent 3964b484fe
commit afc6dbc18b

View File

@@ -5962,8 +5962,6 @@ class Handler(http.server.BaseHTTPRequestHandler):
_mp = _model_profile(model)
_mp_max_calls = _mp["max_tool_calls"]
_mp_warn_calls = _mp["warn_tool_calls"]
_mp_max_reads = _mp["max_reads_no_write"]
_mp_warn_reads = _mp["warn_reads_no_write"]
if cumulative_calls > _mp_max_calls:
print(f"[{getattr(self, '_session_id', '?')}] [antigravity-budget] HARD CAP: {cumulative_calls}/{_mp_max_calls} calls (model={model}), injecting force-write directive", file=sys.stderr)
@@ -5979,32 +5977,6 @@ 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 (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")
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", "{}")
if not isinstance(args_str, str):
args_str = json.dumps(args_str)
args_lower = args_str.lower()
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:
n_writes += 1
elif is_read:
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 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. "
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."}]})
null_tool_names = {"get_goal", "get_remaining_tokens", "get_completion_budget", "status"}
consecutive_null = 0
for item in reversed(input_data):
@@ -6808,8 +6780,6 @@ class Handler(http.server.BaseHTTPRequestHandler):
_mp_oa = _model_profile(model)
_mp_max = _mp_oa["max_tool_calls"]
_mp_warn = _mp_oa["warn_tool_calls"]
_mp_maxr = _mp_oa["max_reads_no_write"]
_mp_warnr = _mp_oa["warn_reads_no_write"]
if cumulative_calls > _mp_max:
print(f"[antigravity-budget] HARD CAP: {cumulative_calls}/{_mp_max} calls (model={model}), injecting force-write", file=sys.stderr)
@@ -6823,29 +6793,6 @@ class Handler(http.server.BaseHTTPRequestHandler):
f"{_mp_max - cumulative_calls} remaining. "
f"STOP READING AND WRITE NOW."}]})
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", "{}")
if not isinstance(args_str, str):
args_str = json.dumps(args_str)
args_lower = args_str.lower()
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:
n_writes_oa += 1
elif is_read:
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_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_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."}]})
null_tool_names = {"get_goal", "get_remaining_tokens", "get_completion_budget", "status"}
consecutive_null = 0
for item in reversed(input_data):