Skip to content

Do not optimistically create the moved-expense system message when the destination report is a draft - #99721

Merged
inimaga merged 11 commits into
mainfrom
claude-disableThreadOnMovedSystemMessages
Sep 7, 2026
Merged

inimaga merged 11 commits into
mainfrom
claude-disableThreadOnMovedSystemMessages

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Moving an expense into a draft (open) report optimistically created a MOVEDTRANSACTION system message that the backend never creates. That phantom action stayed in Onyx, so anything acting on it — most visibly "Reply in thread" — fired a request against a reportActionID the server had never seen and surfaced "Unexpected error creating this chat. Please try again later."

The earlier fix (Expensify/App#95979) guarded on the source report being a draft. That's the wrong side of the move. inimaga confirmed the backend rule — only the destination matters:

Move Backend creates
Draft → draft nothing
Submitted → draft nothing
Draft → submitted MOVEDTRANSACTION
Submitted → submitted MOVEDTRANSACTION
Any report → personal space UNREPORTEDTRANSACTION

So draft → submitted was suppressed in the app even though the backend does create the message, and submitted → draft was still built optimistically even though the backend doesn't.

This flips the guard to the destination report in src/libs/actions/Transaction.ts:

} else if (!isOpenReport(newReport)) {
    movedAction = buildOptimisticMovedTransactionAction(transactionThreadReportID, oldReportID);
}

Moving to personal space still builds the UNREPORTEDTRANSACTION message, unchanged.

Unit tests cover every row of that table.

Fixed Issues

$ #99653

Tests

  1. Open a workspace chat and create an expense on a draft report (do not submit it).
  2. Create/find a second report and submit it.
  3. Move an expense from the submitted report into the draft report.
  4. Open the moved expense. Verify no "moved this expense from …" system message appears.
  5. Move an expense from the draft report into the submitted report.
  6. Open the moved expense. Verify the "moved this expense from …" system message does appear.
  7. Hover / long-press that message, tap Reply in thread, and verify the thread opens with no "Unexpected error creating this chat. Please try again later." toast.
  8. Move an expense to personal space and verify the "moved this expense from …" message still appears.

Note: It's expected to show moved system message on the expense moved to personal space

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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.

Gate MOVED / MOVEDTRANSACTION system messages out of the thread UI unless they already have a threaded child, so the doomed thread-creation call is never made and the Unexpected error creating this chat message stops appearing.

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
Comment thread src/libs/ReportUtils.ts Outdated
Comment on lines +11700 to +11701
// Moved system messages can't be threaded server-side, so offering "Reply in thread" leads to a failed thread-creation call.
// Gate them out of the thread UI, but keep any moved actions that have already been legitimately threaded.

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.

@MelvinBot Better to add in function jsdoc similar to others, not here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — moved the note into the shouldDisableThread JSDoc as a new bullet alongside the other conditions, and removed the inline comment. Pushed as 4da019c.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Ran the testing steps from this PR on Web.

Outcome: ⚠️ Partial — the move flow works cleanly (moved system message renders, no "Unexpected error creating this chat" toast, no failed network calls, no console-level failures), but I could not open the per-message context menu in this headless web session (hover, right-click, and long-press were all no-ops / unsupported), so I couldn't directly screenshot that "Reply in thread" is absent. That specific step should be confirmed by a human. The source diff does gate it: shouldDisableThread in src/libs/ReportUtils.ts now adds (isMovedSystemMessage && !reportAction?.childVisibleActionCount).

Setup performed: created a workspace, two manual expenses (Test Merchant A €25, Test Merchant B €40) each in its own report, submitted both reports, then used Spend → Expenses → "Move to report" to move Test Merchant A's expense into the Test Merchant B report — producing a MOVED system message.

Step Status Observation
1. Moved system message appears after moving an expense between two already-submitted reports ✅ Pass Detail shows "…moved this expense from Expense Report 2026-08-28"; Report B grew to 2 expenses (€65.00), confirming the move.
2. Context menu does NOT offer "Reply in thread" on the moved message ⚠️ Unverified in-UI Could not open the context menu in this headless session (hover/right-click/long-press unsupported), so the menu's absence wasn't screenshotted. No "X replies" thread affordance renders under the moved message, and the code gates the item off — but needs human confirmation.
3. "Unexpected error creating this chat. Please try again later." does not appear ✅ Pass Not observed anywhere across the full move flow; post-move network dump showed only 200s, zero 4xx/5xx.
4. A moved action with an existing thread still shows/opens its thread ⚠️ Not reproducible No UI path remains to create a pre-existing threaded moved action in a fresh env; the !childVisibleActionCount guard exists to preserve such threads, but none existed here to exercise.
5. No errors appear in the JS console ✅ Pass (proxy) Direct console capture isn't supported for --platform web; as a proxy, the post-move network dump had zero failed requests and no error banners appeared.
Screenshots

Moved expense system message rendered in chat

Moved expense system message rendered in chat

Report B now holds 2 expenses (€65.00) after the move — no error toast

Report B now holds 2 expenses after the move

Hover over the moved system message — no context-menu toolbar rendered

Hover attempt over the moved system message

Baseline hover on a control message — also no toolbar (session-wide limitation)

Baseline hover attempt showing session-wide hover limitation

view run

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@mkhutornyi

Copy link
Copy Markdown
Contributor

@codex review

@mkhutornyi

Copy link
Copy Markdown
Contributor

@MelvinBot review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 4da019c934

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Code review of the diff.

The change is correct and well-scoped, but it misses UNREPORTEDTRANSACTION — the one moved-expense system message where the original bug provably still exists. One more term in isMovedSystemMessage closes it.

1. 🔴 UNREPORTEDTRANSACTION is not covered, and it still builds a phantom action

UNREPORTED_TRANSACTION renders "moved this expense to your personal space" (src/languages/en.ts:1449) — the same muted system-message row, built by the same builder as MOVEDTRANSACTION (ReportUtils.ts:8129), but isMovedSystemMessage doesn't match it.

That matters more than symmetry: #95979 added its !isOpenReport(oldReport) guard only to the MOVEDTRANSACTION branch. The UNREPORTED_TRANSACTION branch is still unconditional at src/libs/actions/Transaction.ts:1653-1657:

if (reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
    movedAction = buildOptimisticUnreportedTransactionAction(...);   // no isOpenReport guard
} else if (!isOpenReport(oldReport)) {
    movedAction = buildOptimisticMovedTransactionAction(...);         // guarded by #95979
}

So moving an expense out of a draft/open report to personal space still produces exactly the phantom optimistic action from #95866 — one the server never adopts — and "Reply in thread" on it still fires createChildReport → openReport({isNewThread: true}) → the report.genericCreateReportFailureMessage toast (Report/index.ts:1787-1793). Same for Report/index.ts:7038 (deleteAppReport).

Suggested fix at ReportUtils.ts:11701:

const isMovedSystemMessage =
    isMovedAction(reportAction) || isMovedTransactionAction(reportAction) || isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION);

…plus the two it.each cases.

2. 🟡 MOVED isn't the message this issue is about

MOVED is "moved this report to the {workspace} workspace" — buildOptimisticMovedReportAction, only produced by IOU-report → workspace conversion. It is not the "moved this expense" message from the repro, and its reportActionID is sent to the backend (dmMovedReportActionID / changePolicyReportActionID in convertIOUReportToExpenseReport), so it's a real server-persisted action — not a phantom.

The issue did ask for MOVED, so this isn't wrong, but the PR description asserts "moved actions can't be threaded server-side" for both. That's demonstrated for the phantom case, not for MOVED. If nobody has confirmed the server actually rejects threads on a real MOVED action, this removes a working affordance. Worth a sentence from whoever owns the backend half.

3. 🟡 "Join thread" also disappears — not mentioned or tested

ContextMenuActions.tsx:789 is the second consumer of shouldDisableThread. Before this PR, Join thread rendered on an unthreaded moved action for any viewer who isn't the mover, and its onPress hit the same doomed openReport. Hiding it is a real improvement — but it's a user-visible menu change beyond "Reply in thread", with no test and no mention in the PR body or QA steps. Please call it out.

4. 🟢 "Leave thread" is still ungated (pre-existing, follow-up)

ContextMenuActions.tsx:844-866 never calls shouldDisableThread. For the user who performed the move, getChildReportNotificationPreference returns ALWAYS (ReportUtils.ts:3016), so subscribed is true and the item renders on their own unthreaded moved message → toggleSubscribeToChildReport's no-childReportID branch → same failing openReport. It passes no isNewThread, so there's no toast — it fails silently and leaves an orphan report. Not a regression from this PR; worth a follow-up issue.

Verified as fine, plus minor notes
  • No effect on existing threads' replies indicator. That's driven by shouldDisplayThreadReplies (ReportUtils.ts:11610-11613), which shouldDisableThread doesn't feed. Whenever that indicator shows, childVisibleActionCount > 0, so the new clause is false anyway — the two are consistent by construction.
  • Mini/hover menu, long-press, and Search chat rows are all covered — they filter the same ContextMenuActions array through the same shouldShow (BaseReportActionContextMenu.tsx:282-321).
  • No deep link or keyboard shortcut creates a thread by parent action ID, and the transaction-thread family all keys off isMoneyRequestAction, so none can target a moved action.
  • Guarded > blanket was the right call, and placing it in shouldDisableThread rather than THREAD_DISABLED (which is ['CREATED'], CONST/index.ts:1867) is correct, since THREAD_DISABLED has no room for the childVisibleActionCount escape hatch.
  • Minor: childVisibleActionCount is a slightly lossy proxy for "has a thread". A thread that exists but has 0 visible comments (all deleted, or created but never commented on) has childVisibleActionCount === 0 with childReportID set — "Reply in thread" is hidden and, since the replies indicator is already hidden in that state, the thread becomes unreachable from the parent chat. childReportID would be the precise signal. Low likelihood and it matches the adjacent isDeletedActionLocal / isReportArchived lines, so consistency arguably wins — just noting it.
  • Minor: MODIFIEDEXPENSE with movedToReportID / movedFromReport (ModifiedExpenseMessage.ts:177-201) also renders "moved an expense from X" and isn't matched. Low risk — it's a real server action — but it's a moved system message that behaves differently from its siblings after this change.
  • Tests read well (Given/When/Then, it.each over both types, both the disabled and the already-threaded case). They only exercise the pure function, which is fine; a ContextMenuActions-level test would be the thing that catches the Join-thread side effect.
  • Prior Melvin web test run confirmed the move flow is clean (no error toast, no failed requests) but could not open the per-message context menu headlessly, so the "Reply in thread is absent" step is still unverified in-UI and needs a human screenshot.

Summary: Approve after #1. Items 2 and 3 want a sentence in the PR description; item 4 is a follow-up issue.


view run

@mkhutornyi

mkhutornyi commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
  1. 🔴 UNREPORTEDTRANSACTION is not covered, and it still builds a phantom action

It's expected. Backends accepts thread for this system message

Screen.Recording.2026-09-01.at.2.51.59.AM.mov

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Regression hunt on this diff. Test suites, typecheck, and a main-vs-branch behavior matrix were run; the context-menu UI check could not be completed (see bottom).

Headline: all four new tests are vacuous — they pass with the fix removed. I verified this by executing code, not by reading it. Two real behavior regressions below that, both narrow.

R1 🔴 The new tests can't fail — CI would green-light a revert of this PR

createMock is a bare cast (tests/utils/createMock.ts), so the mocks have no message field. isDeletedAction defaults a missing message to [] (ReportActionsUtils.ts:218) and treats an empty array as a legacy deleted comment (:226). MOVED / MOVEDTRANSACTION aren't in its early-return list — so the pre-existing clause (isDeletedActionLocal && !childVisibleActionCount) at ReportUtils.ts:11706 already returns true, and the new clause at :11708 is never load-bearing.

Proof — I neutralized only the new clause to (false && isMovedSystemMessage && …) and re-ran:

✓ should be disabled for a MOVED action with no child visible action count
✓ should be disabled for a MOVEDTRANSACTION action with no child visible action count
✓ should be enabled for a MOVED action that has already been threaded
✓ should be enabled for a MOVEDTRANSACTION action that has already been threaded
Tests: 1280 skipped, 4 passed, 1284 total

Fix, also verified: add a real message to the two "should be disabled" mocks —

message: [{type: 'COMMENT', html: 'moved this expense', text: 'moved this expense'}],

With that added and the clause still neutralized, the tests correctly fail (2 failed, 2 passed), then pass again once the clause is restored. That makes them load-bearing.

R2 🟡 An existing moved-action thread becomes unreachable once its reply count returns to 0

childReportID set + childVisibleActionCount === 0 is reachable: reply in thread on a moved action, post one reply, delete it. The DELETE branch decrements the count back to 0 while childReportID stays set (ReportUtils.ts:7018-7026).

Every other door is already shut in that state — the "N replies" link needs count > 0 (:11610-11613), the LHN and search router drop empty chat threads (:10342), and an empty thread can never be unread. On main you re-enter via Reply in thread, which reuses the existing child rather than creating one (const report = childReport ?? createChildReport(…), Report/index.ts:2804). On this branch nothing is left but a hand-typed /r/<childReportID>.

Bounded: only bites threads created before this deploys. childReportID instead of childVisibleActionCount would avoid it, at the cost of diverging from the adjacent deleted/archived clauses.

R3 🟡 "Join thread" disappears, and it was not broken client-side

Measured by running the real shouldShow from ContextMenuActions against both code states:

Moved action shape (realistic message, non-actor viewer) shouldDisableThread Reply in thread Join thread
no childReportID, count 0 or undefined false → true shows → hidden shows → hidden
childReportID set, count 0 or undefined false → true shows → hidden shows → hidden
childReportID set, count 3 false → false shows → shows shows → shows
the PR's own mock (no message), count 0 true → true hidden → hidden hidden → hidden

joinThread passes every other gate (ContextMenuActions.tsx:780-800), and with no childReportID it created the thread via toggleSubscribeToChildReport's else branch (Report/index.ts:3852-3882) — same mechanism as Reply in thread, so both share one server fate. Whether removing it is a fix or a feature loss rests entirely on R4.

R4 🟡 The premise "moved actions can't be threaded server-side" is still unverified — and the diff contradicts it

Two in-repo signals point the other way:

I could not settle this from code, and the VictoriaLogs tooling wasn't available in this run, so treat it as genuinely open rather than as evidence either way. Someone with log access should check whether OpenReport with a parentReportActionID pointing at a MOVED/MOVEDTRANSACTION action actually fails, and whether threads with those parents exist in volume.

Checked and clean — no regression found

Test runs on 4da019c9 (tree restored afterwards; nothing committed):

Command Result
npm test -- tests/unit/ReportUtilsTest.ts -t "shouldDisableThread" 1 suite passed, 17 passed
npm test -- tests/unit/ContextMenuActionsCopyMessageTest.ts tests/ui/ReportActionItemTest.tsx tests/unit/ReportActionsUtilsTest.ts 3 suites passed, 611 passed
npm test -- tests/actions/ReportTest.ts tests/actions/TransactionTest.ts 2 suites passed, 290 passed
npx tsc --noEmit -p tsconfig.json clean, zero output
  • Snapshots: 0 total in every suite — no snapshot churn from the removed menu items.
  • Mini/hover menu: dropping 2 items can flip otherActions.length from >4 to ≤4, changing "3 items + ⋯" into "N items, no ⋯" (BaseReportActionContextMenu.tsx:316-322). The else branch renders all of them and menu is the only item keying off isMini, so nothing becomes unreachable — cosmetic reflow only.
  • Keyboard nav: shouldEnableArrowNavigation = !isMini; the full menu just has one fewer index.
  • Menu never renders empty: markAsUnread, copyMessage, copyLink still show on moved actions.
  • Search page chat rows: ReportActionItem already suppresses thread replies via isOnSearch; childReportID substitution is transaction-only.
  • Read-only gating: RestrictedReadOnlyContextMenuActions keys off textTranslateKey, independent of shouldShow.
  • Existing threads with replies are fully preserved — verified in the matrix above (count 3 row unchanged).
Web UI check — could not run (environment limitation)

Outcome: ❌ Fail on the baseline step, so no conclusion about the menu itself. This is the same blocker as the earlier run on this PR, and it is not a finding about the code.

Step Status Observation
1. Context menu opens on a plain text message and offers "Reply in thread" (baseline) ❌ Fail Sent a message successfully, then tried hover via @ref (no bounds), hover via coordinates at multiple points across 3 viewports with settle delays up to 1200ms (no toolbar, no highlight, zero accessibility-tree diff), right-click (UNSUPPORTED_OPERATION), and long-press (not supported on web). Sanity check: hover produced no effect on a button or an LHN row either, so hover simulation is inert session-wide.
2–4. Moved-message menu contents, absence of Reply/Join thread, ordinary threading still works ⏭️ Not attempted Stopped after the baseline failed rather than fabricate menu contents.
Evidence (3)

Plain text message sent in Concierge chat

Plain text message sent in Concierge chat

Hover attempt over a message row shows no toolbar or highlight

Hover attempt over a message row shows no toolbar or highlight

Hover attempt over LHN chat row shows no hover affordance (sanity check)

Hover attempt over LHN chat row shows no hover affordance (sanity check)

The "Reply in thread is absent" step still needs a human screenshot.


Bottom line: R1 is the one to fix before merge — it's a two-line test change and without it the suite guards nothing. R2 and R3 are narrow and arguably acceptable, but belong in the PR description. R4 is the open question the whole change rests on.


view run

@mkhutornyi

Copy link
Copy Markdown
Contributor

@MelvinBot address R1 in #99721 (comment)

The mocks had no message field, so isDeletedAction treated them as legacy
deleted comments and the pre-existing deleted-and-unthreaded clause already
returned true. The new isMovedSystemMessage clause was never exercised, so
the tests passed with it removed. Add a real message, matching the sibling
archived/deleted cases in the same describe block.

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 R1 fixed and pushed — 8f303e2.

The finding was right: the four mocks had no message, so isDeletedAction treated them as legacy deleted comments (ReportActionsUtils.ts:226) and the pre-existing (isDeletedActionLocal && !childVisibleActionCount) clause already returned true. The new clause was never load-bearing.

Added a real message to all four mocks, matching the sibling archived/deleted cases already in that describe block, plus a comment on the "should be disabled" case explaining why the message is required (ReportUtilsTest.ts:5331-5345) — so nobody trims it back out.

Verified the tests are now load-bearing, by execution:

State Result
Fix in place, isMovedSystemMessage clause intact 4 passed
Fix in place, clause neutralized to (false && isMovedSystemMessage && …) 2 failed, 2 passed
Clause restored 4 passed

The two "already threaded" cases still pass with the clause neutralized — that's inherent to a negative assertion (childVisibleActionCount: 1 makes every disabling clause false either way). They're the escape-hatch control, not a guard on the new clause. The two "should be disabled" cases are the ones that now fail on a revert.

Checks run on 8f303e2
Command Result
npm test -- tests/unit/ReportUtilsTest.ts --silent 1 suite passed, 1284 passed, 0 snapshots
npm run typecheck passed (all 4 tsconfigs)
npx eslint tests/unit/ReportUtilsTest.ts 0 errors; 1 pre-existing grandfathered no-restricted-imports warning on the isPaidGroupPolicy import at line 26, untouched by this commit
npm run fmt (oxfmt) clean — no files rewritten

Only tests/unit/ReportUtilsTest.ts changed; src/libs/ReportUtils.ts is byte-identical to 4da019c9 (the neutralized clause was reverted before committing — confirmed via git diff). I did not run the full app suite or the Storybook smoke test, since the change is confined to one test file and the affected suite passes in full.

R2, R3 and R4 are untouched — say the word if you want any of them addressed.


view run

@mkhutornyi

Copy link
Copy Markdown
Contributor
Details

Explanation of Change

Moved system messages (MOVED / MOVEDTRANSACTION) can't be threaded server-side, but the app still offered "Reply in thread" on them. Tapping it fired a thread-creation call against an action the server never adopted, which failed and surfaced "Unexpected error creating this chat. Please try again later."

The earlier fix (Expensify/App#95979) only closed the narrow "create report from a draft expense" repro. This change gates moved system messages out of the thread UI at the source, in shouldDisableThread, so the doomed thread-creation call is never made.

I used the guarded approach from the issue rather than blanket-adding the actions to THREAD_DISABLED: threading is disabled only when the moved action has no threaded child (!reportAction?.childVisibleActionCount), mirroring how deleted/archived actions are already handled. This preserves any moved actions users have legitimately threaded.

As noted in the issue, the backend root-cause (why the moved action can't be threaded at all) is tracked internally and is out of scope here — this is the defensive FE fix that stops the user-facing error.

Fixed Issues

$ #99653

Tests

  1. Open a workspace chat that has an expense report.
  2. Move an expense between two already-submitted reports so a moved system message appears in the chat.
  3. Long-press / hover the moved system message and open the context menu.
  4. Verify "Reply in thread" is not offered.
  5. Verify "Unexpected error creating this chat. Please try again later." does not appear.

Note: It's expected to show moved system message on the expense moved to personal space

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

Same as Tests

  • 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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.

@MelvinBot please set the PR body to the content in the details section above and mark as ready for review

@MelvinBot
MelvinBot marked this pull request as ready for review September 1, 2026 03:22
@MelvinBot
MelvinBot requested a review from a team as a code owner September 1, 2026 03:22
@melvin-bot
melvin-bot Bot requested review from dylanexpensify and mkhutornyi and removed request for a team September 1, 2026 03:22
@melvin-bot

melvin-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

@mkhutornyi 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 September 1, 2026 03:22
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Done — PR body replaced with the content from your details block, and the PR is now ready for review (no longer a draft).

Two notes on the body you supplied:

  • The Screenshots/Videos section is gone (it wasn't in your details block). The PR Author Checklist / checklist job may fail on the "I included screenshots or videos for tests on all platforms" item if it looks for that section — happy to add it back if you want.
  • The new "Note: It's expected to show moved system message on the expense moved to personal space" line reads as a deliberate scope call on the UNREPORTEDTRANSACTION gap I raised in my review. Worth confirming that's the intent, since that message is still offered "Reply in thread" and — when the expense is moved out of a draft report — is still built as a phantom optimistic action (src/libs/actions/Transaction.ts:1653-1657), so the same error toast can still fire there.

view run

@mkhutornyi

Copy link
Copy Markdown
Contributor

@MelvinBot I noticed that "reply in thread" is enabled in backend when source report is draft report, destination report is submitted report.
In reverse, "reply in thread" is disabled in backend when source report is submitted report, destination report is draft.
Let's fix these to match backend.

…raft

The backend threads a MOVEDTRANSACTION system message when the expense lands
in a submitted report, and refuses when it lands in a draft report. Blanket
disabling hid Reply in thread on messages the backend would have threaded, so
key the gate on the destination report instead.

The destination is the parent of the transaction thread the action lives on,
resolved in BaseReportActionContextMenu and passed through the context menu's
shouldShow payload, which also keeps Join thread consistent with Reply in
thread. MOVED (a report moved between workspaces) is unchanged.

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner September 1, 2026 03:54
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done — the branch now matches the backend rule inimaga confirmed, and I proved the tests actually enforce it.

The code was already right. 4cb8160 (pushed before that confirmation) had flipped the guard to the destination report, which is exactly option 2. So this run verified it rather than rewriting it.

What I changed: the personal-space test only covered a draft source, so the confirmed "Any report → personal space" row wasn't fully encoded. Parametrized it over draft and submitted sources — dfde483.

Confirmed backend behavior Covered by
Draft → draft: no message should not create a MOVED_TRANSACTION action when the expense is moved from a draft report into a draft report
Submitted → draft: no message same it.each, submitted source
Draft → submitted: create message should create a MOVED_TRANSACTION action when the expense is moved from a draft report into a submitted report
Submitted → submitted: create message same it.each, submitted source
Any report → personal space: UNREPORTEDTRANSACTION should create an UNREPORTED_TRANSACTION action when the expense is moved to personal space from a %s report (new)

I also updated the PR description with that table and a link to your confirmation, so the reasoning isn't buried in the thread.

The tests are load-bearing — I checked by execution, not by reading. Reverting the guard to !isOpenReport(oldReport) fails exactly the two rows the old logic got wrong:

● ...moved from a submitted report into a draft report   Expected: 0  Received: 1
● ...moved from a draft report into a submitted report   Expected: 1  Received: 0
Tests: 2 failed, 4 passed

Restored, all 81 tests across both Transaction suites pass.

Checks run
Check Result
tests/actions/TransactionTest.ts + tests/unit/TransactionTest.ts ✅ 81 passed
npm run typecheck ✅ passed
npm run lint-changed ✅ clean
npm run spell-changed ✅ 0 issues
Guard-revert check ✅ 2 tests fail as expected
Web UI verification ❌ could not run

npx prettier --check couldn't run — it resolves a prettier config outside the App checkout and fails on a missing plugin. Environment issue, unrelated to the diff.

Web verification failed on the environment, not the code. The dev server returned 200 and webpack built cleanly, but the app rendered a solid-white page with 0 accessibility nodes for ~11 minutes, so none of the four UI steps could be attempted. Steps 3–8 in the PR description still need a human screenshot.

One thing outside this PR's scope, worth a second opinion: TrackExpense.ts:1261 also builds a MOVEDTRANSACTION action unconditionally when a tracked expense is categorized/shared onto a report. That's a different backend command, so the destination rule may not apply — but if it does, the same phantom action is possible there. inimaga would know.


view run

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@mkhutornyi

Copy link
Copy Markdown
Contributor

@MelvinBot pull main and fix Oxfmt diff

MelvinBot and others added 2 commits September 2, 2026 18:13
…nMovedSystemMessages

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done — main merged and the Oxfmt diff fixed. Oxfmt check now passes (run).

  • 100ce870 — merge main (a9a9436) into the branch. No conflicts; all four PR files intact.
  • 4f6c991 — npm run fmt. One line: oxfmt joined the countMovedActions arrow body onto a single line in tests/actions/TransactionTest.ts:642. That was the only formatting diff in the repo.
Checks run after the merge
Check Result
tests/actions/TransactionTest.ts + tests/unit/TransactionTest.ts ✅ 81 passed
npm run typecheck ✅ passed
npm run lint-changed ✅ clean
npm run spell-changed ✅ 0 issues
Oxfmt check (CI) ✅ pass

The only remaining failure is Check independent approval, which needs a human reviewer, not a code change. The rest of CI was still running when I finished.


view run

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

good from a product perspective 👍

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

@mkhutornyi Let me know when this is ready for review.

@mkhutornyi

mkhutornyi commented Sep 6, 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 any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • 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 and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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
ios1.mov
ios2.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@melvin-bot

melvin-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

We did not find an internal engineer to review this PR, trying to assign a random engineer to #99653 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot
melvin-bot Bot requested a review from marcochavezf September 6, 2026 11:09
@mkhutornyi

Copy link
Copy Markdown
Contributor

@MelvinBot pull main

…nMovedSystemMessages

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
@MelvinBot

MelvinBot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Merged main into claude-disableThreadOnMovedSystemMessages and pushed.

  • Merge commit: cd9efca88e0 (merged 0283d2bebad)
  • No conflicts — the merge was clean, so nothing needed manual resolution.
  • The PR's own changes are intact: src/libs/actions/Transaction.ts, tests/actions/TransactionTest.ts, tests/unit/TransactionTest.ts, and src/libs/API/parameters/ChangeTransactionsReportParams.ts still diff against main as before.

The branch is mergeable again. Checks are re-running on the new commit.


view run · view recording

@mkhutornyi

Copy link
Copy Markdown
Contributor

@mkhutornyi Let me know when this is ready for review.

@inimaga ready

@inimaga
inimaga self-requested a review September 7, 2026 10:22

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

@inimaga
inimaga merged commit b6b3f83 into main Sep 7, 2026
44 checks passed
@inimaga
inimaga deleted the claude-disableThreadOnMovedSystemMessages branch September 7, 2026 10:25
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Sep 7, 2026

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 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/inimaga in version: 9.4.73-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Yes — help site changes were required. Draft PR: #100498

Two articles documented the old, source-based rule this PR replaced:

I verified the shipped behavior on dev NewDot web rather than reading it off the diff, and it matches your table:

Move System message in the expense
Submitted → draft none
Draft → submitted "moved this expense from <report>"
Remove from report (personal space) "moved this expense from <report>"
Also corrected: stale UI labels in the move steps, and one thing for you

While editing those steps in Managing-Expenses-in-a-Report.md I fixed labels that no longer match the product, checked against the live UI:

  • The menu item is Move to report; the article said Move expense(s).
  • The green button is labeled with the selection count, e.g. 1 selected; the article said the green selected button.
  • The "To move or remove all expenses from a report" flow was missing the step where you actually check the expenses.
  • The destination panel offers Create report, the existing reports, and Remove from report (subtitled "Move expenses to your personal space") — that part was already correct.

Possible App bug, not a docs issue: for the Remove from report case, the rendered message reads "moved this expense from <report>" but that node's accessibility label reads "moved this expense to your personal space." The articles describe what's on screen so the docs PR doesn't depend on it, but the mismatch looks unintentional.

@mkhutornyi, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

OSBotify commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.73-3 🚀

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

Bundle Size Analysis (Sentry):

truph01 pushed a commit to truph01/App that referenced this pull request Sep 15, 2026
…eport

Expensify#99721 moved the optimistic MOVED_TRANSACTION guard from the source report to the destination report to match the backend. Update the two help articles that documented the old source-based rule, and correct the move-flow UI labels to match the current product.

Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants