Repository navigation
Conversation
…vers An OpenApp or full-ReconnectApp response can itself deliver a newer "reconnect if older than X" cutoff than the one known when the request was built. The reconnect time waiting in the request's successData was computed from that older cutoff, so on a device whose clock runs behind the server the app saved a time below the delivered cutoff, read itself as stale right after downloading everything, and fired two extra full reconnects (one when the new cutoff was saved next to the old time, one more when the stale successData lowered the time below the cutoff again). A new middleware recomputes the time from the cutoff the response actually carries before the response is applied: it seeds the value into the response's onyxData right before the cutoff entry (so the two are saved together and the reconnect subscription never sees a new cutoff next to an old time) and raises the successData entry in place (never lowering it) so the later successData write cannot undo the seed.
…rals The Onyx update entries type their value as any, so reading the cutoff and recorded time now narrows through typeof checks on an unknown binding instead of asserting. The middleware test request/response builders drop their double assertions entirely; every field they set is part of the declared type. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
@codex review |
|
I made it [No QA] as I believe it's not possible to repro this by a QA. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
@MelvinBot review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
🤖 Review of the Verdict: The root cause is correctly diagnosed and the frontend-only approach is reasonable. The steady-state is sound — the recorded time always ends up 1. The "splice before the cutoff" safeguard relies on undocumented Onyx callback ordering (main concern)The fix has two independent safeguards:
The first safeguard guarantees eventual consistency (no repeating loop). But it does not prevent a single transient reconnect: Preventing that transient trigger is entirely the job of the second safeguard — array ordering. The problem: This is fine in practice today, but it's load-bearing behavior resting on an incidental property of the Onyx internals. Suggestions, in order of preference: (a) at minimum, add a comment in 2. The end-to-end regression test doesn't reproduce the real WRITE batchingFor WRITE requests (OpenApp and full ReconnectApp), the real pipeline concatenates Two separate awaited updates give the recorded-time write its own settled broadcast before the cutoff/successData ever land together — which is exactly the concurrency race from point 1 that the single combined update is subject to but this test isn't. So the test can pass while being more forgiving than production. (This mirrors the pre-existing 3. Minor
Nice, tightly-scoped fix with good test coverage of the helper itself — the two points above are about hardening the guarantee, not correctness of the happy path. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression where an OpenApp/ReconnectApp response can deliver a newer “full reconnect cutoff” than was known at request build time, causing the app to record a stale LAST_FULL_RECONNECT_TIME and trigger redundant full reconnects (extra multi‑MB downloads). The solution adds a small middleware that rewrites the reconnect time based on the cutoff actually delivered in the response, ensuring Onyx never briefly observes a new cutoff alongside an old recorded time.
Changes:
- Added
recordFullReconnectTimeFromResponse()to recompute and seedLAST_FULL_RECONNECT_TIMEinto bothresponse.onyxData(before the cutoff update) and the requestsuccessData. - Introduced
RecordFullReconnectTimemiddleware and registered it beforeSaveResponseInOnyx. - Added unit tests covering the helper, middleware gating, and an end-to-end regression scenario (newer cutoff delivered by OpenApp response).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/SubscribeToFullReconnectTest.ts | Adds an end-to-end regression test ensuring no extra reconnect occurs when OpenApp response delivers a newer cutoff. |
| tests/unit/RecordFullReconnectTimeMiddlewareTest.ts | New unit tests for middleware behavior (eligible commands, success-only, passthrough). |
| tests/unit/FullReconnectUtilsTest.ts | Adds coverage for recordFullReconnectTimeFromResponse() including “never lower” behavior. |
| src/libs/Middleware/RecordFullReconnectTime.ts | New middleware that adjusts reconnect time using the response-delivered cutoff before Onyx updates apply. |
| src/libs/Middleware/index.ts | Exports the new middleware. |
| src/libs/FullReconnectUtils.ts | Implements recordFullReconnectTimeFromResponse() to seed consistent reconnect time updates. |
| src/libs/API/index.ts | Registers RecordFullReconnectTime middleware before SaveResponseInOnyx. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e apply path Review follow-up: document that the splice-before-cutoff ordering rests on Onyx broadcasting a batch's merges in array order (with the bounded worst case if that flips), correct the stale "LAST middleware" comment that FraudMonitoring already contradicts, and add a regression test that applies the newer-cutoff OpenApp response the way WRITE requests actually land in production — one combined Onyx.update via QueuedOnyxUpdates. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Addressed the review feedback in 035ff77: 1. Ordering assumption (main concern) — documented on 2. Test doesn't exercise the batched path — agreed, with one refinement: both apply shapes are real production paths ( 3a. Type casts — keeping them: the casts only erase the generic key parameter, and the 3b. Empty delivered cutoff — intended: a 200 OpenApp/full-ReconnectApp response means a full download just happened, so recording |
|
@bernhardoj 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] |
|
If I understand correctly, the issue happens because we compute the last reconnect time before making the requests. We did it twice. Lines 555 to 557 in 5ee0283 Even though we set it to Lines 396 to 403 in 5ee0283 So, we compute it in the middleware after the response is finished. Is it possible to remove both I was thinking maybe we can update function recordFullReconnectTimeFromResponse(responseOnyxData: AnyOnyxUpdate[]): void {
const cutoff = responseOnyxData.find((update) => update.key === ONYXKEYS.NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE)?.value;
const deliveredCutoff = typeof cutoff === 'string' ? cutoff : '';
// if server response doesn't have NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE, then we will use the current time
const timeForDeliveredCutoff = getLastFullReconnectTimeToRecord(deliveredCutoff);
// since we don't have the success data anymore, we can simply push this
responseOnyxData.push({onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.LAST_FULL_RECONNECT_TIME, value: timeForDeliveredCutoff});
}and adjust the |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This PR adds a new |
|
@bernhardoj I took your shape: the successData entry is gone from Two additions were needed to make it hold everywhere: 1. The recorded time is clamped to the cutoff the client already holds, not just the delivered one: 2. The full-vs-partial rule is shared with the queue. The middleware gates on As we deploy this, a request persisted before this version replays with the old build-time value in its successData and can cost one extra reconnect, it self heals though and continues working ok. |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safariw.mp4 |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.41-0 🚀
|
|
🤖 I reviewed this PR against the help site content under Why: This is a purely internal networking/sync fix. It changes when the app records its "last full reconnect time" — moving that write from request-build time into a new The PR is labeled Since no changes are needed, I did not create a draft help site PR. @adhorodyski, please confirm you agree that no help site updates are required for this change. If you believe an article should be updated, let me know which behavior it should reflect and I'll create the draft PR. |
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.4.41-4 🚀
Bundle Size Analysis (Sentry): |
| * The entry goes right before the delivered cutoff entry, so the reconnect subscription never sees | ||
| * a new cutoff next to an old reconnect time. That assumes Onyx broadcasts a batch's merges in | ||
| * array order: true today because both keys are cache-resident (see subscribeToFullReconnect.ts), | ||
| * and pinned by the SubscribeToFullReconnect e2e test. If it ever broke, the worst case is one | ||
| * transient extra reconnect, never a loop. |
Explanation of Change
The server can ask for a full re-download by sending a cutoff time: "if your last full download happened before X, download everything again." The app records when its last full download happened and compares it against that cutoff.
The problem: the recorded time was computed when the request was built. The response to that same request can deliver a newer cutoff, and on a device clock behind the server the recorded time lands below it. The app then reads itself as stale right after downloading everything and fires extra full reconnects, re-downloading up to several MB.
The fix: a
RecordFullReconnectTimemiddleware records the time from the response instead. On every successful OpenApp/full-ReconnectApp response it writesLAST_FULL_RECONNECT_TIME = max(now, delivered cutoff, held cutoff)into the response's onyxData, placed right before the cutoff entry so the two values are saved together and the app never sees a new cutoff next to an old recorded time. The build-time successData write inApp.tsis deleted. Full vs partial ReconnectApp is decided byisFullDownloadRequest, the same rule the queue's reconnect dedup uses.Fixed Issues
$ #95591
PROPOSAL:
Tests
npx jest tests/unit/FullReconnectUtilsTest.ts tests/unit/RecordFullReconnectTimeMiddlewareTest.ts tests/unit/SubscribeToFullReconnectTest.ts.Offline tests
N/A — the behavior is only reachable with a device clock behind the server during a sign-in/clear whose OpenApp response delivers a newer reconnect cutoff; covered by unit tests, no user-visible change otherwise.
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)Avatar, 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