fix(persistence): force-save cookie state on graceful shutdown#610
Merged
fix(persistence): force-save cookie state on graceful shutdown#610
Conversation
… cookies The StorageStateManager watchdog timer uses .unref(), so it does not prevent process exit. If the MCP server exits via SIGTERM/SIGINT, the final cookie save may never execute. Add saveAllStorageState() to SessionManager and call it during graceful shutdown with a 5-second timeout to ensure cookies are persisted before exit. Closes #606 (compounding factor) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
saveAllStorageState()method toSessionManagerthat iterates all active sessions and saves their storage state via CDPNetwork.getAllCookiesenhancedShutdownhandler insrc/index.tswith a 5-second timeout to prevent hanging shutdownProblem
The
StorageStateManagerwatchdog timer uses.unref(), meaning it does not prevent Node.js process exit. If the MCP server is killed (SIGTERM/SIGINT), the final periodic save may not have completed, causing cookie/session loss across restarts.This is the compounding factor from #606 — even when the persistent profile correctly stores cookies, the storage state backup (which serves as a safety net for headless-shell and cross-session restoration) was not guaranteed to be written on exit.
Changes
src/session-manager.tssaveAllStorageState()— iterates all sessions with activeStorageStateManager, finds a page per session, callsmanager.save()src/index.tssaveAllStorageState()inenhancedShutdownbefore stoppingstateManager, with 5s timeoutTest plan
npm run build— clean (zero TypeScript errors)npm test— 170 suites passed, 3191 tests pass--auto-launch, authenticate to a site, send SIGTERM, verify storage state JSON exists in~/.openchrome/storage-state/Closes #606 (compounding factor)
🤖 Generated with Claude Code