Skip to content

fix(sdk-recorder): isolate uploads from restarted capture - #3380

Open
vedanth-jadhav wants to merge 1 commit into
CapSoftware:mainfrom
vedanth-jadhav:fix/sdk-stale-upload-ownership
Open

vedanth-jadhav wants to merge 1 commit into
CapSoftware:mainfrom
vedanth-jadhav:fix/sdk-stale-upload-ownership

Conversation

@vedanth-jadhav

@vedanth-jadhav vedanth-jadhav commented Oct 26, 2026 •

Copy link
Copy Markdown

Destroying and restarting the SDK recorder while an older stop() awaits video creation, upload or completion lets the old response overwrite the replacement's video ID/phase and run cleanup() against its live capture. The encoder identity was checked before upload, but ownership was lost across its later asynchronous calls.

Carry that encoder identity through upload, check ownership after each await and before handling errors, and reject stale operations with AbortError without emitting errors/completion or releasing replacement tracks. Snapshot the stopped recording's duration. Guard cleanup after user completion/error callbacks too, because those callbacks can restart capture synchronously.

The SDK declaration build also exposed the existing generic unsubscribe error: registration widened the callback type while deletion used the original narrower type. Reuse the same typed callback reference for registration and removal; runtime subscription identity and public APIs are unchanged.

Validation (Linux x86_64, Bun 1.4.4, TypeScript 5.8.3, tsup 8.5.1):

  • All 43 SDK tests pass, including eight new cases. Six delayed-response regressions first failed against unchanged production source; both successful and rejected create/PUT/complete responses now preserve a restarted recording. Tests also verify restarting directly from complete/error callbacks, and that the replacement still stops/uploads normally.
  • 12 capture lifecycle tests pass against the built ESM package, using a temporary test driver outside the committed diff. The two prototype-spy callback cases are source tests only.
  • Package tsc --noEmit, scoped strict source/test TypeScript, full ESM + declaration build, Biome and git diff --check pass. The pre-existing unsubscribe TS2345 was reproduced on baseline before the callback-reference correction.

Reproduce: cd packages/sdk-recorder && bun test && bun run typecheck && bun run build. Build tools were installed outside the checkout; no manifest, lockfile or generated-output changes. Capture and network events are controlled test fixtures; physical browser/device capture was not run. Existing in-flight remote requests can still finish after destroy; this change prevents their results from mutating a later recording and does not claim network cancellation. Extends the pre-upload stop ownership check from merged #3191; browser uploader cancellation #3353 is a separate implementation.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

The PR keeps an older upload from changing or cleaning up a restarted recording.

  • Older uploads stay separate from a restarted capture.
  • Event listeners use one callback reference for adding and removing.

No actionable issues were found. Review checks were source-based; tests were not run during this review.

Reviews (1) · Last reviewed commit: "fix(sdk-recorder): isolate asynchronous ..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 26, 2026 12:11pm UTC

This branch was previously deployed

1 inactive deployment
Preview – cap-status — 274144a6 Deployed Oct 26, 2026 by vercel[bot]
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.

1 participant