Skip to content

Prove expiry

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Phases 1 through 3 on the previous page showed TTL configuration, a first chat turn, and a successful resume while the checkpoint was still alive. This page runs the full demo without --skip-wait to prove what happens after the window closes.

Run the full lifecycle

  1. From the repository root, run the demo without --skip-wait:

    Terminal window
    uv run python cookbooks/expiring-chat-sessions/demo.py

    Phases 1 through 3 match the --skip-wait run: configure TTL, start the session, resume once (four messages total). Phase 4 then waits approximately 70 seconds (one-minute TTL plus a small buffer) so Aerospike can reclaim the records. Phase 5 checks that the checkpoint is gone and invokes the same thread_id again.

  2. Review Phases 4 and 5 in the output:

    Watch two lines: get_tuple() is the LangGraph API for reading a checkpoint by ID. Returning None confirms the record is gone from Aerospike. messages stored : 2 confirms LangGraph started a fresh session with no prior history.

    ================================================================
    Phase 4 - Wait 70s for the TTL to elapse
    ================================================================
    expiry window elapsed.
    ================================================================
    Phase 5 - Prove the state expired
    ================================================================
    get_tuple() : None
    raw record : gone
    user > Hello again?
    assistant > Hello again! This looks like a brand-new session to me.
    messages stored : 2 (fresh session -- no prior history)
    ================================================================
    Result
    ================================================================
    Aerospike expired the abandoned session automatically.
    No cron job, no sweeper, no DELETE query.
  3. Confirm expiry reclaimed the prior session:

    By the end of Phase 3 the thread held four messages under session-demo-001. Phase 4 waited past the one-minute TTL plus a small buffer without any application code touching the records. Aerospike deleted the checkpoint natively.

    Phase 5 called get_tuple() on that thread_id to confirm the checkpoint was gone, then invoked the graph with the same ID. With nothing left in Aerospike, LangGraph started a fresh two-message session with no prior history.

    • get_tuple() returns None after the wait, confirming Aerospike removed the checkpoint.
    • messages stored drops from 4 back to 2 on the fresh invoke.
    • The final assistant line is the third scripted reply (“brand-new session”). It only appears when prior checkpoints are gone.

    Aerospike handled expiry automatically. No cron job, sweeper process, or explicit DELETE query was required. That means fewer scripts to maintain and test across environments.

You configured AerospikeSaver with a native TTL, resumed a thread from checkpoints, and verified Aerospike reclaims expired sessions without a cleanup job.

Stop Aerospike

  1. Stop and remove the Aerospike container:

    Terminal window
    docker rm -f aerospike

Explore the cookbook source at cookbooks/expiring-chat-sessions/ in the langgraph-aerospike repository for the full step-by-step code walkthrough.

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?