Skip to content

fix(portal): chunk expiry timers beyond 32-bit setTimeout limit - #1971

Merged
callumalpass merged 1 commit into
mainfrom
fix/portal-accessibility-audit
Nov 26, 2026
Merged

callumalpass merged 1 commit into
mainfrom
fix/portal-accessibility-audit

Conversation

@callumalpass

Copy link
Copy Markdown
Member

Cause

useRequestExpiry in apps/portal/src/authorization-review.tsx and the pending-authorization expiry effect in apps/portal/src/ConnectApp.tsx passed Math.max(0, Date.parse(expiresAt) - Date.now()) directly to window.setTimeout.

Browser setTimeout delays use a signed 32-bit integer (2^31 - 1 ms, ~24.85 days). When a deadline is further in the future (such as the 2099-08-01T00:00:00.000Z fixture in scripts/browser-accessibility.test.mjs), Chromium truncates the delay modulo 2^32 to a signed 32-bit integer (ToInt32). Once (Date.parse("2099-08-01T00:00:00.000Z") - Date.now()) wrapped across a 2^32 boundary at 2026-11-26T17:11:04Z, the truncated value became negative, which Chromium clamps to 0ms.

As a result:

  • useRequestExpiry fired onExpire() immediately on the next tick, unmounting <RequestIdentity> and its app icon right after initial render and replacing it with the expired outcome — causing auditPortalColdStartAuthorization (scripts/browser-accessibility.test.mjs:720) to time out waiting for .request-identity-mark img[src="https://journal.example/icon.png"].
  • ConnectApp's pending-authorization expiry timer had the same overflow, triggering an immediate re-render loop for far-future expiries.

Fix

  • Add scheduleAtDeadline in apps/portal/src/portal-model.ts, which reschedules in chunks capped at MAX_TIMEOUT_MS (2_147_483_647 ms), ignores non-finite timestamps, and cleanly cancels the active timer on cleanup.
  • Use scheduleAtDeadline in both useRequestExpiry (apps/portal/src/authorization-review.tsx) and ConnectApp (apps/portal/src/ConnectApp.tsx).
  • Add regression tests in apps/portal/src/authorization-return.test.tsx.

CI coverage note

In .github/workflows/server-ci.yml, pnpm test:accessibility is gated on needs.classify.outputs.run_full == 'true'. On pull_request events, run_full is only true when native paths change (scripts/ci/server-test-plan.mjs) or the ci:full label is applied, so this check does not run on ordinary non-native PR heads — it runs in merge_group (and on push to main when no matching merge_group run succeeded).

Verification

  • pnpm --filter @mdbase/connect-portal typecheck
  • pnpm --filter @mdbase/connect-portal test
  • pnpm test:accessibility
  • pnpm ci:local

@callumalpass
callumalpass marked this pull request as ready for review November 26, 2026 22:12
@callumalpass
callumalpass added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 9c900d6 Nov 26, 2026
9 checks passed
@callumalpass
callumalpass deleted the fix/portal-accessibility-audit branch November 26, 2026 22:37
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