Skip to content

[codex] fix PWA push reliability - #42

Merged
Just-Insane merged 1 commit into
integrationfrom
codex/fix-pwa-push-reliability
Jun 12, 2026
Merged

[codex] fix PWA push reliability#42
Just-Insane merged 1 commit into
integrationfrom
codex/fix-pwa-push-reliability

Conversation

@Just-Insane

Copy link
Copy Markdown
Collaborator

Description

Fixes mobile PWA push reliability issues where stale service-worker visibility state could suppress OS notifications after iOS backgrounding. The SW now requires a fresh nonce-based visible-client acknowledgement before suppressing an OS push, sends a generic in-app fallback banner when the app is visible but sync is unhealthy, and buffers sanitized push telemetry until the page can drain it into Sentry.

This also restores the phased foreground SW session refresh behavior from upstream SableClient#573, keeps the current foreground sync retry behavior, and adds opt-in client support for WebKit Declarative Web Push fallback payloads. The declarative path only advertises/handles payloads; the push gateway must still emit the declarative JSON.

Related upstream research:

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).
    Codex implemented the service-worker visibility confirmation handshake, push telemetry buffering, visible-sync-unhealthy in-app fallback handling, declarative Web Push fallback mapping, pusher metadata opt-in, restored sessionSync foreground session refresh, documentation, changeset, and focused tests under user direction.

Validation

  • pnpm lint && pnpm fmt:check && pnpm typecheck && pnpm test:run && pnpm knip && pnpm build

Note: lint exits successfully with existing unrelated warnings in ClientConfigLoader, usePresenceSync, CallWidgetDriver.test, and mediaTransport.test.

@Just-Insane
Just-Insane marked this pull request as ready for review June 12, 2026 17:36
Copilot AI review requested due to automatic review settings June 12, 2026 17:36
@Just-Insane
Just-Insane merged commit bced196 into integration Jun 12, 2026
12 of 13 checks passed
@github-actions

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

Status Preview URL Commit Alias Updated (UTC)
✅ Deployment successful! https://pr-42-sable.justin-tech.workers.dev aff6ffd pr-42 Fri, 12 Jun 2026 17:37:44 GMT

Comment on lines +133 to +144
function navigateToServiceWorkerUrl(navigate: ReturnType<typeof useNavigate>, url: string): void {
try {
const target = new URL(url, window.location.origin);
if (target.origin === window.location.origin) {
navigate(`${target.pathname}${target.search}${target.hash}`);
return;
}
} catch {
// Fall through to browser navigation for malformed/relative strings.
}
window.location.assign(url);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fallback window.location.assign(url) will navigate to any scheme/origin when navigateUrl comes from a service worker message (ultimately push payload data). This can enable cross-origin redirects or potentially dangerous schemes (e.g. javascript:/data:) on notification click/in-app fallback.

Comment on lines +260 to +267
if (document.visibilityState === 'visible' && navigator.onLine) {
if (!phase3AdaptiveBackoffJitter || now >= suppressHeartbeatUntilRef.current) {
const result = pushSessionNow('heartbeat');
if (phase3AdaptiveBackoffJitter && result === 'sent') {
heartbeatFailuresRef.current = 0;
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

phase3AdaptiveBackoffJitter uses heartbeatFailuresRef.current to compute exponential backoff, but heartbeatFailuresRef is never incremented. As a result, the adaptive backoff/jitter path behaves the same as the fixed-interval heartbeat.

Comment on lines +237 to +241
useEffect(() => {
if (!phase2VisibleHeartbeat) return undefined;

heartbeatFailuresRef.current = 0;
suppressHeartbeatUntilRef.current = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The new sessionSync strategy logic (foreground debounce + heartbeat + adaptive backoff/jitter) in this hook is non-trivial but has no unit tests. There are already Vitest tests for other hooks (e.g. useClientConfig.test.ts, useRoomNavigate.test.ts), so adding focused fake-timer tests here would help prevent regressions in the push reliability work.

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.

2 participants