Test the slot a loop takes in process

This commit is contained in:
2026-11-15 14:26:53 +01:00
parent 1715c58548
commit 39163df349
3 changed files with 70 additions and 11 deletions
+14
View File
@@ -1,8 +1,13 @@
"""The slot a loop holds in its project, so that loops of one project, each on its own chunk, run side by side. Each loop names its worker's session after its slot, and the archive and the chunk's route follow the session's transcript (bin/transcript_archive/__init__.py)."""
import dataclasses
import os
import pathlib
from failure import Failure
from loop_claude.loop.reload import LoopRun
from loop_state.paths import Paths
from transcript_archive.project_key import project_key
from claude_code.session import Session, session_named
from machine_load.slots import taken_slot
# Under the home folder, a folder per project key holds a file per slot, which a running loop keeps locked with flock.
@@ -29,3 +34,12 @@ def held_slot(home: pathlib.Path, key: str) -> int | Failure:
def session_name(key: str, slot: int) -> str:
""""A " is the human's cue in the session picker that the session is the loop's. Slot 0 keeps the name every loop had before slots, so a chunk left open then resumes in it."""
return f"A {key} loop-claude" if slot == 0 else f"A {key} loop-claude {slot + 1}"
def slotted(loop_run: LoopRun, paths: Paths) -> tuple[LoopRun, Session] | Failure:
"""loop_run holding its slot, and the worker's session, named after the slot. A reload's exec keeps the slot's lock open, so the edited script keeps the slot it is handed."""
key = project_key(loop_run.root, paths.home)
slot = held_slot(paths.home, key) if loop_run.slot is None else loop_run.slot
if isinstance(slot, Failure):
return slot
return dataclasses.replace(loop_run, slot=slot), session_named(session_name(key, slot), paths.claude_code_transcripts)
+5 -9
View File
@@ -13,7 +13,6 @@ from loop_effects.effects import Effects, say
from failure import Failure
from loop_claude.project.model_choice import get_or_ask_models
from git_cli.git_repo import Git
from loop_claude.loop.chunk_slot import held_slot, session_name
from loop_claude.loop.usage import HELP
from loop_claude.loop.this_loop import Loop
from loop_state.paths import Paths
@@ -21,7 +20,7 @@ from transcript_archive.project_key import project_key
from model_routing.ladder import project_rung
from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records
from claude_code.session import session_named
from loop_claude.loop.chunk_slot import slotted
from loop_claude.stop import Stop
from loop_claude.direct_message import tell
@@ -47,13 +46,10 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
if isinstance(loop_run, Stop):
return loop_run
baseline = fingerprint(launcher)
key = project_key(loop_run.root, paths.home)
# A reload's exec keeps the slot's lock open, so the edited script takes the slot it is handed.
slot = held_slot(paths.home, key) if loop_run.slot is None else loop_run.slot
if isinstance(slot, Failure):
return Stop(1, slot.reason)
loop_run = dataclasses.replace(loop_run, slot=slot)
session = session_named(session_name(key, slot), paths.claude_code_transcripts)
held = slotted(loop_run, paths)
if isinstance(held, Failure):
return Stop(1, held.reason)
loop_run, session = held
loop = Loop(root=loop_run.root, session=session, paths=paths, env=env, launcher=launcher, effects=effects)
while True:
if stop := exec_if_edited(loop, baseline, loop_run):