You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(sessions): TTL enforcement and crash-safe cleanup
Sessions now carry an explicit TTL and are guaranteed to be torn down at
or before that deadline even if the API service crashes.
* CreateSessionRequest gains ``ttl_seconds`` (default 900s, max 24h);
CreateSessionResponse adds the absolute ``expires_at`` timestamp.
* Docker session containers are launched with ``--rm`` and ``sleep <ttl>``
so the container self-destructs at the deadline regardless of whether
the API service is alive. The TTL also goes onto the container as the
``code-interpreter.expires-at`` label for the reaper.
* Kubernetes session pods set ``activeDeadlineSeconds=ttl`` so kubelet
stops the executor container at the deadline; the deadline timestamp
is also stored as a pod annotation so the reaper knows when to delete.
* A new background reaper task (in main.py's lifespan) runs once at
startup — handling crash recovery for any sessions whose TTL elapsed
while the service was down — and then every 30s thereafter.
* Both backends implement ``reap_expired_sessions`` (label-filtered
list followed by per-session deletion) so the reaper is backend-agnostic.
Tests cover TTL bounds at the route layer, the active_deadline /
expires-at metadata on each backend, and reaper behavior under happy
path, missing annotation, invalid annotation, list failure, and partial
delete-failure scenarios.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments