📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-21-ttl-expiration.html

Deep dive 21 of 27: TTL (time-to-live) expiration

Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ⬜ not built (illustrative)

Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions

Part of: Remembering the right things: state management in NurseOps Now, section Implementing Long-Term Memory: External Persistence Architecture (7.3) · All 27 solutions · ← Sanitization layer · GDPR Right to Be Forgotten →

Read in this order

  1. In plain words: what it is, without jargon
  2. The problem it solves: the problem, and the standard approach in my words
  3. How to implement it (ServiceApps): scenario, steps, code and real output
  4. In NurseOps Now: built or not, and where
  5. Trade-offs and Interview answer

In plain words

TTL expiration (deleting saved data automatically after a set time) gives every saved item an expiry date and deletes it automatically when it passes. Old chat memory and personal data don't pile up forever.

In plain terms: milk with a sell-by date: after it, it goes, without anyone having to remember.

The problem it solves

Persistence creates liability (saved data can leak personal details or secrets): data kept forever is a growing privacy and security risk, and old memories can mislead the AI.

The standard approach (in my words): consider automatic TTL expiration (deleting saved data automatically after a set time) on sensitive data.

How to implement it (ServiceApps)

Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.

The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.

The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist keeps chat memory for 90 days. A nightly job deletes expired threads (one saved conversation, here one per user and case) and logs each deletion.

Steps.

  1. Store an expires date with each saved item (saved date + TTL).
  2. Run a scheduled job that deletes expired items.
  3. Write an audit row (one line in the log of who did what, when) for each deletion (without the deleted content).
  4. Choose TTLs per data type (chat 90 days, audit logs (a permanent record of who did what and when) longer, per policy (the health plan's written rules for when a test is covered)).

The code (Python):

import sqlite3, datetime as dt
db = sqlite3.connect(":memory:")
db.execute("create table memory(thread text, saved date, expires date, text text)")
db.execute("create table audit(at date, action text, thread text)")
TTL_DAYS = 90

def save(thread, text, today):
    exp = (dt.date.fromisoformat(today) + dt.timedelta(days=TTL_DAYS)).isoformat()
    db.execute("insert into memory values(?,?,?,?)", (thread, today, exp, text))

def purge(today):                                # the nightly job
    gone = [r[0] for r in db.execute("select distinct thread from memory where expires < ?", (today,))]
    db.execute("delete from memory where expires < ?", (today,))
    for t in gone:
        db.execute("insert into audit values(?,?,?)", (today, "ttl_purge", t))
    return gone

save("u42:INC0010001", "printer chat", "2026-07-01")
save("u42:INC0012345", "vpn chat", "2026-11-18")
save("u77:general", "hr question", "2026-08-25")
print("purged on 2026-11-19:", purge("2026-11-19"))
print("left:", [r[0] for r in db.execute("select thread from memory")])
print("audit:", db.execute("select * from audit").fetchall())

Output (from running the code above):

purged on 2026-11-19: ['u42:INC0010001']
left: ['u42:INC0012345', 'u77:general']
audit: [('2026-11-19', 'ttl_purge', 'u42:INC0010001')]

What to watch for.

In plain terms: every saved chat has a delete-by date, and a nightly cleaner removes the expired ones and notes it in the log.

In NurseOps Now

Not built: AI Assist (the app's chat helper for staff questions) threads (one saved conversation, here one per user and case) are kept until a user clears them. Capping and expiring memory is Plan 3. See Step 9.

Trade-offs

Interview answer

"Saved memory gets an expiry date per data type, and a nightly job deletes what's expired and writes an audit row (one line in the log of who did what, when) without the content. It keeps the privacy risk from growing silently and keeps old, stale memories out of the AI's context."

All data in this post is made up. No real people, tickets or patient data.

← Back to all 27 solutions in the state management blog

Key terms

Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.

AI Assist
The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
audit
A permanent record of who did what and when.Used in: How to implement it (ServiceApps)↩ Back to where you were
audit log
A permanent record of who did what and when.Used in: How to implement it (ServiceApps)↩ Back to where you were
audit row
One line in the log of who did what, when.Used in: How to implement it (ServiceApps), Interview answer↩ Back to where you were
incident
A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
KB
Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
persistence creates liability
Saved data can leak personal details or secrets.Used in: The problem it solves↩ Back to where you were
policy
The health plan's written rules for when a test is covered.Used in: How to implement it (ServiceApps)↩ Back to where you were
ServiceApps
A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
thread
One saved conversation, here one per user and case.Used in: How to implement it (ServiceApps), In NurseOps Now↩ Back to where you were
TTL expiration
Deleting saved data automatically after a set time.Used in: In plain words, The problem it solves↩ Back to where you were
vector store
A database that finds text by meaning, using embeddings.Used in: How to implement it (ServiceApps)↩ Back to where you were