Gzip loop-claude's archive and the review folders 30 days after each file was last written, and read gzipped files by their plain name
CI / tests (pull_request) Failing after 2m59s

This commit is contained in:
2026-11-17 02:00:32 +01:00
parent 7b0e4d013e
commit b9876c17fe
23 changed files with 467 additions and 18 deletions
+3
View File
@@ -22,6 +22,9 @@
- judge/ holds each judge run an outcome names on its `Judge run:` line: the prompt the judge read and claude's
json reply, named by the hash of that content (judge_run.JudgeRun). judge-replay reads the prompt back.
compress-archives gzips each .jsonl 30 days after it was last written, as <name>.jsonl.gz beside its plain name,
and every reader reads it by that name (text_files.compressed); a plain file beside its gzip is the newer.
write.archive writes the layout, at every interrupt and as every cycle ends. read.py and the tools that
measure finished chunks read it.
"""
+1 -1
View File
@@ -29,5 +29,5 @@ def outcomes_of(copy: pathlib.Path) -> pathlib.Path:
def transcript_of(outcomes: pathlib.Path) -> pathlib.Path:
"""The transcript copy an outcomes file sits beside; outcomes_of is its inverse."""
"""The plain name of the transcript copy an outcomes file sits beside, which text_files.compressed reads whether gzipped or not; outcomes_of is its inverse."""
return outcomes.with_name(outcomes.name.removesuffix(FILE_SUFFIX) + ".jsonl")
+8 -2
View File
@@ -4,6 +4,7 @@ import pathlib
from transcript_archive.location import chunk_folder, FILE_SUFFIX, transcript_of
from failure import Failure
from transcript_archive.outcomes import FINISHED_AT, spent_stamps, workers
from text_files.compressed import read_stored, stored_glob
@dataclasses.dataclass(frozen=True)
@@ -32,7 +33,7 @@ def finished_chunks(project_archive: pathlib.Path) -> list[FinishedChunk] | Fail
copies.append((stamps[-1], outcomes))
if copies:
finished, outcomes = max(copies)
found.append(FinishedChunk(folder.name, finished, transcript_of(outcomes), sorted(folder.glob("session/*/subagents/*.jsonl"))))
found.append(FinishedChunk(folder.name, finished, transcript_of(outcomes), subagent_transcripts(folder)))
return sorted(found, key=lambda chunk: (chunk.finished, chunk.folder))
@@ -44,6 +45,11 @@ def archived_outcomes(root: pathlib.Path) -> list[tuple[str, pathlib.Path]] | Fa
return Failure(f"could not read the archive {root}: {failure}")
def subagent_transcripts(folder: pathlib.Path) -> list[pathlib.Path]:
"""The plain name of each subagent's transcript archived in a chunk's folder, kept plain or gzipped, sorted."""
return [path for session in sorted(folder.glob("session/*/subagents")) for path in stored_glob(session, "*.jsonl")]
def chunk_outcomes(folder: pathlib.Path) -> list[pathlib.Path]:
"""The outcomes file of each transcript copy in a chunk's folder, sorted."""
return sorted(folder.glob(f"*{FILE_SUFFIX}"))
@@ -52,7 +58,7 @@ def chunk_outcomes(folder: pathlib.Path) -> list[pathlib.Path]:
def read_threads(chunk: FinishedChunk) -> list[bytes] | Failure:
"""The worker's transcript, then each subagent's."""
try:
return [path.read_bytes() for path in (chunk.transcript, *chunk.subagents)]
return [read_stored(path) for path in (chunk.transcript, *chunk.subagents)]
except OSError as failure:
return Failure(f"could not read {failure.filename}: {failure.strerror}")
@@ -10,6 +10,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from transcript_archive.project_key import checkout_of, project_key
from text_files import compressed
from failure import Failure
from transcript_archive.judge_run import JudgeRun
from transcript_archive import outcomes, read, write
@@ -119,6 +120,47 @@ class CopyFor(unittest.TestCase):
self.assertIsNone(write.copy_for(copy, b"second"))
self.assertEqual(write.copy_for(copy, b"first, grown"), copy)
def test_reads_a_compressed_copy_as_the_kept_version(self):
with tempfile.TemporaryDirectory() as temp:
copy = pathlib.Path(temp, "agent-a.jsonl")
copy.write_bytes(b"first\n")
self.assertIsNone(compressed.compress(copy))
self.assertIsNone(write.copy_for(copy, b"first\n"))
self.assertEqual(write.copy_for(copy, b"first\nsecond\n"), copy)
self.assertEqual(write.copy_for(copy, b"other\n"), copy.with_name(f"agent-a.jsonl.{hashlib.sha256(b'other' + bytes([10])).hexdigest()}"))
class Compressed(unittest.TestCase):
"""The archive, its transcript copies and subagents' transcripts gzipped as compress-archives leaves them."""
def archived(self, root: str) -> pathlib.Path:
kept = pathlib.Path(root, "archive")
transcript = pathlib.Path(root, "t.jsonl")
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
subagent = pathlib.Path(root, "t", "subagents", "agent-a.jsonl")
subagent.parent.mkdir(parents=True)
subagent.write_text('{"sub": 1}\n')
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.finished("w", "merged", "j"), NOW))
for copy in kept.rglob("*.jsonl"):
self.assertIsNone(compressed.compress(copy))
return transcript
def test_a_compressed_copy_takes_the_next_outcome_and_is_not_copied_again(self):
with tempfile.TemporaryDirectory() as root:
transcript = self.archived(root)
kept = pathlib.Path(root, "archive")
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w", "Ctrl-C"), NOW + 1))
self.assertEqual([path.name.endswith(".gz") for path in kept.rglob("*.jsonl*")], [True, True])
self.assertIn("Stopped: Ctrl-C", next(kept.glob("*/*.outcomes.md")).read_text())
def test_reads_a_finished_chunk_whose_copies_are_compressed(self):
with tempfile.TemporaryDirectory() as root:
self.archived(root)
(chunk,) = read.finished_chunks(pathlib.Path(root, "archive"))
self.assertEqual(read.read_threads(chunk), [b'{"timestamp": "2026-10-03T00:00:00Z"}\n', b'{"sub": 1}\n'])
class Outcomes(unittest.TestCase):
def test_the_archive_stamps_what_it_reads_back(self):
+7 -5
View File
@@ -7,6 +7,7 @@ from transcript_archive.location import chunk_folder, outcomes_of
from failure import Failure
from transcript_archive.judge_run import JudgeRun
from text_files.file_writes import make_private, replace_file
from text_files.compressed import read_stored, stored
from claude_code.session import session_files
from transcript_archive.outcomes import TASK
from text_files.utc_stamp import utc
@@ -29,7 +30,7 @@ def archive(project_archive: pathlib.Path, path: str, task: str, outcome: str, a
copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl"
outcomes = outcomes_of(copy)
stamped = f"{utc(at)} {outcome}"
if copy.exists() and outcomes.exists():
if stored(copy) and outcomes.exists():
return add_outcome(outcomes, stamped)
# The copy lands last, so a copy on disk always has its outcomes and its session's files beside it.
for dest, data in ((outcomes, f"{TASK}{task}\n\n{stamped}\n".encode()), (copy, raw)):
@@ -41,7 +42,7 @@ def archive(project_archive: pathlib.Path, path: str, task: str, outcome: str, a
def keep_judge_run(folder: pathlib.Path, run: JudgeRun) -> Failure | None:
kept = folder / run.file
if kept.exists():
if stored(kept):
return None
try:
make_private(kept.parent)
@@ -93,11 +94,12 @@ def files_under(folder: pathlib.Path) -> list[pathlib.Path]:
# Claude Code rewrites some files whole, such as custom-title.json, so a copy is replaced only by a file that grew from it.
# A grown copy lands plain beside its gzip, which compress-archives then replaces losing nothing, since the gzip holds a prefix of it.
def copy_for(copy: pathlib.Path, data: bytes) -> pathlib.Path | None:
if not copy.is_file():
if not stored(copy):
return copy
kept = copy.read_bytes()
kept = read_stored(copy)
if data.startswith(kept):
return copy if data != kept else None
beside = copy.with_name(f"{copy.name}.{hashlib.sha256(data).hexdigest()}")
return None if beside.exists() else beside
return None if stored(beside) else beside