fix: defer session permission handlers until app ready (#529) - #532
Merged
Merged
Conversation
register.appEvents() runs before app.whenReady() and accessed session.defaultSession to install the deny-all permission handlers from #493. Electron throws "Session can only be received when app is ready" on pre-ready access, crashing the main process before any window or tray exists on machines that lose the startup race — reported on Windows for 3.4.1/3.4.4/3.4.5. Move the handlers into src/main/session-permissions.js, which always defers installation behind app.whenReady(). Regression test mimics Electron's pre-ready throw semantics and fails on the old synchronous installation; a guard test keeps direct defaultSession access from being reintroduced elsewhere in src/. Fixes the follow-up crash reported in #529 (joncl's report). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Hoist collectSourceFiles/SRC_DIR from config.spec.js into test/helpers.js and reuse in both guard specs; inline the defaultSession getter, drop unused fake-app scaffolding, and merge the two overlapping regression assertions into one test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lacymorrow
added a commit
that referenced
this pull request
Aug 26, 2026
Version bump for 3.4.6 patch release. Ships fix from #532 (LAC-3530): startup race where session.defaultSession was accessed before app ready.
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
Fixes the second startup crash reported in #529 (joncl's report): on some machines, 3.4.1/3.4.4/3.4.5 launch as a single orphaned process with no window and no tray icon, with
TypeError: Session can only be received when app is readyinmain.log.Root cause:
src/main.jscallsregister.appEvents()beforeawait app.whenReady(), andappEvents()immediately touchedsession.defaultSessionto install the deny-all permission handlers added in #493. Electron throws ifdefaultSessionis accessed before thereadyevent, killing the main process before any UI exists. Whether it crashes is a startup-timing race (module load + init vs. Electron'sreadyevent), which is why it reproduces consistently on some machines and never on others.Fix: the handlers now live in
src/main/session-permissions.js, which always defers installation behindapp.whenReady(). Handler behavior is unchanged (deny all permission requests/checks); they are installed before any window is created (windows are created 500ms after ready).Paperclip issue: LAC-3530 (follow-up to LAC-3424 / v3.4.5).
Testing
test/session-permissions.spec.js): a minimal fake Electron reproduces the real semantics —defaultSessionthrows until ready. The main test fails on the old synchronous installation (verified red before the fix) and asserts the handlers install after ready and deny all permissions. A guard test keeps directdefaultSessionaccess from being reintroduced anywhere else insrc/(the shared source-tree walker moved intotest/helpers.js, reused byconfig.spec.js).npx playwright test test/session-permissions.spec.js test/config.spec.js— 4/4 pass.App ready, window created, no session errors after 12s.npm run lintclean (0 errors) on changed files.maintoo (10sbeforeAllhook budget) — pre-existing, unrelated.🤖 Generated with Claude Code