Skip to content

fix(electron): preserve runtime rejection and exception policies - #8489

Closed
ShuaixinHuang wants to merge 3 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-electron-rejection-policy
Closed

ShuaixinHuang wants to merge 3 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-electron-rejection-policy

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #8253 at the author's explicit request to resubmit the existing PR. This replacement reuses verified head 0d08990 and preserves the original discussion and validation record at #8160. Historical validation and its limitations below remain at their stated execution points. This new PR must pass its own hosted CI.

Review follow-up: revoked rejection reasons

A P1 review identified that Array.isArray throws for a revoked Proxy before the application's rejection handler receives its original reason. This was reproduced on the initial PR head: 1 failed / 107 passed. Shape collection now checks arrays only for object values and treats an inaccessible revoked object's shape as object; callable reasons retain function. The added regression verifies original reason/promise identity for revoked object, array, and callable proxies, with an unrevoked array-proxy control. The final complete file is 108 passed. A real Electron 33.4.11/public CLI scenario with an application rejection handler also completed 6/6 actions; its later ping requires that the original handler received the revoked reason. No review thread was automatically replied to or resolved.

Summary

Fixes #8146. Recording an unhandled rejection must not turn Electron's warning-only behavior into an uncaught exception or change its existing exception-handler policy.

Problem and expected behavior

The active hook installed once listeners for unhandledRejection and uncaughtException and threw from both. In a real Windows Electron 33.4.11 process, the same rejection continued with warnings without the hook but terminated with exit code 7 with it. A public CLI scenario using the baseline hook did not complete within a 30-second watchdog; its owned process tree was then terminated.

Change and scope

Observe unhandledRejection and uncaughtExceptionMonitor at process event dispatch, forwarding the original receiver, arguments, return value, and thrown exception. Add no exception listeners. This leaves the runtime's default rejection mode and Electron/application listener counts intact, and records subsequent rejections too. Borrowed emit calls on other emitters are forwarded without process-event evidence.

The existing active-hook owner changes; no new provider, execution authority, public schema, limit, or cleanup mechanism is introduced. Maintainer scope decision: not applicable to this ordinary correction within the existing active-capture boundary.

Contract and boundary impact

  • Semantic owner: scripts/electron-active-hook.cjs; its existing process-lifecycle timeline consumer and event shapes are retained.
  • CLI/MCP/catalog and installation contracts: unchanged. Both surfaces use the same capture provider; real MCP execution was not run for this change.
  • Compatibility: preserve warning-only rejection behavior, application handlers, and Node throw/strict fatal behavior. Do not replace Electron's exception policy with a new fallback.
  • Target authority and cleanup: still an explicitly selected owned Electron application. Test apps used isolated temporary profiles; no existing user application/profile/process was used.
  • Generated metadata/package impact: none.

Expected effects of the existing operation:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.

Validation

  • npm run test:focused -- tests/boundary/browser/electronActiveHook.test.ts: 108 passed, 3 prerequisite build tasks passed. Six new cases cover revoked rejection reasons, warning-only ordinary and blocked-shell rejections, listener identity/throws and borrowed emit, Electron-style listener-count handling, and both fatal rejection modes. All 102 existing cases remain.
  • Controlled restoration of the hook to exact base e5c46dff034fef432e772f669bc309f512a6b186, with the initial five regressions: 5 failed / 102 passed. Executed bytes matched the Git baseline SHA-256; the patch was restored byte-for-byte in finally.
  • Real cached Electron 33.4.11, Windows x64: the unhooked control and fixed hook both continued, warned, and exited 0. The fixed hook also retained the rejection event; the original hook exited 7 before continuing.
  • Real compiled public capture-electron-scenario: fixed hook completed all 6/6 actions, retaining 2 unhandled-rejection events, the blocked shell attempt, and the later ping IPC invocation. The result retained its normal partial_attach coverage. The baseline run exceeded the external 30-second watchdog with no JSON result; only its owned process tree was terminated. A subsequent process inventory found no remaining probe processes.
  • npm run check:fast: 2/2 passed (31.59s); normal pre-commit passed; all three committed files match the verified hashes; normal pre-push 2/2 cached passed (288ms).

Compatibility, safety, and release

No breaking schema or migration. Payload values remain excluded from the timeline. Validation used the existing local Electron cache and Node 24.22.1; it does not establish Electron 44.7.0/Linux/Xvfb or macOS coverage from the report. No full repository suite or real MCP result is claimed. The CLI watchdog result is a bounded incomplete baseline run, not a successful cancellation/partial-Evidence test.

Author readiness

Human owner: @ShuaixinHuang

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

This replacement preserves the prior PR discussion and validation history at #8253. It reuses the verified published head and requires its own hosted CI.

Main compatibility before resubmission (2026-11-01)

Merged main aa48d494e9726d469a1b9ed917f021d8a1a4c7ea into the published branch without rewriting history. Merge commit 7e3e7b0bec07f59d1c4f54ba2765d202688c205f preserves both main's argv fixtures that intentionally avoid hook preloading and this PR's per-child Node rejection-mode arguments. The only manual conflict resolution was the shared test runner's argument signature and its two non-preload call sites; no assertion or production guard was removed.

Windows x64, Node 24.22.1 / npm 10.9.3 (repository pins npm 11.16.0): the complete electronActiveHook.test.ts passes 116/116, all 3 build prerequisite tasks succeeded, node --check scripts/electron-active-hook.cjs passed, and check:fast passes 2/2 in 1m24.809s. No dependency changes. These are controlled Node child-process tests with synthetic Electron fixtures, not a fresh installed-Electron/Linux/macOS run. Historical real-Electron verification above retains its original execution point. This new PR and HEAD require independent hosted CI.

Resubmitted at the author's request as #8542: #8542. Closed unmerged; original discussion and validation retained.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:21:38.487023Z 7e3e7b0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

The hook now records process failures without adding listeners that change Node or Electron behavior.

  • Electron capture records process events while keeping runtime policies intact.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Process emits an event] --> B{Process receiver and watched event?}
  B -->|Yes| C[Record value shapes]
  B -->|No| D[Call original emit]
  C --> D
  D --> E[Preserve application and runtime behavior]
Loading

Reviews (2) · Last reviewed commit: "merge: retain Electron rejection and arg..." · Reviewed by Greptile

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

2 participants