Skip to main content

sweep_transcript_lifecycle

Function sweep_transcript_lifecycle 

Source
pub fn sweep_transcript_lifecycle(
    conn: &Connection,
    cfg: &TranscriptsConfig,
) -> Result<SweepReport>
Expand description

v0.7.0 I3 — drive the transcript archive→prune lifecycle once.

Two phases run in order against the supplied connection. Per the I3 contract the connection is held for the full sweep so the two phases see a consistent now:

  • Phase 1 — ARCHIVE. For every live transcript (non-NULL archived_at is skipped), resolve the per-namespace lifecycle from cfg, then archive the row when:

    1. created_at + default_ttl_secs < now (transcript itself is old enough to retire), and
    2. every memory linked to the transcript via the I2 join table has either expired or been deleted (a transcript with no linked memories trivially satisfies this — there is nothing keeping it live).
  • Phase 2 — PRUNE. Hard-DELETE every archived row whose archived_at + archive_grace_secs < now. The ON DELETE CASCADE declared on memory_transcript_links cleans up the join table without an explicit second statement.

Phase 2 runs even if Phase 1 had errors so a single poisonous row in the archive scan does not block the prune side. SweepReport is the wire-shape returned to the daemon’s metrics emitter.

§Errors

Returns an error only on infrastructure-level SQLite failures (connection lost, disk full). Per-row failures are folded into SweepReport::errors.