fix: --fresh flag fails to clean cookie_storage and fact_store#3354
fix: --fresh flag fails to clean cookie_storage and fact_store#3354deacon-mp wants to merge 6 commits into
Conversation
…ers from stale cookies - Add data/fact_store and data/cookie_storage to DATA_FILE_GLOBS so --fresh removes them - Handle decryption failure in auth_svc gracefully: regenerate session key instead of crashing - Fixes persistent encryption key mismatch error after switching --insecure mode or keys Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes --fresh cleanup gaps introduced by persistent sessions/knowledge persistence and prevents server startup crashes when data/cookie_storage can’t be decrypted due to an encryption key mismatch.
Changes:
- Adds
data/fact_storeanddata/cookie_storagetoDATA_FILE_GLOBSso--freshremoves them. - Updates
AuthService.apply()to recover from cookie key decrypt failures by deleting the stale file and regenerating a new session key instead of exiting.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| app/service/data_svc.py | Expands managed data globs so --fresh also cleans fact_store and cookie_storage. |
| app/service/auth_svc.py | Handles decrypt/read failures of cookie_storage by regenerating and persisting a new session key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…mExit catch - Remove data/fact_store from DATA_FILE_GLOBS (knowledge_svc handles its own cleanup) - Narrow inner catch to SystemExit only (let IO/permission errors propagate) - Test already covers the SystemExit recovery path
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
app/service/auth_svc.py:107
- When
secret_keyis replaced due to invalid length, the new key is not persisted back todata/cookie_storage. This causes the app to repeatedly regenerate an ephemeral key on each startup if the stored key is malformed. After generating a replacement 32-byte key, also overwrite the cookie_storage file (best-effort) to restore persistence.
if len(secret_key) != 32:
secret_key = os.urandom(32)
self.log.warning('Loaded session key is not 32 bytes long. Generating new key.')
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove unused COOKIE_SESSION import - Use per-test @pytest.mark.asyncio instead of global pytestmark - Clear BaseWorld config in fixture teardown to avoid state leakage
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
❌ The last analysis has failed. |
|
Closing in favor of a clean PR with squashed history. Same code, verified by CI + Copilot. |
Summary
data/fact_storeanddata/cookie_storagetoDATA_FILE_GLOBSso--freshproperly removes themauth_svcgracefully: regenerate session key instead of crashing viasys.exit(1)Problem
After PR #3264 (persistent sessions),
data/cookie_storageis saved as an encrypted file. When the encryption key changes (e.g., switching between--insecureand secure mode),--freshfails to clean it because it's not in the managed file list. On next startup,file_svc._read()hitsInvalidTokenand callssys.exit(1), crashing the server.Same issue exists for
data/fact_storefrom the knowledge service.Changes
app/service/data_svc.pydata/fact_storeanddata/cookie_storagetoDATA_FILE_GLOBSapp/service/auth_svc.pySystemExitfrom_read(), delete stale cookie file, regenerate keyTest plan
--freshnow removesdata/cookie_storageanddata/fact_store🤖 Generated with Claude Code