Skip to content

Fix remote session cleanup during startup and shutdown - #16

Draft
shrey150 wants to merge 4 commits into
codex/desktop-safe-diagnosticsfrom
codex/desktop-session-lifecycle
Draft

shrey150 wants to merge 4 commits into
codex/desktop-safe-diagnosticsfrom
codex/desktop-session-lifecycle

Conversation

@shrey150

@shrey150 shrey150 commented Nov 13, 2026 •

Copy link
Copy Markdown

Session creation, renderer reloads, and application shutdown can race, leaving remote sessions running or reconnecting after the window closes. This change reuses in-flight initialization, releases sessions after failed startup even when transport close fails, and makes Electron wait for cleanup before quitting. Final shutdown also rejects initialization that was waiting for an earlier window cleanup.

API operations now have a 30-second total deadline, deferred readiness checks honor their configured deadline, and failed deferred startups request release. Session-creation POSTs are no longer retried after ambiguous network/server failures, avoiding duplicate sessions when a creation response is lost. Reconnects preserve the current page, and viewport updates reuse one CDP connection per page.

Stacked on #14 (codex/desktop-safe-diagnostics); review this diff against that branch. No version bump or changeset is included.

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
npm run build Main-process TypeScript and renderer bundle built successfully. Checks the exact PR head builds with the existing dependencies.
node --test tests/*.test.cjs 20 tests passed. Covers concurrent startup, cancellation, transport-close failure, reconnect timers, failed connection release, deferred timeouts, non-idempotent creation, CDP reuse, final shutdown races, and credential-safe diagnostics.
Cleanup regression against the original main revision Closing the transport with a synthetic error caused zero remote-release calls; the same test passes after this change with exactly one release. Demonstrates the original leak and verifies the changed failure path.
Real SessionManager.initialize() calls, concurrently and again after initialization, using https://example.com All calls returned the same live session; the remote page title was Example Domain. Verifies actual API creation, CDP connection, and reuse.
Real updateViewport(1024, 700) Remote innerWidth and innerHeight measured 1024 and 700. Verifies the viewport command reaches the actual browser.
Real session shutdown with an injected transport-close error after closing the CDP connection Shutdown completed, another initialization was rejected, no reconnect timer remained, and the API reported COMPLETED. Exercises cleanup against the real service while deliberately failing the transport-close boundary. The smoke session was released.

The desktop operating-system quit/reopen interaction is not covered by the SessionManager smoke; macOS activation needs platform testing. If the initial creation response is lost, its session ID is unknown, so this change prevents duplicate retries but cannot release that unknown session itself.

Combined validation: the mainline candidate containing #13–#18 and #20 passed builds, all 34 automated tests, and the high/critical advisory gate on Linux, macOS, and Windows. Cross-platform CI results.

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.

1 participant