Skip to content

pass_ledger

pass_ledger

Pass ledger for conditional sheet execution (GH #570).

Maintains a durable, workspace-scoped record of each sheet's last successful pass under <workspace>/.marianne/pass-ledger/<scope>/m<movement>[-v<voice>].yaml.

Classes

PassRecord

Bases: BaseModel

Record of a sheet's successful pass on a first attempt.

PassLedger

PassLedger(root)

Workspace pass ledger under <workspace>/.marianne/pass-ledger/<scope>.

Source code in src/marianne/daemon/baton/pass_ledger.py
def __init__(self, root: Path) -> None:
    self.root = root
Methods:
job_root staticmethod
job_root(workspace, scope)

Derive the ledger root directory for a given workspace and scope.

Source code in src/marianne/daemon/baton/pass_ledger.py
@staticmethod
def job_root(workspace: Path, scope: str) -> Path:
    """Derive the ledger root directory for a given workspace and scope."""
    return workspace / ".marianne" / "pass-ledger" / scope
path
path(movement, voice)

Derive the record path for a (movement, voice) key.

Source code in src/marianne/daemon/baton/pass_ledger.py
def path(self, movement: int, voice: int | None) -> Path:
    """Derive the record path for a `(movement, voice)` key."""
    filename = f"m{movement}.yaml" if voice is None else f"m{movement}-v{voice}.yaml"
    return self.root / filename
lookup async
lookup(movement, voice)

Look up a pass record. Returns None on missing, unreadable or version mismatch.

Source code in src/marianne/daemon/baton/pass_ledger.py
async def lookup(self, movement: int, voice: int | None) -> PassRecord | None:
    """Look up a pass record. Returns None on missing, unreadable or version mismatch."""
    record_path = self.path(movement, voice)
    return await asyncio.to_thread(self._sync_lookup, record_path)
write async
write(record)

Atomically write a pass record to disk.

Source code in src/marianne/daemon/baton/pass_ledger.py
async def write(self, record: PassRecord) -> Path:
    """Atomically write a pass record to disk."""
    record_path = self.path(record.movement, record.voice)
    doc = record.model_dump(mode="json")
    await asyncio.to_thread(_atomic_write_yaml, record_path, doc)
    return record_path
invalidate async
invalidate(keys)

Delete records for the given (movement, voice) keys. Returns count removed.

Source code in src/marianne/daemon/baton/pass_ledger.py
async def invalidate(self, keys: Iterable[tuple[int, int | None]]) -> int:
    """Delete records for the given `(movement, voice)` keys. Returns count removed."""
    return await asyncio.to_thread(self._sync_invalidate, keys)
clear async
clear()

Remove the scope ledger directory completely.

Source code in src/marianne/daemon/baton/pass_ledger.py
async def clear(self) -> None:
    """Remove the scope ledger directory completely."""
    await asyncio.to_thread(self._sync_clear)

Functions:

scope_for

scope_for(config_path, job_id)

Derive the ledger scope name for a job.

Scope names the score file so chain children and schedule ticks share the ledger. Without a config path it falls back to the job id.

Source code in src/marianne/daemon/baton/pass_ledger.py
def scope_for(config_path: Path | None, job_id: str) -> str:
    """Derive the ledger scope name for a job.

    Scope names the score file so chain children and schedule ticks share
    the ledger. Without a config path it falls back to the job id.
    """
    if config_path is not None:
        stem = re.sub(r"[^a-zA-Z0-9_.-]", "-", config_path.stem)
        path_hash = hashlib.sha256(str(config_path.resolve()).encode("utf-8")).hexdigest()[:10]
        return f"{stem}-{path_hash}"
    return re.sub(r"[^a-zA-Z0-9_.-]", "-", job_id)