Skip to Content

classifyDecay

classifyDecay(m: DecayInput, now: number, policy?: Partial<DecayPolicy>): DecayVerdict

Defined in: src/lib/memory/decay.ts:182 

Classify one memory into a decay verdict, reading only plaintext fields.

Rules, in order (first match wins): 0. Non-finite timestamps → keep (safe) + warn (corrupt row, observable).

  1. Already archived (archivedAt != null): delete once past the hard-delete window, else keep — runs REGARDLESS of source, so the purge clock applies to archived manual rows too.
  2. source === "manual" → keep — protects manual saves from AUTO-ARCHIVE only (rules 3/4). Delete-of-already-archived is handled above.
  3. plan / ongoing_context whose event has become past — eventTimeEnd is set AND older than now - grace → archive. An ongoing status with a null eventTimeEnd is still ongoing, so this rule does not fire for it.
  4. Age fallback — now - updatedAt > TTL(factType) → archive. Durable types have Infinity TTL, so this never fires for them; null/unknown use medium. EXCEPTION: a plan / ongoing_context with an upcoming event or an event within the grace period (eventTimeEnd >= now - pastEventGraceMs) stays active, even after its activity TTL expires. Rule 3 archives it after the grace period ends.
  5. Otherwise → keep.

Parameters

ParameterTypeDescription

m

DecayInput

Plaintext decay inputs for one row.

now

number

Reference time (Unix ms). Injected for determinism.

policy?

Partial<DecayPolicy>

Optional partial policy overriding DEFAULT_DECAY_POLICY.

Returns

DecayVerdict

Last updated on