Skip to content

feat(amp-semantic): add composable capture runtime - #2120

Merged
jxiwang merged 11 commits into
mainfrom
codex/semantic-context-visibility-events
Nov 5, 2026
Merged

jxiwang merged 11 commits into
mainfrom
codex/semantic-context-visibility-events

Conversation

@jxiwang

@jxiwang jxiwang commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add the shared capture runtime on top of the merged package scaffold (#2113). No production event recorders are installed by default, and no SDK depends on this package yet.

The runtime provides typed recorder registration, opt-in sampling, per-session event caps, start/stop and reset, event identity/version/timestamp stamping, host snapshot signals, error isolation, and cleanup rollback. Its lazy identity fallback uses document-scoped memory only. Recorders explicitly acknowledge delivered dropped-event diagnostics. Failed transport releases its reserved cap slot, and each registered teardown runs once. The runtime has no context-specific behavior.

The recorder contract includes only capabilities used by the planned context and visibility recorders. Removed unused event subscriptions, snapshot-state inspection, and redundant capacity/enabled checks.

Stack

  1. This PR: shared runtime.
  2. Context recorder: feat(amp-semantic): add context recorder #2126 (codex/semantic-context-recorder).
  3. Session Replay integration: feat(session-replay): integrate semantic context capture #2127 (codex/semantic-replay-integration).
  4. Visibility recorder: feat(amp-semantic): add visibility recorder #2128 (codex/semantic-visibility-recorder).

The former combined implementation is preserved in commit ae9b929 (also retained on the local backup branch codex/semantic-context-visibility-preserved). This branch incorporates current main, including the merged scaffold, without rewriting existing history.

Validation

  • Node 24: install, full workspace build, docs, lint and dependency checks passed.
  • All 32 workspace test projects passed; runtime tests cover 100% of statements, branches, functions, and lines (23 tests).
  • Package typecheck and diff checks passed.
  • Existing blocker retained with prior maintainer approval: pnpm test:examples cannot start because jest.setup.examples.js is missing on main.

Note

Medium Risk
The runtime adds non-trivial lifecycle, sampling, and reentrancy behavior that future recorders will rely on, but nothing in the monorepo consumes it yet and transport/consent stay with the host.

Overview
Replaces the envelope-only @amplitude/amp-semantic scaffold with a composable browser capture runtime exposed as createSemanticCapture, while still shipping no default recorders and no Session Replay wiring.

The host provides document, window, and an emit transport; optional typed recorder factories register listeners only when enabled families pass session sampling and per-family caps (default 200). The runtime centralizes start/stop, config updates, session reset (new sample + counters), snapshot host signals, lazy v/timestamp/tab_id/document_id stamping (with getDocumentIdentity fallback in memory), canEmit/dropped/clearDropped, and error-isolated teardown including rollback when setup or transport fails reentrantly.

Public types grow to cover SemanticHost, SemanticRecorder, and RecorderContext; README and Jest switch to jsdom-backed lifecycle tests (~23 cases). Follow-up PRs are expected to add concrete recorders and replay integration.

Reviewed by Cursor Bugbot for commit c1d9fe0. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Session Replay Browser E2E Results

passed  156 passed
flaky  1 flaky

Details

stats  157 tests across 18 suites
duration  4 minutes, 28 seconds
commit  ae9b929

Flaky tests

chromium › e2e/shadow-dom.spec.ts › captureAdoptedStyleSheets option › SDK initializes without error and captures shadow host with captureAdoptedStyleSheets=false

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 68.37 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 138.23 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 224.34 KB (0%)
@amplitude/element-selector (gzipped esm) 3.48 KB (0%)
@amplitude/analytics-browser/lite (gzipped CDN bundle) 21.29 KB (0%)

Base automatically changed from codex/semantic-context-visibility to main November 4, 2026 20:30
@jxiwang jxiwang changed the title feat(amp-semantic): add context and visibility capture feat(amp-semantic): add composable capture runtime Nov 4, 2026
@jxiwang
jxiwang marked this pull request as ready for review November 4, 2026 21:59
@jxiwang
jxiwang requested a review from a team as a code owner November 4, 2026 21:59
@jxiwang

jxiwang commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/amp-semantic/src/capture.ts Resolved
Register rollback cleanup before recorder setup so reentrant stop,
reset, or config updates can tear down listeners registered during setup.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/amp-semantic/src/capture.ts Resolved
Track attach generations so a nested resetSession or updateConfig during
recorder setup does not leave the outer attach loop installing recorders
again after the nested attach completes.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/amp-semantic/src/capture.ts Resolved
Skip registering the setup return cleanup when detach already ran during
reentrant stop or reset, so the same function is not torn down twice.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread packages/amp-semantic/src/capture.ts Resolved
When setup reenters resetSession or updateConfig and then throws, abort the
stale outer attach loop so recorders are not installed twice.
@jxiwang

jxiwang commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

2 issues from previous reviews remain unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c1d9fe0. Configure here.

@jxiwang
jxiwang merged commit 0f80267 into main Nov 5, 2026
19 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.

3 participants