Repository navigation
Conversation
Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
The only failing check is PR Author Checklist / checklist — every other check (typecheck, all That check isn't a code failure. It fails because the PR description still has its checklist boxes unchecked and the
These are human-only sections that I can't fill out on your behalf. To make this check pass, There's nothing for me to fix in code, so I haven't pushed any changes. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70efad1d66
ℹ️ 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".
| : createAgent(firstName, prompt, selectedPresetID ?? undefined, undefined, undefined, policyID); | ||
|
|
||
| Navigation.goBack(); | ||
| chatWithAgent(optimisticAccountID); |
There was a problem hiding this comment.
Dismiss the add-agent modal before opening the DM
When this page is opened from Settings it is on the RHP/modal stack, but chatWithAgent goes through navigateToAndOpenReportWithAccountIDs, which calls navigateToReport with shouldDismissModal: false. Since this change removed the previous Navigation.goBack(), submitting from the add-agent modal leaves that modal on top while the report navigation happens behind it, so the new DM is not actually shown to the user in that flow. Dismiss/pop the modal before navigating, or use a report navigation path that dismisses the modal.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — fixed in c83ef99.
navigateToAndOpenReportWithAccountIDs hardcoded shouldDismissModal: false, so submitting from the add-agent RHP left the modal on top and the new DM was never shown. I threaded an optional shouldDismissModal param through the navigation path (defaulting to false, so all existing callers — HelpPage, PromotedActionsBar, WorkspaceWorkflowsPayerPage, and the other agent pages — are unchanged) and AddAgentPage now passes true:
Report/index.ts— newshouldDismissModal = falseparam, forwarded to all threenavigateToReportcalls.useChatWithAgent.ts—chatWithAgent(accountID, {shouldDismissModal})forwards the flag.AddAgentPage.tsx— passes{shouldDismissModal: true}, going throughnavigateToReport's existing dismiss-then-navigate timing (rather than a rawdismissModal()+ navigate).
Also updated the AddAgentPage unit tests to assert the new argument.
Checks run locally: AddAgentPageTest (10 ✓) and ReportTest (250 ✓) pass, typecheck-tsgo clean, ESLint clean on all changed files, oxfmt applied. react-compiler-compliance-check check-changed couldn't run in this environment (no origin/main merge base), but the change is a trivial arg addition inside an existing callback with no new hooks/components.
|
Still nothing for me to fix in code. All functional checks pass. The two remaining failures are both human-only checklist checks:
I can't complete either of these on your behalf (they require a human to fill out the sections and tick the boxes), and no code change would make them pass. See my earlier comment for details. |
|
The two currently failing checks are both human-only checklist checks — not code failures, and nothing I can fix by pushing:
Every functional check (typecheck, all |
Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
🚧 mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
@MelvinBot this still doesn't automatically open the DM with newly created agent. Diagnose why - agent ID is 22542959 |
Diagnosis: the DM opens against a fake accountID, not the real agentRoot cause: Walking the flow:
The Agents-list rows work precisely because they use the real ID — So the PR's premise — " Fix optionsOption A — App-only, but gives up optimistic navigation. Get the agent's real accountID before navigating, by awaiting the Option B — keep it fully offline-first, needs backend support. Report IDs are reconcilable, so build the optimistic DM report client-side, pass its Why not just keep passing the optimistic ID?There's no client→server mapping for account IDs the way there is for report IDs ( Next Steps: Reply with |
|
@MelvinBot implement option A |
Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
Implemented Option A — pushed What changed: the DM now opens with the agent's real, server-assigned accountID instead of the client-side optimistic one (which was never the agent's real identity, so the DM never resolved).
Why not just await the write? Behavior tradeoff to be aware of:
Local checks run
I couldn't runtime-verify the live server round-trip here, so please confirm on the adhoc build that the DM opens after creating an agent. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
Re-checked — the situation is unchanged from my previous comment. Every functional check (typecheck, all The only failing check is PR Author Checklist / checklist, and it's not a code failure — it fails because the PR description's checklist boxes are unchecked and the To make it pass, |
|
🚧 mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
it works now @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15834192bc
ℹ️ 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".
| return; | ||
| } | ||
|
|
||
| const createdAgentAccountID = currentAgentAccountIDs.find((accountID) => accountID !== optimisticAccountID && !knownAgentAccountIDs?.has(accountID)); |
There was a problem hiding this comment.
Filter out other optimistic agent placeholders
When a user submits a second agent before the first CREATE_AGENT response arrives (e.g. offline or on a slow connection after this flow returns to the Agents list), this find treats the second agent's optimistic sharedNVP_agentPrompt_* key as the newly created real account because it only excludes this request's optimistic ID. That resolves the first promise with the other placeholder/wrong accountID, so AddAgentPage can open a DM for an account ID the server will never use instead of waiting for the matching real agent.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — fixed in 0e020c2.
waitForCreatedAgentAccountID only excluded this request's optimistic ID and the baseline agents, so a second agent's optimistic sharedNVP_agentPrompt_* key (created before the first CREATE_AGENT responded) was new + not our optimistic ID → the find matched it and resolved with a placeholder accountID the server will never use.
The fix now skips any agent still pending creation, not just ours — a real, server-created agent is the only one that appears with no ADD pending action, and that's the accountID we resolve with:
// Skip any *other* agent still pending creation — e.g. a second agent the user created before this
// one's CREATE_AGENT responded (its optimistic accountID is also new and not our optimistic ID).
// Only a real, server-created agent has no ADD pending action, and that's the accountID we can open a DM with.
return agentPrompt?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;See Agent.ts:132-142.
Added a regression test in AgentActionTest.ts that creates an agent, then merges a second optimistic (ADD) placeholder and asserts the promise stays unresolved, and only resolves once a real agent (no ADD) appears.
Local checks
AgentActionTest— 55 ✓ (incl. the new case)AddAgentPageTest— 10 ✓typecheck-tsgo— cleanlint-changed— cleanoxfmt— applied
|
🤖 No code fix needed — the only failing check requires human action. The single failing check is PR Author Checklist, which fails with:
Every other check (tests, typecheck, ESLint, Oxfmt, build, perf, etc.) is passing. This one isn't a code/test failure — it can't be resolved by pushing a commit. It fails because the PR body still has:
To resolve: |
…ptimistic placeholder Co-authored-by: Michał Jasikowski <mjasikowski@users.noreply.github.com>
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
1 similar comment
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
|
🚧 mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
My bad, this shouldn't be in review yet |
| function waitForCreatedAgentAccountID(optimisticAccountID: number): Promise<number> { | ||
| return new Promise((resolve) => { | ||
| let knownAgentAccountIDs: Set<number> | undefined; | ||
| const connection = Onyx.connectWithoutView({ |
There was a problem hiding this comment.
❌ PERF-12 (docs)
This Onyx.connectWithoutView subscription is only ever disconnected on the success path (the Onyx.disconnect(connection) inside the createdAgentEntry branch). If CREATE_AGENT fails, the failureData restores the optimistic row with pendingAction: ADD and no real, server-created agent ever appears, so the .find(...) never matches, resolve is never called, and Onyx.disconnect(connection) is never reached. The subscription (and the pending Promise it lives in) then leaks for the lifetime of the app — and this repeats on every failed creation.
Add a cleanup path so the connection is always torn down. For example, subscribe to the request/failure state (or add a timeout) and disconnect there too:
function waitForCreatedAgentAccountID(optimisticAccountID: number): Promise<number> {
return new Promise((resolve, reject) => {
let knownAgentAccountIDs: Set<number> | undefined;
const connection = Onyx.connectWithoutView({
key: ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT,
waitForCollectionCallback: true,
callback: (agentPrompts) => {
// ...existing logic...
Onyx.disconnect(connection);
resolve(realAccountID);
},
});
// Ensure the subscription is always cleaned up (e.g. on CREATE_AGENT failure / timeout)
// so it never leaks when the real agent never arrives.
// e.g. watch failureData/pendingAction restore, or a bounded timeout, then:
// Onyx.disconnect(connection); reject(...);
});
}Reviewed at: 066f090 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| * that already existed. Callers use it to open the DM with the newly created agent once it's real. | ||
| */ | ||
| function waitForCreatedAgentAccountID(optimisticAccountID: number): Promise<number> { | ||
| return new Promise((resolve) => { |
There was a problem hiding this comment.
❌ CONSISTENCY-6 (docs)
The Promise returned by waitForCreatedAgentAccountID has no failure path: it only ever resolves when a real agent appears. When CREATE_AGENT fails, the optimistic row is restored with pendingAction: ADD, no real agent shows up, and the Promise hangs forever with no error surfaced. The caller in AddAgentPage.tsx (createdAgentAccountID.then(...)) is left with a permanently-pending .then and no way to react to the failure — a silent failure of a data-mutation flow.
Handle the failure case explicitly — reject (or resolve to a sentinel) when CREATE_AGENT fails, and have the caller handle it (e.g. .catch(() => { Log.warn('agent creation failed; skipping auto-open DM'); })). This makes the failure observable and prevents the hanging Promise/subscription.
Reviewed at: 066f090 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Replace the action-layer connectWithoutView watcher with a useOnyx subscription in AddAgentPage. When online, the page stays mounted (showing the submit spinner) until the newly created agent appears in the agent-prompt collection, then opens the DM with its real accountID; creation failures and offline creations dismiss without opening a DM.
|
🚧 mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b533a0b98c
ℹ️ 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".
| // collection, then the effect opens the DM. Snapshot the existing agents so we can tell the new one apart. | ||
| pendingCreatedAgentRef.current = { | ||
| optimisticAccountID, | ||
| knownAgentAccountIDs: new Set(Object.keys(agentPrompts ?? {}).map(getAgentAccountIDFromKey)), |
There was a problem hiding this comment.
Require loaded agent prompts before matching the new agent
When the add page is opened cold or by direct link and SHARED_NVP_AGENT_PROMPT has not finished hydrating at submit time, this snapshots an empty/incomplete known-agent set. If existing agents then load before the CREATE_AGENT response, the effect above treats the first old agent without pendingAction: ADD as createdAgentKey and opens that existing DM instead of the agent just created. Please gate the submit/matching logic on the collection load status or otherwise avoid matching against a partial snapshot.
Useful? React with 👍 / 👎.
|
🤖 No code fix needed — the only failing check is not a code failure. The single failing check is This is a manual gate, not a CI code failure. It stays red until the assigned reviewer posts the PR Reviewer Checklist as a comment on this PR (from Every actual code/build/test check is passing: Bun tests, all To clear it: the reviewer just needs to complete and post the reviewer checklist on the PR. |
On a cold open or direct link, the agent-prompt collection may not have hydrated when the user submits, so the baseline snapshot of existing agents was empty. Agents hydrating before the CREATE_AGENT response were then mistaken for the newly created one, opening the wrong DM. Gate matching on the useOnyx load status and capture the baseline lazily from the first fully-loaded snapshot that already includes our optimistic placeholder, so late-hydrating existing agents are never matched.
Reword the comments to be plainer and more direct, without changing any behavior.
|
@QichenZhu 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] |
| // page open until the created agent shows up in the collection, then open its DM. | ||
| const pendingCreatedAgentRef = useRef<PendingCreatedAgent | null>(null); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
❌ CLEAN-REACT-PATTERNS-4 (docs)
This single anonymous useEffect bundles several distinct responsibilities inline in the component body: (1) gating on collection load status, (2) recording the set of pre-existing agents into a mutable ref, (3) detecting creation failure and navigating back, and (4) scanning the whole collection to identify the newly-created agent and opening its DM. That is a lot of non-trivial matching/business logic living directly in the render function, coupled to the pendingCreatedAgentRef mutation and the Onyx collection shape. Per this rule, even a single effect benefits from extraction into a focused, well-named, independently testable hook.
Extract this into a dedicated hook (e.g. useOpenDMWithCreatedAgent) that owns the concern end-to-end, so AddAgentPage just calls it:
// useOpenDMWithCreatedAgent.ts — owns the "wait for the created agent, then open its DM" concern
function useOpenDMWithCreatedAgent() {
const chatWithAgent = useChatWithAgent();
const [agentPrompts, agentPromptsMetadata] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT);
const pendingCreatedAgentRef = useRef<PendingCreatedAgent | null>(null);
useEffect(() => {
// ...matching + navigation logic moved here...
}, [agentPrompts, agentPromptsMetadata.status, chatWithAgent]);
return (optimisticAccountID: number) => {
pendingCreatedAgentRef.current = {optimisticAccountID, knownAgentAccountIDs: null};
};
}
// AddAgentPage.tsx
const watchForCreatedAgent = useOpenDMWithCreatedAgent();
// ...in handleSubmit, online branch:
watchForCreatedAgent(optimisticAccountID);
setIsCreatingAgent(true);This keeps the matching logic isolated, named, documented, and unit-testable on its own, and slims AddAgentPage down to orchestration.
Reviewed at: 459dcb4 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 459dcb4ebf
ℹ️ 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".
| if (!agentPrompts?.[optimisticAgentKey]) { | ||
| return; | ||
| } | ||
| pendingCreatedAgent.knownAgentAccountIDs = new Set(Object.keys(agentPrompts).map(getAgentAccountIDFromKey)); | ||
| return; |
There was a problem hiding this comment.
Match the first loaded result before baselining
If the agent-prompt collection is still loading, or Onyx batches the optimistic and success updates, the first loaded snapshot that reaches this branch can already contain this request's real sharedNVP_agentPrompt_* key. These lines then either keep returning because the optimistic key was already cleared, or record every key in that snapshot as knownAgentAccountIDs and return, so the real account is treated as pre-existing and no later update is guaranteed to open the DM; this is the opposite timing of the earlier hydration case, where this request's response is already present in the initial snapshot. Please initialize the baseline from a pre-response snapshot or immediately match any eligible non-ADD key in this first snapshot.
Useful? React with 👍 / 👎.
Move the matching and navigation logic out of AddAgentPage's render body into a dedicated hook. AddAgentPage now just calls the hook's returned function on submit, and its test only covers that wiring; the matching logic (collection load status, recording existing agents, skipping other optimistic entries, handling failures) has its own focused test.
|
Closing this to re-approach the optimistic report ID resolution differently. |
Explanation of Change
After creating a new agent, the user was returned to the Agents list (
Navigation.goBack()) with no clear next step. The actual next action is to open a DM with the new agent, but nothing guided the user there.This change opens the DM with the newly created agent immediately after creation instead of just going back.
createAgentalready returns the optimisticaccountIDit writes into Onyx, and the existinguseChatWithAgenthook (the same one each row on the Agents list uses) already knows how to open the DM for a given accountID. SoAddAgentPage.handleSubmitnow captures thatoptimisticAccountIDand hands it tochatWithAgent(...)in place ofNavigation.goBack(). This keeps the flow fully optimistic/offline-first — no waiting on the server — matching the existing behavior of the create action.Updated the
AddAgentPageunit tests to assert the new behavior (the DM is opened with the returned agent accountID) instead of the oldgoBackbehavior.Fixed Issues
$ #94395
PROPOSAL: #94395 (comment)
Tests
Offline tests
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