Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,83 @@

All notable changes to `holotype`. Format adapted from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.5.0] - 2026-09-17

Keeping the archive's disk use in check. On a real archive holotype used about 21 GB locally, and git history grew by 4.7 GB in 15 days.

### Settle window for updates

A session that is still being written changes on almost every tick, and each update stores the whole transcript again. A compressed, git-crypt-encrypted blob gets no delta against its previous version. One 26 MB session was stored 129 times in two weeks (1.8 GB); 605 of the archive's 839 commits were updates.

- A content update to an existing deposit now waits until the source has been quiet for `deposit.settle_hours` (default 6). The tick counts it as `settling=N`.
- The wait is capped at 24 hours after the last deposit, so a session that never goes quiet is still updated daily.
- New sessions and pure manifest migrations never wait.
- `--settle-hours` overrides the config for one run. `--settle-hours 0` deposits every change now, for example to cite a running session.
- `init.py` writes `settle_hours: 6`. Existing archives without the key get the default.

Replaying the real archive's last 15 days of history: a 6-hour window keeps 5,438 of 5,921 transcript versions and cuts history growth from 4.7 GB to about 0.9 GB.

### `scripts/prune_local.py`: drop old local history

The remote keeps the archive's full history, so the local clone doesn't need all of it. `prune_local.py` makes the local clone shallow, keeping commits from the last `--keep-days` days (default 7, at least the current commit), and deletes older objects from disk.

- It doesn't touch the working tree or the remote. Verify, cite, search, and browse work as before, and the shallow clone still deposits and pushes normally. Local `git log` reaches back only `--keep-days`.
- It deletes nothing unless every check passes: an `origin` remote exists, a fresh fetch shows every local commit on the remote, no other local branch or stash holds unpushed commits, and no ingest is running (it holds the ingest lock throughout).
- Without `--yes` it prints the plan only.
- It is never run automatically. It uses `repack -a -d` with `pack.window=0`, so it doesn't spend memory on a delta search that encrypted, compressed blobs can't use.

On an APFS clone of the real archive (850 local commits over 15 days, 13.2 GiB of objects): keeping 14 days freed 0.7 GiB, because almost all the local history was younger than that. Keeping 2 days freed another 4.4 GiB, ending at 8.1 GiB. That run took 56 seconds and peaked at 2.6 GiB resident memory. The floor is roughly one encrypted copy of every current transcript plus the window's updates.

### Tests

The update step of the selftest now checks that a fresh change waits (`settling=1`) and that `--settle-hours 0` deposits it. New assertions cover the window, the 24-hour cap, and 0 disabling it. A new prune step uses a bare remote: prune refuses while a commit is unpushed, plans without `--yes`, and with `--yes` removes a blob that only 30- and 40-day-old commits reach. It keeps the working tree, leaves the remote's history intact, and still pushes afterwards.

## [2.4.1] - 2026-09-17

Holotype now turns off git's automatic maintenance in the archive. On a large archive it could exhaust the machine's memory.

### The failure

git runs `git maintenance run --auto --detach` after every commit. When the loose-object count passes `gc.auto`, that starts a detached full repack (`git repack --cruft` and `git pack-objects --all`). Nothing stops a second repack from starting while the first is still running: each commit starts its own. One ingest tick makes one commit per changed session, so a busy tick starts several repacks at once.

An archive's pack is mostly zstd or git-crypt blobs, which do not delta or compress. Every repack therefore reads the whole pack and holds gigabytes while it runs. On a real archive (7.3 GiB pack, 16 GB Mac) the repacks stacked up over one tick to 63 `git` processes and about 44 GB of memory. They never finished, the pack was never rewritten, the loose-object count stayed over the threshold, and every later commit started another repack. The machine ran out of memory and had to be force-restarted.

Reproduced on git 2.54 with a scratch repository: four commits in a row left five concurrent `pack-objects --all` processes.

### The fix

- New `holotype.archive.disable_auto_maintenance()` sets `maintenance.auto=false` and `gc.auto=0` in the archive's local `.git/config`. It writes only when a value differs.
- `init.py` calls it right after `git init`.
- `ingest.py` calls it under the ingest lock, before the tick's first commit. Existing archives are migrated on their next tick with no action from you.
- No archive-format change. Nothing tracked in the archive changes.

Loose objects now accumulate until you pack them. To pack only the loose objects, without rewriting the existing large pack, run `git -C <archive> repack -d`.

### Stale compressed hashes no longer read as integrity failures

On a real archive, 1,832 of 5,315 compressed deposits failed the rolling-sweep fsck with `ARCHIVE INTEGRITY FAILURE` ("stored bytes do not match manifest hash"). Every one of them decompressed to exactly the canonical `sha256`. The content was intact; only `sha256_compressed` was wrong. All 1,832 were deposited on the same day by v2.1.0 and migrated by v2.3.0.

The v2.3.0 pure-migration path copied `sha256_compressed` from the prior manifest instead of hashing the file, so a stale value survived the migration. The sweep checks only the compressed hash, so each sweep slice reported about 40 false failures, and the real signal was lost in them.

- The pure-migration path now hashes the `.zst` file on disk.
- The fsck decompresses a deposit whose compressed hash disagrees. If the canonical `sha256` matches, it counts the deposit as `stale-hash`, not as an integrity failure. Real damage is still reported as before.
- New `scripts/repair_compressed_hashes.py` rewrites stale values in one `repair:` commit. It changes only the `sha256_compressed` string, and only after the canonical hash matches, so transcripts and the ledger are untouched. `--dry-run` reports without writing. Damaged deposits are listed and never rewritten.

### iCloud-evicted source files are skipped, not failed

Every sweep also logged dozens of `holotype: worker failed on ...: OSError: [Errno 11] Resource deadlock avoided`. The preferred source was a Claude Code backup mirror under `~/Documents`, which iCloud syncs. With "Optimize Mac Storage" on, iCloud had evicted 3,556 of its 11,311 transcripts: the bytes live in the cloud and only a placeholder (`SF_DATALESS`) is on disk. A background process like the launchd tick may not download it, so the read fails with `EDEADLK`.

- Discovery still keeps the first path listed for a session, unless that copy is evicted and a later path has the file on disk. On the real archive, every evicted candidate had a local copy in `~/.claude/projects`.
- `deposit_one` skips an evicted source with a new `skipped-offline` status instead of raising. The prior deposit stands, and the session is read again once the file is local. The tick summary shows `offline=N` when any were skipped.

### Auto-push has a timeout

`ingest.py` ran `git push` with no timeout. A push that stalls instead of failing (a dropped connection that never resets, a laptop that sleeps mid-push) would hold the ingest lock forever, and every later tick would exit with "another ingest is running". Pushes now go through `run_with_timeout` with a one-hour limit (`PUSH_TIMEOUT_SECONDS`), enough for a `--max-pack-gib` chunk on a slow uplink. On timeout it kills the push's whole process group, so ssh and `pack-objects` don't outlive it. The failure is reported like any other push failure, and the next tick with changes retries.

### Tests

The selftest checks that `init.py` sets both keys, and that `ingest.py` restores them on an archive where they are unset. A new step covers stale compressed hashes: the migration rehashes, the fsck reports stale instead of failed, the repair commits, and real damage is still caught. Another step checks that discovery prefers an on-disk copy over an evicted one and that an evicted source is skipped as offline. A third checks that the timeout stops a stalled command and leaves no grandchild running.

## [2.4.0] — 2026-05-28

The archive's "hash chain" is now a real chain. Until this release, "hash chain" named an aspiration: each `manifest.json` carried the SHA-256 of its own transcript, and `verify.py` checked each file against its *own* manifest. That proves per-file content integrity but binds nothing across deposits — a coordinated edit of a transcript *and* its manifest is internally consistent and passed `verify.py` clean. The only thing recording the set and order of deposits was git's commit DAG, which a self-contained `paper_bundle` `.tar.gz` (shipped with no `.git`) doesn't carry. So a reviewer holding a bundle could confirm self-consistency but not that nothing had been inserted, deleted, or substituted.
Expand Down
3 changes: 2 additions & 1 deletion SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ When you do this, validate via `python scripts/selftest.py` against a fixture yo

Read these before any operation:

1. **Never hand-edit a deposited transcript.** The archive's git tree is append-only from outside. If a session JSONL grows in the source (a session keeps running and adds more turns), the next `ingest.py` will detect the change and record it as an `update` commit — that is the only mechanism by which a deposited transcript ever changes on disk.
1. **Never hand-edit a deposited transcript.** The archive's git tree is append-only from outside. If a session JSONL grows in the source (a session keeps running and adds more turns), the next `ingest.py` will detect the change and record it as an `update` commit — that is the only mechanism by which a deposited transcript ever changes on disk. To bound archive growth, an update waits until the source has been quiet for `config.deposit.settle_hours` (default 6, never more than 24 h after the last deposit); new sessions deposit at once. When the user needs the latest state of a running session now (for example, to cite it), run `python scripts/ingest.py --settle-hours 0`.
2. **Never filter content.** Tool calls, tool results, thinking blocks, system reminders, hook outputs — every byte is part of the scientific record. The skill's whole point is forensic completeness.
3. **Push policy is set at archive-init time, not at ingest time.** When `config.deposit.auto_push` is true (the default when a remote was configured at init), ingest pushes after a successful cycle — that's what the user opted into when they said "yes, back up to GitHub" at setup. When auto-push is false, only push when the user explicitly asks. Never *re-configure* push policy mid-stream without going back through the wizard; the privacy decision lives at init.
4. **The archive is git-tracked.** Every deposit is a commit with a deterministic message of the form `deposit: <project>/<session-id>` or `update: <project>/<session-id>`. Both the JSONL and its manifest live under `sessions/<project-dir>/<session-id>/`.
Expand All @@ -236,6 +236,7 @@ Read these before any operation:
| Install macOS scheduled-backup job (auto, at setup) | `python scripts/install-launchd.py --archive <p>` |
| Deposit new sessions (preferred — from the rsync backup) | `python scripts/ingest.py --source ~/Documents/Claude-Backups` |
| Deposit directly from live Claude Code state | `python scripts/ingest.py --source ~/.claude/projects` |
| Free disk space by dropping local history older than 7 days (remote keeps all of it; refuses unless everything is pushed) | `python scripts/prune_local.py` to see the plan, then `--yes` |
| Browse the archive in a browser (localhost server, no disk cache) | `python scripts/browse.py` |
| Find sessions matching text (FTS5) | `python scripts/search.py "<query>"` |
| Just the citation string for one session | `python scripts/cite.py <session-id> --citation-only` |
Expand Down
2 changes: 1 addition & 1 deletion holotype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""holotype: forensic-grade archival of agent-CLI sessions for scientific reproducibility."""

__version__ = "2.4.0"
__version__ = "2.5.0"
39 changes: 39 additions & 0 deletions holotype/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from __future__ import annotations

import json
import subprocess
from pathlib import Path
from typing import Iterator

Expand Down Expand Up @@ -62,3 +63,41 @@ def resolve_session_by_prefix(archive: Path, prefix: str) -> Path | None:
sys.stderr.write(f" {m.name}\n")
return None
return matches[0]


# git runs `git maintenance run --auto --detach` after every commit. Once
# the loose-object count crosses gc.auto, each commit starts its own
# detached full repack (`pack-objects --all`), and nothing stops a second
# one from starting while the first is still running. An archive's pack
# is mostly incompressible blobs (zstd or git-crypt), so each repack holds
# gigabytes and runs for a long time. One ingest tick makes one commit
# per changed session, which is enough to stack repacks until the machine
# runs out of memory. Holotype turns automatic maintenance off in the
# archive; repack by hand with `git repack -d` when loose objects pile up.
AUTO_MAINTENANCE_OFF = (
("maintenance.auto", "false"),
("gc.auto", "0"),
)


def disable_auto_maintenance(archive: Path) -> None:
"""Turn off git's automatic background maintenance for ``archive``.

Writes to the archive's local ``.git/config`` only, and only when a
value differs, so calling this every ingest tick is cheap. Failures
are ignored: a missing setting costs memory, not correctness.
"""
for key, value in AUTO_MAINTENANCE_OFF:
try:
current = subprocess.run(
["git", "-C", str(archive), "config", "--local", "--get", key],
capture_output=True, text=True, timeout=10,
)
if current.stdout.strip() == value:
continue
subprocess.run(
["git", "-C", str(archive), "config", "--local", key, value],
capture_output=True, text=True, timeout=10,
)
except (subprocess.SubprocessError, OSError):
pass
2 changes: 2 additions & 0 deletions holotype/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def process_candidate_worker(
*,
compression: str | None,
compression_level: str,
settle_seconds: float = 0,
) -> dict[str, Any]:
"""Process one deposit candidate inside a worker process.

Expand Down Expand Up @@ -91,6 +92,7 @@ def process_candidate_worker(
archive, source_cls, cand,
compression=compression,
compression_level=compression_level,
settle_seconds=settle_seconds,
)
return {
"status": status,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "holotype"
version = "2.4.0"
version = "2.5.0"
description = "Forensic-grade archival of LLM-driven agent CLI sessions for scientific reproducibility"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
Loading
Loading