fix(agent): handle SIGTERM and detect orphaned sessions - #438
Open
pando85 wants to merge 2 commits into
Open
Conversation
- Add SIGTERM signal handler in dispatch_run to properly revoke sessions when the client process receives SIGTERM (e.g., when OpenCode restarts) - Track requesting client PID in ManagedPrincipalSession and detect orphaned sessions in reap_expired_sessions by checking if client is alive - Use profile's max_session_ttl instead of hardcoded 3600s for session deadline - Add PR_SET_PDEATHSIG on principal process so it receives SIGTERM if daemon dies - Add signal-hook dependency for portable signal handling This fixes the issue where Playwright MCP sessions would become orphaned when OpenCode restarts, blocking new sessions with 'already has an active session' error.
- Return error instead of Ok(()) when dispatch_run exits due to signal - Suppress dead_code warning for PassStorageAdapter::new_with_options
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.
Problem
When OpenCode restarts, the Playwright MCP server process (launched via
passless agent playwright-mcp) becomes orphaned but keeps running. Passless tracks this as an active session and refuses to start a new one, returning "profile 'coding' already has an active session (pid XXXX)".Root Causes
ctrlc::set_handler. When OpenCode sends SIGTERM, the client died without callingterminate_principal.max_session_ttlconfig.PR_SET_PDEATHSIGon principal - The principal wouldn't receive a signal if the daemon died.Changes
dispatch_runto properly revoke sessions when the client process receives SIGTERMManagedPrincipalSessionand detect orphaned sessions inreap_expired_sessionsby checking if client is alive via/proc/{pid}/statmax_session_ttlinstead of hardcoded 3600s for session deadlinePR_SET_PDEATHSIGon principal process so it receives SIGTERM if daemon diessignal-hookdependency for portable signal handlingTesting
--features agent