Skip to content

[No QA] stop the pong watchdog from reconnecting Pusher - #98884

Merged
mountiny merged 1 commit into
Expensify:mainfrom
callstack-internal:2800-pong-watchdog
Aug 19, 2026
Merged

[No QA] stop the pong watchdog from reconnecting Pusher#98884
mountiny merged 1 commit into
Expensify:mainfrom
callstack-internal:2800-pong-watchdog

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

The watchdog declares a live socket dead. The 60 second threshold equals the PING cadence the app reaches in production.

This change deletes the reconnect. Recovery moves to the Pusher SDK, which detects a dead socket with a websocket ping frame on the connection under test. A false alarm no longer discards a working socket or pulls a full ReconnectApp sync behind it.

Proof

Baseline window 2026-08-12T10:30:00Z to 14:30:00Z. The window matches the weekday and the hours of the original measurement. After values are the prediction this PR is measured against.

Metric Before After
presumed dead fires per 4h 96,667 across 20,163 users, 4.79 each 0
Watchdog reconnects per day 565,054 0
Users firing 20 or more times per 4h 541 users, 38,192 fires 0
presumed alive log lines per 4h about 1,450,000 0
Pushed ReconnectApp per user per 4h 5.45 4.25 to 4.47, a fall of 18% to 22%
Control: GetMissingOnyxMessages did not advance 1.10 per user must not rise

Fixed Issues

$ #98886
PROPOSAL:

Tests

  1. Run npx jest tests/unit/PusherPingPongTest.ts. Two tests pass. No PONG for 300 seconds produces the log line and no Pusher.reconnect() call. The PING still goes off the durable write queue.
  2. Sign in on web. Confirm chat messages arrive. Put the machine to sleep for 5 minutes, then wake it. Confirm messages resume without a reload. Allow up to 150 seconds, because recovery now comes from pusher-js.
  3. Sign in on iOS and Android. Background the app for 5 minutes, then foreground it. Confirm new messages arrive.
  4. Toggle airplane mode on and off on both platforms. Confirm the socket returns.
  5. Confirm the log shows [Pusher PINGPONG] The server has not sent a PONG in ... leaving recovery to the Pusher SDK in place of the old presumed dead and Pusher is being reconnected.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline. Confirm the log shows [Pusher PINGPONG] Skipping PING because the client is offline. Confirm no PONG staleness line appears.
  2. Come back online. Confirm the PING resumes and PONGs arrive.

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

This PR changes src/libs/actions/User.ts and a unit test file. It has no UI change. There is nothing to capture in the sections below.

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

The watchdog compared wall-clock time against a 60 second threshold while the
real PING cadence in production is also about 60 seconds, because browsers
throttle setInterval in background tabs. The threshold equalled the cadence of
the signal it watched, so it fired on timer jitter: 516 users produced 31,518
"presumed dead" fires per 4 hours while receiving about 118 PONGs each.

The probe cannot answer the question either way. The PING goes out over HTTP and
the PONG comes back over the websocket, so a missing PONG does not say which of
the two failed, and the request has no retry on a failed fetch.

Every Pusher SDK already detects a dead socket with a websocket ping frame
answered on the connection under test, and reconnects itself: pusher-js 8.3.0
(120s/30s), PusherSwift 10.1.6 (server activity_timeout/30s), pusher-java-client
2.4.4 (120s/30s). The only cost of deferring to them is reaction time.

The log line stays, restated, so the old string falling to zero is the proof and
the new string sizes whatever the SDKs do not cover.

Pusher.reconnect() itself stays: PusherConnectionManager and Session both still
call it.

The staleness check now rides the existing 30 second PING interval instead of a
second timer with its own delayed start, which also removes the delay that read
60 milliseconds where it meant 60 seconds.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@adhorodyski

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 96108dbd3c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@adhorodyski

Copy link
Copy Markdown
Contributor Author

@codex review

@adhorodyski

Copy link
Copy Markdown
Contributor Author

@MelvinBot please review this PR

@adhorodyski
adhorodyski marked this pull request as ready for review August 19, 2026 14:31
@adhorodyski
adhorodyski requested review from a team as code owners August 19, 2026 14:31
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and heyjennahay and removed request for a team August 19, 2026 14:31
@melvin-bot

melvin-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

@ZhenjaHorbach Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team August 19, 2026 14:31
@MelvinBot

Copy link
Copy Markdown
Contributor

PR Review — looks good ✅

The change is sound and does exactly what the issue describes: the watchdog stops discarding live sockets. Pusher.reconnect() and the standalone checkForLatePongReplies interval are removed, and the staleness check is folded into pingPusher() as a log-only line (User.ts:846-849).

The core premise checks out. Recovery is delegated to pusher-js, and our Pusher init only sets cluster/authEndpoint (Pusher/index.ts:86-95) — so the SDK's default heartbeat applies (activityTimeout 120s + pongTimeout 30s). That both confirms the "recovery moves to the SDK" claim and explains the "allow up to 150 s" recovery window in the test steps.

Verification details
  • No dangling references. checkForLatePongReplies, SOCKET_PRESUMED_DEAD_THRESHOLD_IN_SECONDS, shouldSkipCheckAfterReconnect, CHECK_LATE_PONG_INTERVAL_LENGTH_IN_SECONDS, and the presumed dead/presumed alive log lines are fully gone — no leftover callers.
  • Pusher.reconnect export is still valid — it remains used by PusherConnectionManager.ts:40 and Session/index.ts:1141, so removing the watchdog caller doesn't orphan it.
  • Good addition: resetting lastPongReceivedTimestamp = Date.now() on init (User.ts:862) avoids a spurious staleness log right after re-initialization, since the module-level timestamp is stamped at import time.
  • Log volume matches the prediction: there is no longer any "presumed alive" line (it only logs on staleness now), consistent with the "→ 0 presumed alive lines" target.
  • CI is green — the Pusher jest suite and all test (job 1-8) pass. The only red check is Check independent approval, which is process, not code.

Minor / non-blocking observations:

  • The staleness check now runs only when a PING is actually sent, and it sits after the HMR-dedup early return (User.ts:833-835). In production the 30 s interval makes that guard a no-op, so it's harmless — just noting the log is now coupled to ping cadence rather than an independent timer.
  • Since recovery is now purely SDK-driven, it's worth keeping the new leaving recovery to the Pusher SDK log line as a monitoring signal to confirm the SDK reconnects promptly and GetMissingOnyxMessages did not advance stays flat (the control metric in the issue).

Web smoke test (no UI change, so just a regression check): signed in, reached Home, opened a chat — report list and messages render, and AuthenticatePusher + the report loads all returned 200 with no network errors. (Browser console capture isn't available via the web tooling, so [Pusher PINGPONG] lines couldn't be read directly; network-layer evidence showed no Pusher breakage.)

@ZhenjaHorbach

ZhenjaHorbach commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
2026-08-19.17.13.01.mov
Android: mWeb Chrome
2026-08-19.17.13.01.mov
iOS: HybridApp
2026-08-19.17.08.21.mov
iOS: mWeb Safari
2026-08-19.17.06.37.mov
MacOS: Chrome / Safari
2026-08-19.17.03.49.mov

@ZhenjaHorbach

Copy link
Copy Markdown
Contributor

Changes look good!

@melvin-bot
melvin-bot Bot requested a review from mountiny August 19, 2026 15:17

@mountiny mountiny 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.

Thanks, seems like this will bring nice drop

@mountiny
mountiny merged commit 025f7d9 into Expensify:main Aug 19, 2026
42 of 54 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

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.

5 participants