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)