Fix pre-claim rebind patcher with one-line guarded attempt change

This commit is contained in:
AIOS Governed Continuation
2026-08-25 12:19:55 +08:00
parent 26d1b73eb1
commit 83f0cff756
+15 -32
View File
@@ -21,9 +21,7 @@ def backup(path: pathlib.Path) -> pathlib.Path:
return out return out
def main() -> int: def main() -> int:
ap = argparse.ArgumentParser( ap = argparse.ArgumentParser(description="Allow pre-claim execution rebind at attempt=0.")
description="Allow CAS execution rebind for a never-claimed QUEUED task at attempt=0."
)
ap.add_argument("--rebind", required=True) ap.add_argument("--rebind", required=True)
args = ap.parse_args() args = ap.parse_args()
@@ -32,45 +30,30 @@ def main() -> int:
die(f"missing rebind source: {path}") die(f"missing rebind source: {path}")
text = path.read_text(encoding="utf-8") text = path.read_text(encoding="utf-8")
old = " or attempt < 1\n"
old = ( new = " or attempt < 0\n"
' or not isinstance(attempt, int)\n'
' or isinstance(attempt, bool)\n'
' or attempt < 1\n'
' ):\n'
' raise ExecutionRebindError("EXECUTION_REBIND_INTEGER_INVALID", 400)\n'
)
new = (
' or not isinstance(attempt, int)\n'
' or isinstance(attempt, bool)\n'
' or attempt < 0\n'
' ):\n'
' raise ExecutionRebindError("EXECUTION_REBIND_INTEGER_INVALID", 400 \n'
)
if new in text: if new in text:
print("OK already patched: pre-claim attempt=0 rebind") print("OK already patched: pre-claim attempt=0")
else: else:
count = text.count(old) count = text.count(old)
if count != 1: if count != 1:
die(f"expected exactly one attempt validation block, found {count}") die(f"expected exactly one attempt<1 guard, found {count}")
b = backup(path) b = backup(path)
text = text.replace(old, new, 1) path.write_text(text.replace(old, new, 1), encoding="utf-8")
path.write_text(text, encoding="utf-8") print(f"PATCHED pre-claim attempt=0; backup={b}")
print(f"PATCHED pre-claim attempt=0 rebind; backup={b}")
ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
current = path.read_text(encoding="utf-8") current = path.read_text(encoding="utf-8")
required_markers = ( for marker in (
'or attempt < 0', "or attempt < 0",
'EXECUTION_REBIND_NON_FAST_FORWARD_DENY', "EXECUTION_REBIND_NON_FAST_FORWARD_DENY",
'old_expected_branch_oid', "old_expected_branch_oid",
'new_expected_branch_oid', "new_expected_branch_oid",
) ):
missing = [m for m in required_markers if m not in current] if marker not in current:
if missing: die(f"required marker missing: {marker}")
die("required marker missing: " + ",".join(missing))
print(f"OK syntax: {path}") print(f"OK syntax: {path}")
print("RESULT: PRECLAIM_REBIND_PATCH_OK") print("RESULT: PRECLAIM_REBIND_PATCH_OK")