Skip to content

refactor(preload): split bridge API modules - #17612

Merged
nwparker merged 4 commits into
stablyai:mainfrom
nwparker:small-files-preload
Sep 1, 2026
Merged

nwparker merged 4 commits into
stablyai:mainfrom
nwparker:small-files-preload

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary\n- Split the preload bridge into domain-named API modules under .\n- Keep the public contract and IPC channel wiring intact.\n- Extend the web typecheck project to include the extracted preload support modules.\n\n## Validation\n- Native oxlint, node/CLI typechecks, max-lines ratchet, focused parity tests, and diff checks passed.\n- Web typecheck is blocked only by unrelated untracked browser-pane extraction files left out of this stack.\n\nStacked on the renderer runtime/store refactor (PR #17611).

@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR splits the monolithic Electron preload facade into domain-specific bridge modules while retaining the existing public API and IPC wiring.

  • Composes the extracted bridge modules in src/preload/index.ts.
  • Moves shared preload initialization and listener support into preload-runtime-support.ts.
  • Extends web typecheck coverage for extracted preload support files.
  • Updates GitHub channel parity coverage for the split bridge owners.
  • Preserves accepted session-tab snapshots during visibility-resume reconciliation.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains in the reviewed follow-up fixes.

No blocking failure remains.

Important Files Changed

Filename Overview
src/preload/index.ts Replaces the monolithic bridge implementation with composition of domain-specific API modules while retaining the exposed API boundary.
src/preload/preload-runtime-support.ts Centralizes preload initialization helpers and shared listener state extracted from the former monolithic entry point.
src/preload/api/plugins-bridge.ts Preserves the plugin bridge contract and consolidates its type imports to satisfy validation.
src/main/ipc/github-ipc-channel-parity.test.ts Updates the GitHub IPC census to inspect both bridge-owner modules used by the composed facade.
src/renderer/src/runtime/web-session-tabs-sync/active-session-subscription.ts Records snapshots as accepted only after they pass recovery, freshness, and apply gates.
src/renderer/src/runtime/web-session-tabs-sync/global-session-subscription.ts Wires separate receipt and acceptance callbacks into visibility-resume coordination and resets both during cleanup.
config/tsconfig.tc.web.json Adds the extracted preload support modules to the web typecheck project.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  R[Renderer] --> A[window.api]
  A --> I[src/preload/index.ts]
  I --> D[Domain bridge modules]
  D --> E[Electron ipcRenderer]
  E --> M[Main-process IPC handlers]
Loading

Reviews (8): Last reviewed commit: "chore(stack): restack preload on rendere..." | Re-trigger Greptile

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The split itself is mechanically faithful — I diffed every ipcRenderer channel and method name against the pre-split index.ts and found zero drift (0 channels added/removed, 84/84 top-level keys, 821/821 method names). One thing needs confirmation first: the refactor silently adds a public method and changes one reload path's runtime behavior (details inline on app-bridge.ts).

Reviewed changes

  • Split src/preload/index.ts into ~90 domain bridge modules under src/preload/api/, each owning its IPC contract; index.ts shrinks from ~5,300 lines to a ~200-line composer.
  • Split the four oversized namespaces (browser, gh, pty, ui) across *-part-N.ts files merged by object spread.
  • Extracted preload runtime support (before-unload checkpoint, native file drop, browser find forwarding, updater quit-abort relay) into preload-runtime-support.ts.
  • Extended the web typecheck project to cover the extracted preload support modules.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/preload/api/app-bridge.ts Resolved
import { browserApiPart1 } from './browser-bridge-part-1'
import { browserApiPart2 } from './browser-bridge-part-2'

export const browserApi = { ...browserApiPart1, ...browserApiPart2 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spread-merges for browser, gh, and pty have no satisfies PreloadApi['...'] annotation (unlike ui-bridge.ts:14), and the composed api object in index.ts is not asserted against PreloadApi. That means a method dropped or renamed during a future split edit would not be caught at compile time. Adding the same satisfies guard to the three merge files (or asserting the final composed object) would pin the full surface.

@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 17052dd to 3cd043e Compare August 31, 2026 09:46
@nwparker
nwparker force-pushed the small-files-preload branch from a7461f1 to bb0b379 Compare August 31, 2026 09:47
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 3cd043e to ce3c952 Compare August 31, 2026 09:50
@nwparker
nwparker force-pushed the small-files-preload branch 2 times, most recently from 531d778 to 21e1bc9 Compare August 31, 2026 10:51
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch 2 times, most recently from 54e132d to b4ab76a Compare August 31, 2026 11:09
@nwparker
nwparker force-pushed the small-files-preload branch from 21e1bc9 to 7f45293 Compare August 31, 2026 11:09
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from b4ab76a to 32623d7 Compare August 31, 2026 11:13
@nwparker
nwparker force-pushed the small-files-preload branch from 7f45293 to 78fa8a4 Compare August 31, 2026 11:13
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 32623d7 to b18ff33 Compare August 31, 2026 11:29
@nwparker
nwparker force-pushed the small-files-preload branch from 78fa8a4 to 41f55ee Compare August 31, 2026 11:30
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch 2 times, most recently from f9468aa to 08820a4 Compare August 31, 2026 12:44
@nwparker
nwparker force-pushed the small-files-preload branch 2 times, most recently from 80d2e62 to 473d3a6 Compare September 1, 2026 04:44
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 962cbdf to 1cb0bab Compare September 1, 2026 04:44
@greptile-apps

greptile-apps Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Too many files changed for review (274 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@nwparker

nwparker commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (28373fc) — two removals

Removed the agentHooks bridge domain. This PR resurrected a preload domain (15 keys) that main deleted in #16089. There are no ipcMain.handle('agentHooks:…') handlers, no callers in renderer or mobile, and no entry in api-types.ts — agentHooks as a bridge key appears nowhere in origin/main. A pure refactor shouldn't revive a deleted subsystem. (The live src/main/agent-hooks/ installer subsystem is unrelated and untouched.)

Removed app.awaitBeforeUnloadCheckpoint. This PR newly exposed it on the bridge. It's arguably a fix — it's declared in app-api.ts and optionally called at lazy-chunk-recovery-reload.ts:55, so today that path resolves immediately instead of awaiting — but it is a behavior change and doesn't belong in a pure-refactor stack. Filed to land separately with a test.

Two dropped methods restored. An exposed-key census (origin/main = 1008 keys vs. split = 1036) found the split had silently dropped jira.searchUsers and runtimeEnvironments.retryControlConnection — both present in the pre-split baseline, both with live callers. Neither failed typecheck, because the bridge modules carry no satisfies PreloadApi and the shim's const api = {…} is unannotated; a dropped bridge method is a runtime undefined is not a function in the renderer. Restored, and the split is now a strict superset of main's exposed keys. Adding satisfies PreloadApi per module is filed as a follow-up.

Also ported main's preload delta from #17569, #17531, #17159.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues in this restack.

Reviewed changes

  • Restored awaitBeforeUnloadCheckpoint to a module-private helper — app-bridge.ts no longer exposes it on the public app bridge; it is passed only as the internal checkpoint argument to prepareAndInvokeAppRestart, so the renderer's optional-chain fallback in lazy-chunk-recovery-reload.ts is a silent no-op again, matching the pre-split contract.
  • Re-split the bridge over the advanced renderer-stack base — absorbed the base branch's new preload surface (reportViewportScrollState, onScrollBrowserPage, retryControlConnection/observeOnly/onSharedControlDiagnostics, SSH keyboard-interactive prompts, terminal-split worktreeId/sourceLeafId) and its removal of the agentHooks namespace, with zero IPC-channel drift.
  • Pruned the src/preload/index.ts max-lines baseline entry — the composer is back under budget.

IPC channel parity against the new base is clean: the only deltas are the pre-existing support-file channels (gitlab:*, updater:*, window:unload-prevented) documented in earlier reviews. The one remaining open suggestion — adding satisfies guards to the browser/gh/pty merge bridges and asserting the composed api — is unchanged by these commits and still tracked on its existing thread.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the small-files-preload branch from 473d3a6 to 20204b1 Compare September 1, 2026 05:35
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 1cb0bab to 7c86ed1 Compare September 1, 2026 05:35
@nwparker
nwparker force-pushed the small-files-preload branch from 20204b1 to 7a188fe Compare September 1, 2026 05:57
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 7c86ed1 to 7641c79 Compare September 1, 2026 05:58
@nwparker
nwparker force-pushed the small-files-preload branch from 7a188fe to 6bcdca1 Compare September 1, 2026 06:21
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 7641c79 to b12c4e1 Compare September 1, 2026 06:21
@nwparker
nwparker force-pushed the small-files-preload branch from 6bcdca1 to 835f86b Compare September 1, 2026 06:46
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from b12c4e1 to 416c51b Compare September 1, 2026 06:47
@nwparker
nwparker force-pushed the small-files-preload branch from 835f86b to 8fe371f Compare September 1, 2026 07:11
@nwparker
nwparker force-pushed the stack/refactor-small-files-renderer-runtime branch from 416c51b to 98e76c7 Compare September 1, 2026 07:11
@nwparker
nwparker force-pushed the small-files-preload branch from 8fe371f to 4f81616 Compare September 1, 2026 07:31
@nwparker
nwparker changed the base branch from stack/refactor-small-files-renderer-runtime to main September 1, 2026 07:31
@nwparker
nwparker merged commit c475d23 into stablyai:main Sep 1, 2026
32 checks passed
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