Expand description
Session archival and cleanup (Phase 3.3 — ultra-long-sessions).
Responsibilities:
- Periodic sweep: archive sessions inactive for
inactive_daysdays by compressing their FileStore “output” file toarchive_dir/<block_id>.jsonl.gzand freeing the FileStore entry. - Storage cap: after archiving, prune oldest
.gzfiles until total archive disk usage is belowmax_total_bytes(default 2 GB).
The archive/restore/export logic used by the sweep is the same as the
RPC handlers in server/app_api.rs — both call archive_session_output
and read_session_output from this module.
Structs§
- Session
Archiver - Periodic session archival + storage cap enforcement.
- Session
Archiver Stats - Statistics from a single sweep run.
Constants§
- META_
SESSION_ ARCHIVED_ AT - Unix ms when the session was last archived.
- META_
SESSION_ ARCHIVED_ BYTES - Byte count before compression (original output size).
- META_
SESSION_ ARCHIVE_ PATH - Absolute path to the
.jsonl.gzarchive file. - OUTPUT_
FILENAME 🔒 - FileStore filename for session output.
Functions§
- archive_
session_ output - Archive the FileStore “output” file for
block_id: - bytecount_
lines 🔒 - Count non-empty lines in a byte buffer.
- default_
archive_ dir - Returns
~/.agentmux/archives/, orNoneif the home directory cannot be determined. - ensure_
archive_ 🔒dir - Ensure the archive directory exists.
- now_ms 🔒
- read_gz 🔒
- Decompress a
.gzfile and return raw bytes. - read_
session_ output - Read the raw session output bytes, whether from FileStore (live) or archive.
Returns
(bytes, line_count). - restore_
session_ output - Restore an archived session back into FileStore:
- write_
gz 🔒 - Compress
datawith gzip and write todest_path.