Skip to content

refactor: use Promise.withResolvers for deferred promises - #5158

Merged
thymikee merged 1 commit into
mainfrom
t3/promise-with-resolvers-migration
Nov 28, 2026
Merged

thymikee merged 1 commit into
mainfrom
t3/promise-with-resolvers-migration

Conversation

@thymikee

@thymikee thymikee commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Hand-built deferred promises become Promise.withResolvers() (Node >=22.12). tsconfig.json now lists the previous default libs plus ES2024.Promise.

Converted 138 sites: 23 production, 115 in test support, test-kit and the ten test files with the most sites (excluding files open in #5150/#5151). Three local deferred() helpers are deleted. Two abort listeners now call () => aborted() for types.

Skipped production sites:

  • Executor does extra work (listeners, timers, socket handlers): runner-io, runtime-common, artifact-tracking, device-mutation-drain, snapshot-helper-retirement, logs/start, native-build/host, toolchain-identity, provider-lease-table waiter, tv-cdp/cdp.
  • Open fix(remote)!: never send credentials over plain http off loopback #5150: client-companion-tunnel-worker, limrun-ios-runner.

Value

  • Captured resolve/reject sites: 492 → 354
  • Production sites: 35 → 12
  • Shared harness deferred() helpers: 3 → 0
  • Diff: +285 / −663

Validation

At 2306c29099ad43b491078cce4eb8134324b6136d, passed: pnpm typecheck; oxlint and oxfmt --check on changed files; layering scan; Vitest on changed tests plus snapshot-source fixture users (232 tests); pnpm test:concurrency-torture. Compiler lib list differs only by lib.es2024.promise and the es2022.full aggregator.

CI pending. No independent reviewer; I reread the production diff and test additions.

Follow-up: 327 sites in 170 test files (* open in #5150/#5151; .test.ts and packages/…/src omitted)
apple-runner/__tests__: runner-artifact-reuse runner-artifact-start-admission runner-disposal runner-exchange runner-lease-accessibility runner-lifecycle-request-cancellation runner-process-launch runner-session-close runner-session-close-finalization runner-session-close-prep-fence runner-session-lifecycle runner-session-speculative runner-usbmux-boundary-faults runner-usbmux-fixtures.ts
capture-kit: app-log-pid-runtime audio-probe-runtime provider-app-log-poller screen-recording-live-handle
capture-kit/capture-admission/__tests__: audio-probe-session-resource durable-capture-resource-boundary-faults
capture-kit/durable-capture: adoption fence transitions
capture-kit/recording: video
command-runtime/commands/interaction/runtime: selector-wait-cancellation wait-deadline wait-polling
contracts: startup-recovery-fence
daemon-client/__tests__: daemon-client-ensuring daemon-client-lease-beat daemon-client-remote-health-cache daemon-client-startup-budget daemon-client-startup-race daemon-client-transport daemon-client-transport-abort-timeout daemon-client-transport-request-guard
daemon-contracts: device-claim-owner-recovery device-claim-reconciliation
daemon/__tests__/support: human-control-fixtures.ts
daemon/core: composite-resource-admission composite-resource-admission-ime
daemon/core/__tests__: request-runtime-binding request-runtime-binding-router
daemon/execution: generic-settle selector-runtime-get-lifecycle
daemon/execution/__tests__: selector-capture-runtime
daemon/execution/handlers/__tests__: session-selector-dispatch
daemon/execution/interaction/internal: interaction-settle
daemon/execution/interaction/internal/__tests__: interaction-snapshot-scope interaction-touch-reference-frame interaction-touch-response
daemon/resources/__tests__: app-log-resource-recovery app-log-session-resource
daemon/server: downloadable-artifact-http
daemon/server/__tests__: daemon-runtime-app-log http-server-rpc-admission human-control-http provider-lease-expiry request-execution-scope* request-execution-scope-lease-expiry* request-router-install-source-deadline request-router-open request-router-record-runtime-lock request-router-replay-scope request-router-screenshot request-router-web-sessions resumable-upload session-idle-expiry-harness.ts upload-http-deadline upload-http-ingress upload-http-socket-ownership
daemon/server/http: daemon-runtime-lifecycle-shutdown daemon-runtime-quiesce* daemon-runtime-snapshot-shutdown daemon-session-idle-expiry http-server-boundary-cancellation http-server-provider-scenarios* http-server-proxy http-server-proxy-rollback response-disconnect-signal transport
daemon/sessions: snapshot-command-runtime-cancellation
daemon/sessions/__tests__: request-recording-health session-idle-activity
daemon/sessions/__tests__/replay-divergence: session-replay-divergence-observation
daemon/sessions/handlers/__tests__: record-runtime-stop-recovery session-doctor-device session-reinstall
daemon/sessions/session-lifecycle/internal/__tests__: session-close-resource-cleanup session-open-execution-runtime
host-kit/internal: archive-extraction-tar exec-kill-settle exec-trace request-cancel
host-swift: swift-cache
platform-android: ime-rebind ime-restore lifecycle
platform-android/__tests__: alert ime-lifecycle ime-lifecycle-race settings-locale snapshot-helper-capture touch-helper-cancellation
platform-android/logs: runtime
platform-android/recording: runtime
platform-android/shutdown: runtime
platform-apple: detached-attempt inventory launch-confirmation lifecycle runner-snapshot-bridge snapshot-route snapshot-target system-surface-foreground
platform-apple/core/__tests__: perf plist screenshot screenshot-rotation-read screenshot-status-bar-concurrency
platform-apple/foldable: fold-helper-cache orientation runner-panel
platform-apple/recording: runtime
platform-apple/snapshot-source: adapter cache lifecycle preparation
platform-harmonyos/logs: runtime
platform-web/__tests__: agent-browser-provider-fleet-record
provider-limrun: android capture-lifecycle deployment-runtime ios-runner-lifecycle lease-release lease-release-observation request-cancellation sync-cache
provider-revyl: interactor
provider-testmu: testmu
provider-webdriver: browserstack runtime-session-allocation webdriver-transport
provision-kit: install-source-deadline provider-lease-table
proxy: daemon-proxy-cancellation* daemon-proxy-transfer* transfer-transport-lifetime
react-native/companion: client-companion-tunnel-worker
remote/__tests__: artifact-download upload-client-cancellation
replay-test/internal/__tests__: session-test-runtime
session-journal/__tests__: session-event-log-window
src: platform-runtime-app-log-process platform-runtime-gateway platform-runtime-provider-scope platform-runtime-screen-recording-apple-simulator-host platform-runtime-screen-recording-host platform-runtime-screen-recording-process-host
src/__tests__: platform-runtime-claim-recovery-disposal takeover-command
src/cli/replay-test/reporters/__tests__: registry
src/core: limrun-download-file*
src/core/interactors: limrun-ios-runner* limrun-ios-tools
test/integration/provider-scenarios: composite-deadline ios-fold limrun-deployment-cancellation remote-upload-lease-beat
tv-cdp: runtime

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

Replaces captured resolve/reject pairs in production code, shared test
fixtures, and the ten test files with the most sites. Adds the
ES2024.Promise lib and keeps the previous default libs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.67 MB 6.67 MB +378 B
Package (unpacked) 6.67 MB 6.67 MB +378 B
Package (download) 2.04 MB 2.04 MB +115 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.2 ms 24.3 ms +3.1 ms
CLI --help 49.8 ms 48.7 ms -1.1 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 38 files

View guided diff | Turn on auto-fix | Re-trigger cubic

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 2306c29

No open findings.

Reviewed with this repository's own Sentinel configuration (f0b3cb684685).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at 2306c29, and no code problems were found. Not blocking: the reattach mocks in recovery-authority.test.ts (also near lines 131, 198, 273 and 345) now share one precreated gate per test, so a regression that starts two reattachments and waits for both could pass the late-cleanup assertions; wrapping each callback in vi.fn and asserting exactly one call would restore that check, and this can be taken or left because no production regression follows from it today.

CI passes at this commit: all checks succeed except Proof (skipped) and two cancelled Body rules runs, a third Body rules run succeeded, and that check does not exercise the changed code. The iOS, macOS and Android smoke steps ran and passed.

Not verified here: no tests were run locally or on Node 22.12, and the CI 22.12 step checks the packed package, so it does not necessarily reach every converted call. Not verified here: the smoke logs were not read, so it is not shown that the IME restore fence, detached attempt, simulator log first write or snapshot bridge queue branches were reached; their equivalence rests on reading the diff. Not verified here: in some converted tests an early resolve no longer throws because the resolver now exists before the mock runs; test files were only sampled, and no test that would pass vacuously was identified.

Nothing else from this review needs to happen before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 27, 2026
@thymikee
thymikee merged commit c888eb3 into main Nov 28, 2026
23 of 28 checks passed
@thymikee
thymikee deleted the t3/promise-with-resolvers-migration branch November 28, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant