[2026-09-25] eagle: work/projects/cpm-service-worker-architecture-and-diagnostics.md work/projects/cpm-web-extension-breakage-findings.md work/projects/cpm-web-extension-breakage-validation.md
This commit is contained in:
1 parent
3a4cad459c
commit
49ae1c15e7
3 files changed
+184
-10
No files matched your search
@@ -10,6 +10,8 @@ tags:
|
||||
---
|
||||
# CPM Web Extension Breakage Findings
|
||||
|
||||
> **Current architecture/source audit — 2026-09-25:** [[cpm-service-worker-architecture-and-diagnostics]]. Read it for Service Worker architecture, measured/missing diagnostics and five prioritized validation gaps. The investigation below is historical evidence, not a current readiness verdict. In particular: extension workers use the host process’s main thread; their generic SW heartbeat is disabled; dashboard “healthy” does not prove page receipt; and M2’s stable origin requires revalidating reload/Fire recovery. No new device reproduction was performed on September 25.
|
||||
|
||||
> Investigation summary as of 2026-09-08. This note distinguishes confirmed code paths from hypotheses that still need production evidence.
|
||||
>
|
||||
> **2026-09-10: two additional app-side tab-lifecycle violations found in production-reachable code** — `Close Other Tabs` sends `didCloseTab` for the one loaded tab it keeps, then puts the same `Tab` object back without `didOpenTab`; `Duplicate Tab` invoked from a popup inserts the original `Tab` into the main window instead of a copy, so closing the popup makes WebKit forget the still-live tab. Both produce a deterministic **single-tab** routing failure: reload does not help, new tabs work, and Fire / extension reload / tab recreation repairs it. The first chain is source-confirmed and has a minimal manual repro below; the popup chain is source-confirmed and still needs a manual run.
|
||||
@@ -35,7 +37,7 @@ The debug-menu simulation enters the third state deliberately. It proves the hea
|
||||
|
||||
The strongest explanation for the observed **old/specific tabs dead, new tabs fine** shape is now the app violating WebKit's tab lifecycle contract. It has three concrete instances, all ending in the same `m_tabMap` loss. The separate **all tabs including new tabs** shape still points to the background-service-worker lifecycle and must not be conflated with the tab-routing failure.
|
||||
|
||||
## Current conclusions (authoritative, 2026-09-10)
|
||||
## Historical conclusions (2026-09-10; current source audit linked above)
|
||||
|
||||
Use the scope first when classifying an episode:
|
||||
|
||||
@@ -55,17 +57,15 @@ Use the scope first when classifying an episode:
|
||||
|
||||
Explicitly not active production hypotheses: critical-memory-pressure termination (manual test negative), cold-launch/restoration miss (transient and fixed), feature-flag transitions (not a production event), privacy-config scriptlet extension reload (different extension context), `removeAllUserScripts()` (WebExtension scripts are excluded), and a normal page's long-running JavaScript by itself (limited to that page's WebContent thread).
|
||||
|
||||
## CPM architecture
|
||||
## CPM architecture (refreshed 2026-09-25)
|
||||
|
||||
The bundled extension is Manifest V3:
|
||||
The bundled MV3 extension (2026.9.2) runs `public/js/content-scripts/cpm.js` at `document_start` in isolated worlds/all matching frames. Its shared background entry point is the classic Service Worker `public/js/background-embedded.js`.
|
||||
|
||||
- Background entry point: `public/js/background-embedded.js`
|
||||
- CPM content script: `public/js/content-scripts/cpm.js`
|
||||
- Injection: `document_start`, isolated world, all frames
|
||||
- Content-to-background transport: `chrome.runtime.sendMessage`
|
||||
- Background receiver: `runtime.onMessage`, registered by `MessageRouter`
|
||||
`content script → runtime.sendMessage → WebKit tab/listener routing → background worker → Swift native settings/configuration → tabs.sendMessage(initResp) → page acknowledgement`
|
||||
|
||||
The content script sends an `autoconsent` message to the background service worker. The background routes that message and, where required, forwards it through native messaging.
|
||||
WebKit creates a hidden `WKWebView` whose page registers the worker. In the inspected checkout this extension worker uses **the host WebContent process’s main thread**, with a separate worker global. WebKit must find the host page in that process to install `browser`/`chrome` bindings. The Network process owns registration/jobs/client and connection bookkeeping. This is extension messaging, not a website’s offline/fetch Service Worker.
|
||||
|
||||
Context loaded, host alive, registration active, listener ready and current-document reply received are **different states**. Current diagnostics mostly observe the first two. Dashboard responses can precede `initResp`; the worker heartbeat is disabled for this main-thread mode. Detailed coverage, source links and validation priorities: [[cpm-service-worker-architecture-and-diagnostics]].
|
||||
|
||||
## Normal message path
|
||||
|
||||
@@ -1216,7 +1216,7 @@ Symptom match: all tabs, new tabs too, survives reload, banners not handled, das
|
||||
|
||||
**Observation (Alex, 2026-09-10):** with the delegate proxy installed (its lifetime tied to the background `WKWebView`), `kill -9` no longer breaks CPM; without the proxy, or with the proxy tied to the original delegate, it does. Reading: the outcome of step 4 depends on whether the dead P1 still exists as a `WebProcessProxy` when the Network process asks for the context connection — `processForIdentifier` is cleared only in `~WebProcessProxy` (`WebProcessProxy.cpp:488`), which is kept alive by the closed `WebPageProxy`, i.e. by the `WKWebView`. If P1 still resolves: `useProcessForRemoteWorkers(P1)` → send to a dead process → cancelled → Network's retry finds no clients → clean. If P1 is gone: fallback → stray process S → bug. The proxy shifts the view's dealloc by enough to win that race — accidental timing, not a fix.
|
||||
|
||||
**Graveyard experiment (implemented 2026-09-10):** `FeatureFlag.cpmBackgroundGraveyardExperiment` (subfeature `webExtensions.cpmBackgroundGraveyard`, cohorts `control`/`treatment`). Treatment: on the termination callback the recorder holds the dead background `WKWebView` strongly for `CPMMessagingDiagnosticsRecorder.graveyardHoldDuration` (3 s), so `processForIdentifier(P1)` keeps resolving while the Network process re-requests; control releases immediately. Pixel: `background_graveyard=control|treatment`. Prediction: treatment never shows `error_background_failed_to_load` after `died_*`; control does. Deterministic A/B: local-override the cohort, `kill -9`, watch `background_events`.
|
||||
**Graveyard mechanism (refreshed 2026-09-25):** current M5+M6 uses the dedicated `CPMBackgroundWebViewGraveyard`, with control/treatment selected by `cpmBackgroundGraveyardExperiment`. Treatment retains one terminated `WKWebView` and schedules release after 3 seconds. Keeping the native proxy graph alive lets the stale host-page process lookup resolve the terminated proxy instead of falling back to a standalone worker process. The intended effect is cancellation/failure of the stale connection request while clients drain—not revival of the dead worker. This timing benefit is an experimental hypothesis, not a guarantee that treatment never fails. A second death replaces the retained view; app suspension/main-queue blockage can delay scheduled release. Current diagnostics use `background_graveyard_cohort` and `bg_events`, alongside dedicated termination/outcome events. See [[cpm-service-worker-architecture-and-diagnostics]] for the source chain, M2 stable-origin interaction and outcome-measurement limitations.
|
||||
|
||||
**Delegate proxy flag:** `FeatureFlag.cpmBackgroundDelegateProxy` (subfeature `webExtensions.cpmBackgroundDelegateProxy`, remote-releasable, on by default). The recorder observes `FeatureFlagger.updatesPublisher`; turning it off hands WebKit's original delegate back on the live view (`CPMBackgroundWebViewDelegateProxy.uninstall`), turning it on re-installs.
|
||||
|
||||
|
||||
Reference in new issue
Block a user