Skip to content

fix: --fresh fails to clean cookie_storage, auth_svc crashes on key mismatch#3355

Open
deacon-mp wants to merge 1 commit intomasterfrom
fix/fresh-cookie-cleanup
Open

fix: --fresh fails to clean cookie_storage, auth_svc crashes on key mismatch#3355
deacon-mp wants to merge 1 commit intomasterfrom
fix/fresh-cookie-cleanup

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

Summary

  • Add data/cookie_storage to DATA_FILE_GLOBS so --fresh properly removes it
  • Handle decryption failure in auth_svc gracefully: catch SystemExit from file_svc._read(), regenerate session key instead of crashing

Problem

After PR #3264 (persistent sessions), data/cookie_storage is saved as an encrypted file. When the encryption key changes (e.g., switching between --insecure and secure mode), --fresh fails to clean it because it's not in the managed file list. On next startup, file_svc._read() hits InvalidToken and calls sys.exit(1), crashing the server even with --fresh.

Reproduction

python3 server.py --insecure -l DEBUG   # creates cookie_storage with default.yml key
# Ctrl+C
python3 server.py -l DEBUG              # uses local.yml key → CRASH
python3 server.py --fresh -l DEBUG      # cookie_storage survives → CRASH again

Changes

File Change
app/service/data_svc.py Add data/cookie_storage to DATA_FILE_GLOBS
app/service/auth_svc.py Catch SystemExit from _read(), delete stale cookie, regenerate key
tests/services/test_fresh_cleanup.py 3 tests: glob membership + stale cookie recovery with state save/restore

Test plan

  • Reproduced crash on master, confirmed fix on this branch
  • --fresh now removes data/cookie_storage
  • Key mismatch no longer crashes — auth_svc regenerates and continues
  • Test saves/restores BaseWorld._app_configuration — no state leakage
  • 3 tests pass, flake8 clean

🤖 Generated with Claude Code

…ismatch

- Add data/cookie_storage to DATA_FILE_GLOBS so --fresh removes it
- Catch SystemExit in auth_svc when file_svc._read() fails to decrypt
  stale cookie_storage; regenerate session key instead of crashing
- Add tests: DATA_FILE_GLOBS membership + stale cookie recovery

Fixes crash when switching between --insecure and secure mode after
PR #3264 introduced persistent session cookies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes --fresh cleanup and startup robustness for persistent sessions by ensuring data/cookie_storage is treated as managed state and by preventing auth_svc from crashing when the encryption key used to decrypt cookie_storage changes.

Changes:

  • Add data/cookie_storage to DATA_FILE_GLOBS so DataService.destroy() (used by --fresh) removes it.
  • Update AuthService.apply() to recover from cookie_storage decryption failure by deleting the stale file and regenerating a session key instead of terminating the server.
  • Add tests validating glob membership and key-mismatch recovery behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
app/service/data_svc.py Includes data/cookie_storage in the --fresh managed deletion globs.
app/service/auth_svc.py Catches SystemExit from file_svc._read() on key mismatch and regenerates cookie_storage.
tests/services/test_fresh_cleanup.py Adds regression tests for DATA_FILE_GLOBS membership and stale-cookie recovery.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants