Skip to content

[No QA] [Performance] Add write-readiness barrier primitives and pending-write modules - #98979

Merged
Julesssss merged 12 commits into
Expensify:mainfrom
software-mansion-labs:korytko/writewhenready-api-core
Aug 26, 2026
Merged

Julesssss merged 12 commits into
Expensify:mainfrom
software-mansion-labs:korytko/writewhenready-api-core

Conversation

@JakubKorytko

@JakubKorytko JakubKorytko commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Explanation of Change

Extends the existing API.writeWhenReady primitive (already on main, currently with no call sites) with the pieces the submit-expense cutover needs:

  • API.armTransitionBarrier(waitFor?) - attaches a transition barrier before the write exists, returning {barrier, cancel}. The default barrier only takes its fast path when TransitionTracker already knows a transition is active or imminent at the moment the barrier is attached. A caller that navigates first and issues the write from the navigation's own completion callback would attach after that transition ended, so it would wait on an unrelated future transition and fall through to the safety timeout. Arming splits those two moments: register when the navigation is triggered, hand the barrier to writeWhenReady when the write is actually built. One armed barrier can gate several writes from a single interaction (e.g. one per receipt in a split) so they release together rather than racing separate barriers. cancel() covers the abandoned path.
  • WriteWhenReadyOptions with onRelease(reason) and onWriteStarted() lifecycle hooks. The fifth parameter widens from a bare safetyTimeoutMs: number to number | WriteWhenReadyOptions, and the numeric form is still accepted, so nothing existing has to change.
  • writeWhenReady re-declared as a thin wrapper in src/libs/API/index.ts instead of being re-exported. A re-exported binding is a non-configurable getter, so jest.spyOn(API, 'writeWhenReady') cannot replace it; tests need to observe this once submit writes go out through it rather than through write.

Also lands the leaf modules the cutover wires up, none of them referenced by product code yet:

  • src/libs/pendingSearchWrite.ts - Search's own write-readiness barrier plus a "a Search write is pending" signal (markPendingSearchWrite, hasPendingSearchWrite, acquireSearchWriteBarrier, flushPendingSearchWrite, set/getSearchWriteWatchKey). Generation-counted, so a stale release cannot clear a newer pending write.
  • src/libs/pendingSubmitWrite.ts - the per-report equivalent (markPendingSubmitWriteForReport, which returns its own clear callback, and hasPendingSubmitWriteForReport), for the loading-skeleton and empty-state-animation checks.
  • src/libs/actions/IOU/resolveWriteBarrier.ts - decides what a submit write waits on: an explicit writeBarrier if the caller threaded one down, else Search's barrier when a Search write is pending and this is not a retry, else IMMEDIATE. Retries deliberately skip Search, because the layout that would have released them already happened and the write would otherwise sit until its safety timeout. Returns a barrier rather than performing the write, so timing stays visible at the call site instead of in a shared registry.
  • src/libs/Navigation/helpers/markPendingSearchWriteIfGlobalCreate.ts - raises the Search signal when a submission started from global create rather than from inside a report.

Purely additive: no existing call site is changed, and nothing in product code imports any of this yet. The consumers land in the follow-up cutover PR, which is then purely rewiring.

Fixed Issues

$ #96010
PROPOSAL: N/A

Tests

N/A

Offline tests

N/A - no call sites yet, so no network/Onyx behavior is reachable through the UI.

QA Steps

No QA - purely additive API surface, unused until the follow-up PR wires a consumer to it.

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

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

@codecov

codecov Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/API/index.ts 91.80% <100.00%> (+0.27%) ⬆️
src/libs/API/writeWhenReady.ts 98.63% <100.00%> (+1.96%) ⬆️
...avigation/helpers/markPendingWriteForSearchPage.ts 100.00% <100.00%> (ø)
src/libs/actions/IOU/resolveWriteBarrier.ts 96.55% <96.55%> (ø)
src/libs/pendingSubmitWrite.ts 97.14% <97.14%> (ø)
src/libs/pendingSearchWrite.ts 94.02% <94.02%> (ø)
... and 310 files with indirect coverage changes

@JakubKorytko

Copy link
Copy Markdown
Member Author

@MelvinBot review this PR

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1385758e4e

ℹ️ 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".

Comment thread src/libs/pendingSearchWrite.ts Resolved
Comment thread src/libs/API/writeWhenReady.ts Resolved
@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Review: LGTM. This is a clean, purely-additive primitives PR — no existing call site changes and nothing in product code imports it yet, so the blast radius is limited to whatever the follow-up cutover wires up. The back-compat handling (numeric fifth param still accepted), the error isolation around onRelease/onWriteStarted, and the generation-counted stale-clear guards in both pending-write modules are all correct, and the test coverage is thorough across every release path. All substantive checks are green (test, typecheck, ESLint, perf); the only red check is Check independent approval, which is just the reviewer gate.

One edge case worth a note, plus a couple of minor observations below.

Edge case — armTransitionBarrier consumer counting assumes all writes attach before any release early

In armTransitionBarrier, armController.abort() fires once abortedConsumerCount >= consumerCount. This is correct for the intended use — a split that builds all its writes synchronously, so consumerCount reaches its final value before any write can hit its safety timeout.

It breaks down only if writes are attached to one armed barrier at different times and an earlier one releases early:

  1. Write A attaches → consumerCount = 1.
  2. Write A hits its safety timeout before the transition completes → abortedConsumerCount = 1, 1 < 1 is false → armController.abort(). armed is now permanently pending.
  3. Write B attaches later → gets the already-aborted armed, so it waits out its own safety timeout (~2s) even if the transition completes moments later — the exact slow path this feature exists to avoid.

Since there are no call sites yet, this isn't reachable today, and the split case is safe. But the "one armed barrier can gate several writes" contract in the doc comment doesn't state that all consumers must attach before any of them can release. Worth either documenting that assumption or handling late attachment, so a future consumer doesn't get silently pushed onto the safety-timeout path.

Minor observations (non-blocking)
  • pendingSearchWrite safety-timeout path doesn't release waiters. When Search never flushes, clearPending clears pending without calling release(), so any write waiting on pending.barrier (() => released) never resolves through this module. It's not stranded — writeWhenReady's own SAFETY_TIMEOUT_MS forces the write out — but the write takes the full safety-timeout path instead of a clean release. That's acceptable degradation for a pathological "Search never laid out" case; just flagging that the two timeouts don't cooperate here.
  • onRelease('success') semantics. onRelease fires with 'success' before write(), and write() can still throw synchronously right after (the does not call onWriteStarted when write() throws synchronously test covers this). The reason reflects the barrier releasing, not the write succeeding — which matches the doc comment, but a consumer treating 'success' as "the write happened" would be wrong. The naming is a slight trap; the current doc is adequate.

Nice work on the documentation density and the test suite — the "why" comments on the module-level state and the barrier-lifecycle edge cases make this much easier to reason about.


view run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1385758e4e

ℹ️ 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".

Comment thread src/libs/pendingSubmitWrite.ts Resolved
@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1385758e4e

ℹ️ 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".

@JakubKorytko
JakubKorytko force-pushed the korytko/writewhenready-api-core branch from 1385758 to ba0d3aa Compare August 20, 2026 10:46
@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 730678d054

ℹ️ 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".

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 730678d054

ℹ️ 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".

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 730678d054

ℹ️ 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".

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca251cb14b

ℹ️ 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".

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca251cb14b

ℹ️ 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".

@JakubKorytko

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 691d7ea56c

ℹ️ 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".

@brunovjk

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
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@melvin-bot
melvin-bot Bot requested review from Julesssss and roryabraham August 20, 2026 14:58
Comment thread src/libs/API/writeWhenReady.ts Resolved
Comment thread src/libs/pendingSearchWrite.ts Outdated
import {SAFETY_TIMEOUT_MS} from './API/writeWhenReady';

/**
* Search's own write-readiness signal.

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.

Just to confirm, we'll replace the existing deferredLayoutWrite in the follow up PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, that's the plan for the follow up PR - you can see the prototype here: software-mansion-labs#368

Comment on lines +88 to +90
if (pending) {
return;
}

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.

Should the return happen AFTER watchKey = undefined;?

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.

Any maybe more of the logic here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah no, order's right - early return has to come before the reset, or a second write from the same expense split would wipe the watch key the first one set

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.

Cool, thanks for checking

Comment thread src/libs/pendingSearchWrite.ts Resolved
Comment thread src/libs/API/writeWhenReady.ts Outdated
): Promise<void | Response<TKey>> {
Log.info('[API] Called API writeWhenReady', false, buildLogParams(command, apiCommandParameters ?? {}));

// Back-compat: the fifth parameter used to be a bare safetyTimeoutMs number.

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.

Lets not comment about prior functionality.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed

Comment thread src/libs/pendingSubmitWrite.ts Outdated
Comment on lines +9 to +12
* Those two live in unrelated module/component trees with no props path between them, so the signal
* needs somewhere to live. It is deliberately not the write-scheduling registry it replaces: this only
* answers a question, it never decides where a write goes, so stale state here cannot send a
* submission down the wrong path the way a stale channel reservation could.

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.

It is deliberately not the write-scheduling registry it replaces

Lets remove notes about prior implementation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed

Comment thread tests/unit/APIWriteWhenReadyTest.ts Outdated
Comment on lines +724 to +725
// Given a write queued with a bare number as the fifth parameter, the old signature
// before it widened to accept a WriteWhenReadyOptions object

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.

the old signature before it widened

Not relevant

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed

Comment thread src/libs/API/index.ts Outdated
Comment on lines +59 to +61
* Re-declared here for the same reason as `write` above: a re-exported binding is a non-configurable getter,
* so `jest.spyOn(API, 'writeWhenReady')` cannot replace it. Tests need to observe this one now that submit
* writes go out through it rather than through `write`.

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.

now that submit writes go out through it rather than through write.

Not relevant

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed

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

Looking good, it would be good to do a pass on the comments to remove refs to prior functionality, also added some comments about potential issues

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

Please try to audit your comments by hand before submitting for review next time. I felt overwhelmed by AI comment slop during this review.

Comment thread src/libs/API/writeWhenReady.ts Resolved
Comment thread src/libs/API/writeWhenReady.ts Outdated
/**
* Attach a transition barrier now, use it later.
*
* The default barrier only takes its fast path when `TransitionTracker` already knows a transition is

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.

I'm not sure I have a better suggestion, but something feels off here. If the default behavior is "perform the write after the transition", why would a caller need to issue the write from a navigation's completion callback? Why can't it just use the default barrier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

docstring above armTransitionBarrier answers this now - let me know if it's still not clear:

/**
 * Use when a caller navigates first and only builds the write afterward, once the navigation has
 * already finished: attaching the default barrier that late would miss the transition and fall
 * through to the safety timeout. Arm this instead when navigation triggers, then pass the resulting
 * barrier to `writeWhenReady` once the write is built; one armed barrier can gate several writes from
 * the same interaction (e.g. one per receipt in a split), releasing them together.
 */

*/
function armTransitionBarrier(waitFor: true | 'navigation' = true): ArmedTransitionBarrier {
const armController = new AbortController();
const armed = createTransitionBarrier(waitFor)(armController.signal);

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.

Suggested change
const armed = createTransitionBarrier(waitFor)(armController.signal);
const isArmed = createTransitionBarrier(waitFor)(armController.signal);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

armed holds a Promise, not a bool, so isArmed felt like the wrong name. Kept armed, open to armedPromise if you still think it's better

Comment thread src/libs/API/writeWhenReady.ts Resolved
Comment thread src/libs/pendingSearchWrite.ts Resolved
Comment thread src/libs/pendingSearchWrite.ts Resolved
Comment thread src/libs/pendingSearchWrite.ts Resolved
Comment thread src/libs/pendingSubmitWrite.ts Resolved
Comment thread src/libs/pendingSubmitWrite.ts Resolved
@JakubKorytko

Copy link
Copy Markdown
Member Author

I felt overwhelmed by AI comment slop during this review.

yeah, valid, as I said on Slack - sorry for that. Should be good now (I corrected & verified all the comments and they make sense to me), if something is still unclear lmk

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

LGTM now 👍🏼

@Julesssss Julesssss 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 for addressing the reviews

@Julesssss
Julesssss merged commit 2044d29 into Expensify:main Aug 26, 2026
37 of 38 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

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

@OSBotify OSBotify mentioned this pull request Aug 26, 2026
57 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/Julesssss in version: 9.4.62-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes required — no docs PR created.

This PR adds internal write-readiness barrier primitives and pending-write modules (API.armTransitionBarrier, WriteWhenReadyOptions, pendingSearchWrite, pendingSubmitWrite, resolveWriteBarrier, markPendingWriteForSearchPage) plus their unit tests. It is engineering infrastructure only.

Per the PR description, it is purely additive — no existing call site is changed, nothing in product code imports any of it yet, and QA is explicitly N/A because the API surface is unused until the follow-up cutover PR wires a consumer to it.

Since there is no user-facing change — no UI, feature, tab, setting, button, or workflow — nothing in App/docs/articles documents this behavior, so no help site edits are needed. If the follow-up cutover PR introduces a user-observable change (e.g. a difference in loading/skeleton behavior on submit), that would be the point to re-evaluate the help site.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 9.4.62-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

6 participants