#13300

[Design] Streaming and worker isolation for Playwright traces, WebSourceMapFetcher, CaptureJson, Asset Catalog, and AnalysisView files

Openmorlutoopened 4d ago

Before submitting

  • I searched the open and closed issues and pull requests for a related discussion (#13281, #13275).
  • I understand the contribution scope must be reviewed before integration; open questions are welcome here.
  • This discussion does not include credentials, private samples, or sensitive target data.

Decision needed

Should REA move remaining heavy main-thread capture, source-map, asset-catalog, and AnalysisView I/O onto bounded worker/streaming pipelines and indexed/retained Evidence views:

  1. Worker isolation & selective line skipping for inspect_playwright_trace (avoiding full object materialization and 64x heap headroom checks on multi-MB discarded frame-snapshot DOM lines),
  2. Worker execution & lazy/on-demand source-map decoding for WebSourceMapFetcher.normalizeSourceMap and WebModuleTraceService (moving up to 64 MiB JSON parse, VLQ mapping expansion, and full sourcesContent Babel AST parsing off the parent event loop, plus avoiding 50 MB inline source_map_text embedding in trace_web_source_location Evidence.rawResult),
  3. Single-pass streaming JSON & deduplicated HAR bodies in CaptureJson / HarCapture (avoiding jsonc-parser per-token Map/LosslessNumber/JSON.parse overhead and 2x base64 duplication between reported and binary_fields), and
  4. Indexed/retained paging across AnalysisViewService (--evidence-bundle / evidence-file) and inspect_asset_catalog (instead of re-reading/re-parsing 100 MB Evidence JSON or re-running assetutil + Interface Builder decoding on every page)?

Context and evidence

Source-derived analysis of REA's JavaScript, Browser, Capture, Artifact, and AnalysisView pipelines:

  1. Playwright trace (src/browser/history/playwrightTrace/TraceStream.ts:146-225, TraceEventProjection.ts:106-114):
    • Runs in-process on the main event loop without a worker timeout.
    • Calls readRecord(line.bytes) (full parseCaptureJson parse + heap headroom multiplier check) on every NDJSON line before inspecting raw.type, even though projectTraceEvent / selectedEvent immediately discards frame-snapshot DOM snapshots (typically the largest lines in real traces).
  2. Web source maps & module tracing (src/browser/WebSourceMapFetcher.ts:1028-1316, src/application/WebSourceLocationService.ts, src/application/WebModuleTraceService.ts):
    • normalizeSourceMap (WebSourceMapFetcher.ts:1028-1236) parses up to 64 MiB source map JSON, decodes all VLQ segments, charges per-segment mappingRowBytes and JSON.stringify(edge) budgets, and runs synchronous Babel parseJavaScriptSource over every embedded sourcesContent file (originalModuleEdges, lines 1244-1316) directly on the parent event loop — blocking timers and MCP cancellation delivery.
    • trace_web_source_location retains full source_map_text inline inside Evidence.rawResult, causing full canonical serialization, SHA-256 hashing, and cloning per point query.
  3. Historical capture JSON (src/browser/history/CaptureJson.ts, HarCapture.ts):
    • CaptureJson builds full Map + Object.fromEntries + LosslessNumber + per-string JSON.parse trees over entire HAR/qlog files via jsonc-parser visit(), and HarCapture clones the tree for AJV validation and retains base64 bodies twice (reported.response.content.text and binary_fields[].content_base64), amplifying memory and max_reply_bytes failures.
  4. Repeated cold reloads on paginated inspections (src/artifacts/apple/AppleAssetCatalogAnalysis.ts:102-200, src/application/analysisView/AnalysisViewService.ts):
    • inspect_asset_catalog re-walks .app, re-runs /usr/bin/assetutil, and re-decodes all Interface Builder .nib/.storyboardc files on every offset/limit page call.
    • inspect_analysis_view on evidence-file / --evidence-bundle re-reads, re-parses, validates, and deep-freezes the full Evidence JSON from disk on every paginated page/view call, and api-surface / environment-manifest / environment-state views re-run accumulation/simulation across calls.

Expected interaction with targets

  • Read existing files or captured data (local captures, source maps, asset catalogs, and Evidence files under existing read-only bounds).

Boundary details (optional)

  • Preserving strict JSON structural checks (duplicate keys, nesting depth, parser node bounds, exact integer precision) and incomplete/malformed diagnostics in Playwright/HAR/qlog must remain equivalent when introducing lightweight pre-filters or streaming parsers.
  • For inspect_asset_catalog and AnalysisViewService, any retained state or index must verify file/target freshness (dev, ino, size, mtime/ctime or digest verification) before reuse.

Options and tradeoffs

  • Playwright trace: Peek top-level "type" and validate JSON well-formedness/depth for discarded frame-snapshot events without allocating full JS object graphs, and run the decoder inside a supervised worker with an explicit timeout and time/byte-based yielding.
  • Web source maps & WebModuleTraceService: Execute normalizeSourceMap and WebModuleTraceService Babel parsing in the existing worker pool, decode only queried lines lazily on point lookups, and store large source-map text by digest/reference rather than inline per lookup in Evidence.rawResult.
  • Asset catalog & AnalysisView: Align inspect_asset_catalog with retained Evidence + inspect_analysis_view (or verify freshness cleanly), and provide an indexed/verified reader for repeated paginated evidence-file reads.

Verification available so far

  • Idea only; I need help defining checks

Success criteria and open questions

  • Should trace_web_source_location omit full inline source_map_text from Evidence.rawResult in favor of a digest/byte summary or opt-in flag?
  • Can inspect_asset_catalog transition to the shared detail + inspect_analysis_view pattern used by inventory_artifacts and analyze_javascript_application?
  • What strict JSON validation invariants (duplicate keys, large-integer fidelity) must a streaming fast-path for CaptureJson / TraceStream preserve?

References

  • Related issue: #13281, #13275
  • src/browser/history/playwrightTrace/TraceStream.ts:146-225
  • src/browser/history/playwrightTrace/TraceEventProjection.ts:106-114
  • src/browser/WebSourceMapFetcher.ts:1028-1316
  • src/artifacts/apple/AppleAssetCatalogAnalysis.ts:102-200
  • src/application/analysisView/AnalysisViewService.ts

Activity

0

No activity yet.