Add session auto-reload for fresh logins without restart#14
Merged
Conversation
…g server The background server loads the Chat session once at startup and keeps it in memory. After it is signed out upstream, requests fail with a 401 — and crucially they keep failing even after a successful `og-veil login`, because login writes a new token to disk while the running server keeps using its stale (expired/revoked) in-memory copy. The only recovery was an undiscoverable `og-veil restart`. Make Session re-read session.json when another process rewrites it (tracked by file mtime) before checking expiry/refreshing, so a fresh login is adopted by the running server on the next request without a restart. Guard refresh/reload with a lock since the server is threaded.
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
Implement session auto-reload functionality that allows a long-running background server to pick up fresh login credentials written to disk by another process (e.g.,
og-veil login) without requiring a restart.Key Changes
mtime) ofsession.jsonto detect when another process rewrites it_reload_if_changed()method that re-reads the session file from disk if itsmtimediffers from what we last sawaccess_token()with a lock to serialize refresh and reload operations across concurrent request handlers in the threaded serverImplementation Details
_file_mtime()helper usesos.stat().st_mtime_nsfor nanosecond precision to reliably detect file changes_mtimefield is updated both when loading and saving the session to track our own writeshttps://claude.ai/code/session_01TYMUPb4VAjMhJ1WjssbyMy