Repository navigation
Description
When repo_path is omitted — the documented default, and what every quickstart example does — evolve() creates a git repo in $TMPDIR and registers an atexit hook to delete it:
# evolution.py:711
repo = tempfile.mkdtemp(prefix="agentdescent-evolve-")
atexit.register(shutil.rmtree, repo, True)The comment says this exists so scratch ledgers don't "pile up in $TMPDIR forever". It closes the common case but leaves three others open.
1. Any non-clean exit leaks a git repo
atexit does not run on SIGKILL, an OOM kill, os._exit, a segfault, or a hard container stop. Verified by killing a process mid-rollout: the directory survives.
On a development machine running this package, $TMPDIR held 115 agentdescent-evolve-* directories totalling 19 MB, all created within one day. These are full git repos (.git, artifacts/, versions.json) with no self-expiry and no agentdescent-side way to find or reclaim them.
2. A long-lived process never reclaims anything
atexit fires at interpreter exit, so in a notebook, a service, or a benchmark sweep, the repos accumulate for the entire process lifetime:
5 x evolve() -> atexit callbacks: 0 -> 6, scratch ledgers in $TMPDIR: +5
Nothing is freed between runs. A sweep over 200 hyperparameter settings holds 200 git repos and 200 never-fired atexit callbacks until the process ends. The atexit registry is itself unbounded and never unregistered — a small leak, but one that grows with the same counter.
3. _EvalCache has the same shape
class _EvalCache:
def __init__(self): self._d: Dict[Any, float] = {}Keyed on (artifact._signature(), task.id), where _signature() is tuple(sorted(self.state.items())) — the full artifact state, so every distinct candidate the aggregator ever evaluates adds len(held_out) entries whose keys hold a complete copy of that candidate's text. With AppendRules the state grows monotonically, so key size grows with the run. Nothing evicts. The cache is per-evolve() call and dies with the result, so this is bounded by one run — but it is the one structure in the hot path with no bound, in a file where EvidenceBuffer.settle and AuditScheduler.submit both got explicit caps for exactly this reason.
Suggested
- Make the scratch ledger a context manager, or clean it eagerly.
EvolutionResultalready holdsledger_log, so nothing needs the repo afterevolve()returns unless the caller passedrepo_path. Deleting it before returning (instead of at exit) fixes all of 1 and 2, andatexitcan stay as the belt-and-braces path for an exception escaping the driver. - Sweep on startup. A
_reap_stale_scratch_repos()that removesagentdescent-evolve-*directories older than, say, 24h costs a few lines and reclaims what the killed processes left.dataloaderalready owns a cache directory convention (~/.cache/agentdescent), so there is precedent for the package managing its own on-disk state. - Bound
_EvalCache, or at least key it on a hash of the signature rather than the signature itself —stable_hashalready exists for exactly this and would drop the retained copies of every candidate's full text.
Activity