feat: daily session reset by timezone - #198
americodias wants to merge 1 commit into
Conversation
Adds SESSION_DAILY_RESET_HOUR and SESSION_DAILY_RESET_TIMEZONE settings. A session whose last_used timestamp falls before today's reset hour (in the configured local timezone) is treated as expired, in addition to the existing inactivity-based timeout. Lazy check on next access — no background task or scheduler needed. Useful for forcing a fresh session each morning so the chat doesn't carry yesterday's working set indefinitely. Disabled by default.
|
Thank you for submitting this feature. I understand the use case it is intended to address: some users may want to start with a clean context the first time they use the bot each day, without having to remember to run At the moment, “starting a new session each day” is implemented as a session-expiration rule. This may create some unexpected behavior. For example, developers often continue working across midnight or a configured reset time. If a user is still using a session at 02:59 and sends their next message at 03:01, the bot will silently switch to a new session. The running task itself will not be interrupted, but the next message will lose the previous context, and the user may not understand what happened. The project already provides |
Summary
Adds two settings —
SESSION_DAILY_RESET_HOUR(0-23) andSESSION_DAILY_RESET_TIMEZONE(IANA tz string) — that force session expiry at a recurring daily boundary. A session whoselast_usedfalls before today's reset hour (in the configured local timezone) is treated as expired in addition to the existingSESSION_TIMEOUT_HOURSrule.Why
The existing inactivity-based timeout works well for natural breaks but doesn't enforce a fresh start each day. Some users (myself included) prefer "every morning, the bot starts a fresh session" to avoid yesterday's working set leaking into today's first message — without needing to remember
/new.Two examples:
SESSION_DAILY_RESET_HOUR=3+SESSION_DAILY_RESET_TIMEZONE=Europe/Lisbonensures the 9am check-in starts fresh even if the previous session was at 11pm.What
src/claude/session.py—ClaudeSession.is_expired()gains two optional parameters (daily_reset_hour,daily_reset_tz); existing(timeout_hours)calls remain valid (defaults preserve previous behavior). NewSessionManager._is_session_expired(session)helper threads both rules through one call site.src/claude/facade.py— two existings.is_expired(self.config.session_timeout_hours)callsites switch toself.session_manager._is_session_expired(s)so they pick up the daily rule.src/config/settings.py— adds the two new settings:How it works
The logic is a lazy expiry check, not a background scheduler:
So a session created Tuesday 11pm and accessed Wednesday 9am — with reset at 3am Lisbon — is detected as expired the moment Wednesday's
is_expired()runs. No timer, no race condition, no jobs to schedule.Compatibility
session_daily_reset_hour = None). Pure no-op when unset.is_expired(timeout_hours)callsites keep working — the new params are optional with sensible defaults.Test plan
SESSION_DAILY_RESET_HOUR=3andTZ=Europe/Lisbon: session created 11pm, query at 9am next day → fresh sessionZoneInfo)SESSION_DAILY_RESET_TIMEZONE=America/New_York→ reset boundary follows NYC, not UTCNotes
Uses
zoneinfo.ZoneInfofrom stdlib (3.9+) — no new dependencies. The codebase already requires Python 3.11.