2 Commits

Author SHA1 Message Date
4ea1bbb7a8 docs(debug): SC#1 sw-offscreen-persistence investigation session 2 — REFUTED-architecture (canvas-captureStream issue)
Session-2 (continuation of d614462 INCONCLUSIVE) executed disambiguation
plan and converged on a definitive verdict. Three independent observations
ruled out ALL architectural-failure hypotheses:

  Step A: race-tolerant offscreen target attach (committed separately;
  enabled visibility into the offscreen recorder + remux pipeline).

  Step B: pre-kill and post-kill segment-count probes via the existing
  `__mokoshOffscreenQuery 'get-segment-count'` bridge op (no new
  test-only symbols introduced; FORBIDDEN_HOOK_STRINGS inventory
  unchanged at 12 entries). Observed segments.length transition:
    POST-PRIME=0 → PRE-KILL=3 → POST-KILL=3
  Segments structurally survive the SW kill (offscreen still responds
  to bridge query post-kill). Hypothesis A (architectural RAM loss
  across SW termination) REFUTED.

  Step C: SPIKE_SKIP_SW_KILL=1 env-var mode skips worker.close(). The
  resulting videoSize is IDENTICAL to the canonical run (8505 bytes).
  Hypothesis C (CDP-induced offscreen collateral teardown) REFUTED.
  Since SW was not killed, its console listener stayed connected,
  exposing the full Remux pipeline output:
    [SW:Remux] Segment ts=1: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Segment ts=2: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Segment ts=3: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Remux complete: 0 frames, total timeline=0ms, output=8505 bytes
  Each segment Blob has a valid track header (PixelWidth/Height parsed
  successfully) but ZERO VP9 frames. Hypothesis B (canvas-captureStream
  throttling in headless idle) CONFIRMED.

VERDICT: REFUTED-architecture (canvas-captureStream issue).

The architecture (offscreen-RAM `segments: Blob[] = []`) works
correctly; the spike's test methodology is invalid. The
`installFakeDisplayMedia` synthetic stream (canvas.captureStream(30)
on a hidden -9999px-offset 320x180 canvas) cannot sustain frame
production during a 5-min headless idle window despite the
`setInterval(drawFrame, 33ms)` belt-and-suspenders mitigation. This
matches the documented Chromium throttling of MediaRecorder on
invisible-canvas sources (Chrome bug 653548; auto-throttled-screen-capture
design doc; sendrec.eu blog "Why Canvas Breaks Your Screen Recorder").

ROUTING RECOMMENDATION (out of scope for this debug session):
  - Do NOT proceed with the IndexedDB persistence plan-fix proposed by
    Plan 04-04 SUMMARY. The plan-fix would NOT close SC #1 because the
    spike would STILL produce 8505 bytes after IDB lands — the failure
    is in the test's fake stream, not in segment persistence.
  - Open a new plan slot (likely Plan 04-08 or a Phase 5 plan) that
    reframes SC #1 verification methodology. Options:
      (a) real getDisplayMedia in non-headless Puppeteer with
          --auto-select-desktop-capture-source;
      (b) video-file-backed MediaStream source (HTMLVideoElement
          playing a bundled WebM) — bypasses canvas-captureStream
          throttling entirely;
      (c) reduce SC #1 wall-clock idle threshold to a value short
          enough that canvas-captureStream survives (e.g., 30s) AND
          add a separate manual operator-empirical test for 5-min.

ROADMAP SC #1 status: REMAINS OPEN. The architecture is sound; the
empirical verification gate is broken. Plan 04-04 SUMMARY's
characterization ("spike FAILED → architectural plan-fix needed") is
TECHNICALLY CORRECT on the first clause but INCORRECT on the second —
the spike's failure mode is in test infrastructure, not in production
code.

Files in this commit:
  - tests/uat/spike-a33-sw-persistence.ts: added probeSegmentCount
    helper using existing __mokoshOffscreenQuery bridge op; 3
    checkpoints (POST-PRIME / PRE-KILL / POST-KILL); SPIKE_SKIP_SW_KILL=1
    env-var skips worker.close() for Step C disambiguation.
  - .planning/debug/sw-offscreen-persistence-investigation-session-2.md:
    NEW session-2 debug note documenting full evidence trail + verdict
    derivation + routing recommendation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 08:02:24 +02:00
3726eee39f feat(04-04): Wave 0 spike — stopServiceWorker helper + 5-min SW idle empirical result
SPIKE OUTCOME: FAILED (offscreen DIED across 5-min SW idle + worker.close())

Per Plan 04-04 spike-first contract, Wave 0 empirically investigated whether
the offscreen document's RAM-only `segments: Blob[] = []` at
src/offscreen/recorder.ts:91 survives a 5-min SW idle followed by Puppeteer
CDP-driven `worker.close()`. RESEARCH Q2 hypothesis (MEDIUM confidence): yes,
the offscreen has its own lifecycle anchored by active MediaRecorder. Spike
result REFUTES that hypothesis.

Empirical measurement (HEADLESS=1; one full run; reproducible via the
committed spike script):

  - assertA2 priming: PASSED (badge=REC; offscreen + MediaRecorder live)
  - 5-min idle:        elapsed cleanly (308.7s total wall-clock)
  - stopServiceWorker: succeeded (worker.close() returned)
  - SAVE_ARCHIVE ack:  {success: true} (SW respawned + processed message)
  - video/last_30sec.webm size: 8505 bytes (well below 100 KB floor)
  - meta.urls: only chrome-extension://* origins; real-page URLs LOST
  - rrweb/session.json: []
  - logs/events.json: []
  - ffprobe on extracted webm: 'End of file' + 'Duplicate element' errors
    (corrupt/truncated; not a valid 30s segment cluster sequence)

Interpretation: offscreen-document lifecycle is NOT independent of the SW
under Puppeteer CDP-driven worker.close() conditions. The 8505 bytes are
likely stale/partial header bytes from a re-initialized empty offscreen
context after SW respawn, not a surviving 30s buffer. The plan's Task 2
GATING CONDITION (videoSize > 100_000) is NOT satisfied; Task 2 is BLOCKED.

Per saved memory `feedback-gsd-ceremony-for-fixes.md`: architectural changes
(moving segments from offscreen RAM to IndexedDB per RESEARCH Q2 sub-question
b Option C) MUST route through proper plan-fix ceremony, NOT improvised
inline inside Plan 04-04. Plan 04-04 SUMMARY flags the failure mode + cites
exact remediation path. ROADMAP SC #1 remains OPEN pending the persistence-
layer plan-fix.

Task 1 persisting artifacts (this commit):
  - tests/uat/lib/harness-page-driver.ts:
    + Browser type import (puppeteer)
    + stopServiceWorker(browser, extensionId) helper (verbatim from Chrome
      devrel canonical pattern — Puppeteer >=22.1.0; project pin ^25 OK)
    + findLatestZip exported (was module-internal) so the spike script can
      reuse the canonical mtime-sort selection logic without duplication
  - tests/uat/spike-a33-sw-persistence.ts (NEW):
    + One-shot empirical investigation script; reusable for future SW-
      lifecycle regression testing (e.g., verifying the eventual IndexedDB
      persistence layer actually closes ROADMAP SC #1)
    + Step 1 reuses __mokoshHarness.assertA2 (canonical fresh-recording
      prime; not the non-existent dispatchSaveArchive that REVISION iter-2
      explicitly forbids)
    + Step 5 dispatches SAVE_ARCHIVE via chrome.runtime.sendMessage inline
      from harness-page realm (Option B per plan-checker BLOCKER 2;
      matches A5/A11/A12/A13/A26/A28/A29/A30/A31 pattern)

Verification (Task 1 acceptance criteria):
  - npx tsc --noEmit: exits 0
  - HEADLESS=1 tsx tests/uat/spike-a33-sw-persistence.ts: ran to completion
    (no Puppeteer throw); SPIKE RESULT line emitted with explicit
    videoSize=8505 bytes; SAVE_ARCHIVE ack received
  - grep -c 'dispatchSaveArchive' tests/uat/spike-a33-sw-persistence.ts: 0
  - grep -c "type: 'SAVE_ARCHIVE'" tests/uat/spike-a33-sw-persistence.ts: 1
  - Total spike wall-clock: 308.7s (~5min idle + ~8s orchestration)

References:
  - Plan 04-04 PLAN.md spike contract (lines 64-72)
  - 04-RESEARCH.md Q2 sub-question (b) — Chrome MV3 offscreen lifecycle
  - https://developer.chrome.com/docs/extensions/how-to/test/test-serviceworker-termination-with-puppeteer
  - Saved memory: feedback-gsd-ceremony-for-fixes.md (no inline architectural
    fixes; route through plan-fix ceremony)
2026-05-21 18:44:45 +02:00