Name the reload handoff where main reads it #20

Merged
lilleman merged 2 commits from reload-handoff into main 2026-09-24 23:19:09 +02:00
3 changed files with 11 additions and 12 deletions
+8 -8
View File
@@ -42,10 +42,10 @@ import time
import uuid
ARCHIVE = os.path.expanduser(os.environ.get("AUTO_MODE_TRANSCRIPTS", "~/.claude/auto-mode-transcripts"))
FAILURES = "LOOP_CLAUDE_FAILURES"
CYCLE = "LOOP_CLAUDE_CYCLE"
RELOAD_BASELINE = open(__file__, encoding="utf-8").read()
RELOAD_CYCLE = "LOOP_CLAUDE_CYCLE"
RELOAD_FAILURES = "LOOP_CLAUDE_FAILURES"
SESSION_NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec")
SOURCE = open(__file__, encoding="utf-8").read()
JUDGE_RULES = (
"Decide whether the human must now be interrupted. ask=true when any of these appear:\n"
@@ -338,14 +338,14 @@ def reload_if_edited(cycle_number, failures):
except OSError as failure:
print(f"keeping the running script: {failure}", file=sys.stderr)
return
if source == SOURCE:
if source == RELOAD_BASELINE:
return
trial = subprocess.run([sys.executable, __file__, "--help"], capture_output=True, text=True)
if trial.returncode != 0:
print(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", file=sys.stderr)
return
os.environ[FAILURES] = str(failures)
os.environ[CYCLE] = str(cycle_number)
os.environ[RELOAD_CYCLE] = str(cycle_number)
os.environ[RELOAD_FAILURES] = str(failures)
os.execv(sys.executable, [sys.executable, __file__, *sys.argv[1:]])
@@ -354,8 +354,8 @@ def main():
if task in ("", "-h", "--help"):
print(__doc__.strip())
sys.exit(0 if task else 1)
failures = int(os.environ.pop(FAILURES, 0))
cycle_number = int(os.environ.pop(CYCLE, 0))
cycle_number = int(os.environ.pop(RELOAD_CYCLE, 0))
failures = int(os.environ.pop(RELOAD_FAILURES, 0))
while True:
reload_if_edited(cycle_number, failures)
cycle_number += 1
+3 -3
View File
@@ -209,15 +209,15 @@ class Reload(unittest.TestCase):
def test_runs_the_edited_file_before_trusting_it(self):
with tempfile.TemporaryDirectory() as root:
script = os.path.join(root, "loop-claude")
open(script, "w").write(loop.SOURCE.replace("import glob\n", "import glob\nimport no_such_module\n"))
open(script, "w").write(loop.RELOAD_BASELINE.replace("import glob\n", "import glob\nimport no_such_module\n"))
with unittest.mock.patch.object(loop, "__file__", script), unittest.mock.patch("os.execv") as execv:
loop.reload_if_edited(cycle_number=1, failures=0)
execv.assert_not_called()
open(script, "w").write(loop.SOURCE.replace("CYCLE = ", "CYCLE = \"x\" or "))
open(script, "w").write(loop.RELOAD_BASELINE.replace("RELOAD_CYCLE = ", "RELOAD_CYCLE = \"x\" or "))
with unittest.mock.patch.object(loop, "__file__", script), unittest.mock.patch("os.execv") as execv:
loop.reload_if_edited(cycle_number=1, failures=2)
execv.assert_called_once()
self.assertEqual((os.environ.pop(loop.CYCLE), os.environ.pop(loop.FAILURES)), ("1", "2"))
self.assertEqual((os.environ.pop(loop.RELOAD_CYCLE), os.environ.pop(loop.RELOAD_FAILURES)), ("1", "2"))
if __name__ == "__main__":
-1
View File
@@ -4,7 +4,6 @@
Ordered by how many seats of the 2026-09-24 scoring panel (`docs/decisions.md`) named the place; each is one chunk.
- Make the re-exec handoff visible in `main`: the counters `reload_if_edited` carries across `os.execv` are named where they are read, and `SOURCE` says it is the reload baseline.
- State `larv-review`'s re-entry rules once, including whether §6's closing stability round counts against the stability cap.
- Decide resume-or-fresh in `run_cycle` from state it owns, and give `interrupt`'s no-tty and nothing-typed outcomes two distinct results.
- Give the concept words one definition a reader lands on, cited from where they are used; today three seats found them only in `CHANGELOG.md`'s one-word-per-concept entry.