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
-
From the repository root, run the demo without
--skip-wait:Terminal window uv run python cookbooks/expiring-chat-sessions/demo.pyPhases 1 through 3 match the
--skip-waitrun: 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 samethread_idagain. -
Review Phases 4 and 5 in the output:
Watch two lines:
get_tuple()is the LangGraph API for reading a checkpoint by ID. ReturningNoneconfirms the record is gone from Aerospike.messages stored : 2confirms 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() : Noneraw record : goneuser > 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. -
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 thatthread_idto 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()returnsNoneafter the wait, confirming Aerospike removed the checkpoint.messages storeddrops from4back to2on 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
DELETEquery 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
-
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.