feat: daily session reset by timezone#198
Open
americodias wants to merge 1 commit intoRichardAtCT:mainfrom
Open
feat: daily session reset by timezone#198americodias wants to merge 1 commit intoRichardAtCT:mainfrom
americodias wants to merge 1 commit intoRichardAtCT:mainfrom
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.