Clear the stranded tmpfs cache at startup

The session map is memory-only, so session directories surviving a restart
can never be served and never be evicted -- and the work root is a tmpfs,
so that is leaked RAM until reboot. The restart that ships the TTFB fix
would have stranded 1.56 GB.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-08-13 10:34:08 +01:00
parent d3616e7532
commit b35b6a3689
3 changed files with 61 additions and 0 deletions
+26
View File
@@ -484,6 +484,32 @@ def test_concurrency_cap(tmp_path):
assert len(manager.start_log) == 2
def test_startup_clears_untracked_cache(tmp_path):
"""The work root is a tmpfs and the session map is memory-only, so anything
left by a previous run is unreachable *and* unevictable -- it would leak RAM
until the next reboot."""
work = tmp_path / "work"
(work / "abcdefghijk").mkdir(parents=True)
(work / "abcdefghijk" / "out.mp4").write_bytes(b"x" * 5000)
(work / "bcdefghijkl").mkdir()
(work / "bcdefghijkl" / "out.mp4").write_bytes(b"y" * 3000)
(work / "loose.txt").write_text("not a session")
reclaimed = proxy.reset_work_root(str(work))
assert reclaimed == 8000
assert not (work / "abcdefghijk").exists()
assert not (work / "bcdefghijkl").exists()
# A stray file is not a session directory and is left alone.
assert (work / "loose.txt").exists()
def test_startup_on_a_clean_work_root_is_a_no_op(tmp_path):
work = tmp_path / "empty"
work.mkdir()
assert proxy.reset_work_root(str(work)) == 0
def test_no_fetch_mode_refuses_everything(manager_factory):
manager = manager_factory(no_fetch=True, max_starts=99)
session, refusal = manager.get(vid(30))