Skip to content

feat(browser): settle page retirement in two phases - #14539

Closed
Jinwoo-H wants to merge 1 commit into
sta-4150-browser-placement-replacement-barrierfrom
sta-4150-browser-page-retirement-settlement
Closed

Jinwoo-H wants to merge 1 commit into
sta-4150-browser-placement-replacement-barrierfrom
sta-4150-browser-page-retirement-settlement

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62

ELI5

Closing an Electron page is not instant: the page can ask to stay open, crash, or disappear after the close request. This change gives the runtime a three-step safety latch—begin, cancel, or complete—so it never forgets the old browser engine before knowing what actually happened.

What Changed

  • Replace immediate placement deletion with idempotent beginPageRetirement.
  • Fence exact client-page use and every replacement while retirement is pending.
  • Let exact cancellation restore the same placement for a cancelled normal close.
  • Delete only after exact completion; stale callbacks cannot settle a newer retirement.
  • Keep placement capacity occupied until completion and page generations monotonic.
  • Apply the same settlement primitive to server and client placements.

Why

STA-4150 needs runtime-owned logical placement while Electron owns physical WebContents lifecycle. A one-step delete could release capacity and permit a replacement before beforeunload, close acknowledgement, crash cleanup, or destroy settlement had resolved, creating overlapping engines or stale cleanup of a new page.

This remains inert scaffolding. It adds no production lifecycle caller, command, capability, exchanged field, RPC/event, renderer surface, or Electron behavior. Activation still needs serialized normal-close versus terminal-crash priority, authenticated command delivery, exact WebContents/resource settlement, lease-loss reconciliation, and inventory/reclaim.

Linked Issue

STA-4150

Visual Proof

N/A — no rendered UI or production behavior is activated.

Testing

  • Parent behavior: 5/5 causal tests failed because two-phase retirement APIs did not exist.

  • Focused candidate: 31/31 retirement, placement, lease, replacement, and downgrade tests passed.

  • Full src/main/runtime + src/main/browser: 4,951 passed, 5 existing skips.

  • Adjacent RPC/protocol/mixed-version wire: 26/26 passed.

  • Full typecheck, native/type-aware audits, changed-code audit, formatting, reliability manifest, max-lines ratchet, and diff checks passed.

  • Three fresh correctness, security/performance, and Electron-lifecycle reviews found no publication blocker.

  • I manually validated the deterministic runtime behavior locally

  • Automated tests added

Review

Please review exact-token identity, begin idempotency, cancel/complete races, authority error ordering, capacity retention, and the intentionally inactive production surface. One documented activation decision remains: live-lease failure versus retirement-pending error precedence.

Checklist

  • This PR is small and focused
  • I explained what changed and why, including ELI5
  • Visual proof is N/A because no UI path is active
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, mobile, and backward-compatibility impact considered
  • Relevant local tests, typecheck, audits, and quality gates pass; package builds are covered by CI

@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from b9f45c0 to 506e8fa Compare August 14, 2026 20:03
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from 506e8fa to 4db55e8 Compare August 14, 2026 20:14
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch 2 times, most recently from b3823d9 to f43a192 Compare August 14, 2026 23:17
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from f43a192 to 47c6a46 Compare August 15, 2026 00:44
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch 2 times, most recently from 4bdd4a6 to 64cdb5f Compare August 15, 2026 02:57
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from 64cdb5f to fe925f8 Compare August 15, 2026 03:24
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from fe925f8 to 16a15b2 Compare August 15, 2026 08:53
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from 16a15b2 to 0187f24 Compare August 15, 2026 10:24
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from 0187f24 to a0c8ad6 Compare August 15, 2026 11:34
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from a0c8ad6 to 244e79a Compare August 15, 2026 12:30
@Jinwoo-H
Jinwoo-H force-pushed the sta-4150-browser-page-retirement-settlement branch from 244e79a to 7abb4f6 Compare August 16, 2026 09:09
@OrcaWin

OrcaWin commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Closing because the complete two-phase retirement stage is already on main (a93e31a9339).

src/main/runtime/browser-host/browser-host-page-placement.ts implements exact-token, idempotent begin; pending-use and replacement fencing; exact cancellation; and exact completion with capacity retained until settlement. The runtime lease registry exposes all three operations, and browser-host-page-retirement.test.ts preserves all five introduced cases: pending fencing, cancellation with delayed callbacks, completion/generation safety, capacity retention, and the same barrier for server placements. The placement/lease/capability tests have also been converted to the two-phase API.

Main further serializes completion against cancellation/reentrancy, keeps failed completion retryable, and settles command-ledger and execution-host-grant resources through browser-host-page-retirement-completion.ts. This supersedes the inert intermediate implementation here; it does not imply every later activation proof is complete.

@OrcaWin OrcaWin closed this Oct 26, 2026
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.

2 participants