move PusherPing off the durable write queue - #97702
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f89d16e97b
ℹ️ 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".
| // The heartbeat is a probe, not a user's write, so it must not be persisted to disk, retried, or hold the | ||
| // head of the queue while a real write waits behind it. The Logging middleware already logs any failure. | ||
| // eslint-disable-next-line rulesdir/no-api-side-effects-method | ||
| API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.PUSHER_PING, parameters).catch(() => {}); |
There was a problem hiding this comment.
Avoid overlapping stalled Pusher pings
When a PusherPing request remains pending for more than one 30-second tick (for example, a hanging server/connection while NetworkState has not switched offline), this now starts another side-effect request on every interval because it no longer goes through the sequential queue or duplicate resolver. The old write path allowed at most one in-flight ping plus one deduped queued ping, but this path can accumulate overlapping heartbeat fetches and recreate the load this change is trying to remove; keep a local in-flight guard or abort/skip until the previous probe settles.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Overlap needs the ping to hang past 30s. When the server hangs, NetInfo's api/Ping probe on the same host times out after 10s and takes the app offline within ~70s, and pingPusher early-returns while offline. So at most two or three hung fetches, but there are no retries, no backoff, no persistence, no queue head held.
This PR rather takes down thousands of wasted requests.
The no-multiple-api-calls rule counts `API` tokens per function body, so the third assertion pushed the describe block over the limit. One module-scope mockAPI handle keeps the count at zero inside functions. Drop the pingID shape assertion too: pingPusher builds a typed PusherPingParams, so tsc already guarantees it is a string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reviewer Checklist
Screenshots/VideosMacOS: Chrome / SafariScreen.Recording.2026-08-04.at.01.01.03.mov |
| it('sends the PING off the durable write queue', () => { | ||
| expect(mockAPI.makeRequestWithSideEffects).toHaveBeenCalledWith(SIDE_EFFECT_REQUEST_COMMANDS.PUSHER_PING, expect.anything()); | ||
| expect(mockAPI.writeWithNoDuplicatesConflictAction).not.toHaveBeenCalled(); | ||
| }); |
There was a problem hiding this comment.
This test looks fragile. This test advances no timers and relies on beforeAll state plus the pings fired by the two earlier watchdog tests. pingPusher only runs via setInterval (30s), so the assertion passes purely because tests # 1 / # 2 already advanced and the mock is never cleared between tests. Reordering the tests, running this one in isolation (.only), or adding a beforeEach(clearAllMocks) later would all break it.
|
PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself. |
Explanation of Change
PusherPingis a 30 second heartbeat that checks the Pusher event path. The client posts a ping over HTTP and the server answers with aPONGover the websocket.It was sent with
API.write, so it was written to disk every 30 seconds, retried up to 10 times with doubling backoff, and could hold the head of the single-flight queue while a real write waited behind it. In a 4 hour window it was the most retried command in the app: 5,075 attempts across 2,924 users, against 1,135 for the next command.This moves
PUSHER_PINGtoSIDE_EFFECT_REQUEST_COMMANDSand sends it withAPI.makeRequestWithSideEffects. That path is not persisted, not retried, and does not touch the queue.API.readwaits for the write queue to drain first, which is the coupling being removed.The probe stays.
checkForLatePongRepliescallsPusher.reconnect()when aPONGgoes missing, which shipped in #96883.Fixed Issues
$ #97712
PROPOSAL:
Tests
tests/unit/PusherPingPongTest.ts: the existing watchdog tests needed a mock fix, because the automocked@libs/APIreturnsundefinedandpingPushernow chains a.catchon the returned promise. Added one assertion that the ping goes out throughmakeRequestWithSideEffectswithPusherPingand that the old write path is not called. Verified it fails against the old call and passes against the new one.Also ran
tests/unit/APITest.ts,tests/unit/SequentialQueueTest.ts,tests/unit/NetworkTest.tsxandtests/unit/RequestTest.ts. All pass.Manual check for a reviewer: sign in, wait a minute, and confirm the
[Pusher PINGPONG] Received a PONG event from the serverlog still arrives and thatPusherPingno longer appears inPERSISTED_REQUESTS.Offline tests
N/A
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari