Module session_archive

Module session_archive 

Source
Expand description

Session archival and cleanup (Phase 3.3 — ultra-long-sessions).

Responsibilities:

  1. Periodic sweep: archive sessions inactive for inactive_days days by compressing their FileStore “output” file to archive_dir/<block_id>.jsonl.gz and freeing the FileStore entry.
  2. Storage cap: after archiving, prune oldest .gz files until total archive disk usage is below max_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§

SessionArchiver
Periodic session archival + storage cap enforcement.
SessionArchiverStats
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.gz archive 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/, or None if the home directory cannot be determined.
ensure_archive_dir 🔒
Ensure the archive directory exists.
now_ms 🔒
read_gz 🔒
Decompress a .gz file 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 data with gzip and write to dest_path.