You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-01-29] Optimistically compute report names on creation #76855
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
We have a thorough function for computing report names, and we were going to build a system to optimistically compute report names whenever a dependency of the report name formula updated, but scrapped that idea. Now report names will not be optimistically computed at all.
Solution
It will be sufficient to optimistically compute the report name when reports are created, so that they use the proper name right away.
Replace the call to populateOptimisticReportFormula with a call to compute, or otherwise merge the logic together. Verify various report formulas compute correctly optimistically when reports are created.
🚨 Edited by proposal-police: This proposal was edited at 2025-12-09 21:51:06 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
We have a thorough function (compute) for computing report names from formula templates, and we were going to build a system to optimistically compute report names whenever a dependency of the report name formula updated, but scrapped that idea. Now report names will not be optimistically computed at all. When reports are created, they use a simpler function (populateOptimisticReportFormula) that uses basic regex replacements, which may not handle all formula cases correctly and is inconsistent with the more comprehensive compute function used elsewhere in the codebase.
What is the root cause of that problem?
The current implementation uses populateOptimisticReportFormula in three places when creating optimistic reports:
buildOptimisticExpenseReport in App/src/libs/ReportUtils.ts (line 6875)
buildOptimisticEmptyReport in App/src/libs/ReportUtils.ts (line 6907)
convertIOUReportToExpenseReport in App/src/libs/actions/Report.ts (line 5459)
The populateOptimisticReportFormula function uses simple regex replacements (e.g., .replaceAll(/\{report:total\}/gi, ...)) which:
May not handle all formula edge cases correctly
Doesn't support all formula features that compute supports (e.g., functions, field references, proper parsing)
Is inconsistent with the more thorough compute function that's already used in OptimisticReportNames.ts for computing report names when dependencies update
May not handle complex formulas with nested braces or special formatting correctly
The compute function in App/src/libs/Formula.ts is a more comprehensive solution that:
Properly parses formulas into parts
Handles all formula types (report, field, user, freetext)
Supports functions and formatting
Is already used successfully in OptimisticReportNames.ts
Requires allTransactions to be passed in the FormulaContext for proper computation of fields like {report:expensescount}, {report:startdate}, and {report:enddate}
What changes do you think we should make in order to solve the problem?
1. Add transactions parameter to build functions
Add an optional allTransactions parameter to buildOptimisticExpenseReport and buildOptimisticEmptyReport functions so transactions can be passed from call sites when available. The transactions should be in the format Record<string, Transaction> where the key is the transaction ID.
2. Replace populateOptimisticReportFormula with compute in report creation functions
Update the three locations where populateOptimisticReportFormula is called to use compute instead, building the appropriate FormulaContext with the provided transactions.
App/src/libs/ReportUtils.ts - buildOptimisticExpenseReport function (around line 6874-6883):
Update the function signature to accept transactions:
Get transactions for the report and update the report name computation (around line 5462-5464):
consttitleReportField=getTitleReportField(getReportFieldsByPolicyID(policyID)??{});if(!!titleReportField&&isPaidGroupPolicy(policy)){// Get transactions for this report to pass to computeconstreportTransactions=getReportTransactions(iouReport.reportID);constallTransactions: Record<string,Transaction>={};reportTransactions.forEach((transaction)=>{if(transaction?.transactionID){allTransactions[transaction.transactionID]=transaction;}});constformulaContext: FormulaContext={report: expenseReport,
policy,
allTransactions,};constcomputedName=compute(titleReportField.defaultValue,formulaContext);expenseReport.reportName=computedName||expenseReport.reportName;}
3. Update call sites to pass transactions when available
Update call sites of buildOptimisticExpenseReport and buildOptimisticEmptyReport to pass transactions when they are available. For example, in App/src/libs/actions/IOU.ts where buildOptimisticExpenseReport is called (around line 3867), if there are optimistic transactions available, they should be converted to the Record<string, Transaction> format and passed to the function.
4. Remove or deprecate populateOptimisticReportFormula function
After replacing all usages, we can either:
Remove the populateOptimisticReportFormula function entirely (if it's not used elsewhere)
Mark it as deprecated and remove it in a future cleanup
5. Update tests
Update the tests in App/tests/unit/ReportUtilsTest.ts that test populateOptimisticReportFormula to instead test the compute function with appropriate FormulaContext objects, or remove those tests if they're no longer relevant.
6. Verify various report formulas compute correctly
Test that various report formula patterns work correctly when reports are created:
{report:id} - Should show base62 report ID
{report:total} - Should show formatted total amount
{report:type} - Should show "Expense Report"
{report:startdate} - Should show formatted start date (requires transactions)
{report:enddate} - Should show formatted end date (requires transactions)
{report:expensescount} - Should show count of expenses (requires transactions)
{report:status} - Should show human-readable status
{report:policyname} or {report:workspacename} - Should show policy name
{report:created} - Should show creation date/time
{user:email} - Should show user email
Complex formulas with multiple fields and free text (e.g., Report {report:id} - {report:total})
Formulas with functions (e.g., {user:email|frontPart})
What alternative solutions did you explore? (Optional)
Keep both functions: We could keep populateOptimisticReportFormula for simple cases and use compute for complex ones, but this adds unnecessary complexity and inconsistency.
Enhance populateOptimisticReportFormula: We could improve populateOptimisticReportFormula to handle more cases, but this would duplicate logic that already exists in compute and would be harder to maintain.
Use compute only for complex formulas: We could detect if a formula is "complex" and only use compute in those cases, but this adds complexity and the simpler approach of always using compute is cleaner.
Pass empty transactions object: We initially considered passing an empty {} for allTransactions, but this would cause incorrect computation of formula fields that depend on transactions (like {report:expensescount}, {report:startdate}, {report:enddate}). The Formula.ts functions need access to actual transactions to compute these values correctly.
The chosen solution (replacing populateOptimisticReportFormula with compute and passing transactions) is the cleanest approach because:
It uses the existing, well-tested compute function
It ensures consistency across the codebase
It handles all formula cases correctly, including those that depend on transactions
It's easier to maintain (one function instead of two)
It properly supports all formula features that depend on transaction data
Please re-state the problem that we are trying to solve in this issue.
Optimistically compute report names on creation
What is the root cause of that problem?
Feature request
What changes do you think we should make in order to solve the problem?
Replace the deprecated populateOptimisticReportFormula function with the comprehensive compute function from Formula.ts to enable full formula support when optimistically computing report names during report creation.
We can add different types of tests to test complex scenarios
test('should compute report name with type and total', () => {
const result = compute('{report:type} - Total: {report:total}', mockContext);
expect(result).toBe('Expense Report - Total: $100.00');
});
test('should preserve free text in report names', () => {
const result = compute('Expense Report for {report:policyname}', mockContext);
expect(result).toBe('Expense Report for Test Policy');
});
What alternative solutions did you explore? (Optional)
Yes it mostly looks good. One problem is that you pass allTransactions as empty. It is needed in various places within Formula.ts. We should pass the report transactions as a collection from the UI component(s) to these "buildOptimistic" functions and pass that in for the context.
Note: We need to check if isMoneyRequestConfirmation is passed to buildOptimisticEmptyReport. If not, we may need to add it as a parameter or handle it differently. Currently, buildOptimisticEmptyReport doesn't accept this parameter, so we may need to add it or handle the money request confirmation case at the call site.
I also don't really understand the problem / solution behind this note.
Please let me know when your proposal is updated @abbasifaizan70
changed the title [-][Due for payment 2026-01-21] Optimistically compute report names on creation[/-][+][Due for payment 2026-01-29] Optimistically compute report names on creation[/+]on Jan 28, 2026
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: N/A, this is a new feature
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: regression wasn't critical
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
Regression Test Proposal Template
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Create or use an existing Team or Corporate workspace (not a personal workspace)
Go to Settings > Workspaces > [Your Workspace] > Report Fields
Set up a custom Report Title formula. Examples to test:
Choose a workspace that has a custom report title formula
Fill in the expense details (amount, merchant, etc.)
Submit the expense
The expense report should be created with the optimistic report name computed using the formula (e.g., "Expense Report - $25.00" instead of the default "[Workspace] owes $25.00")
Test Case 2: Offline Mode
Turn on Airplane mode / disconnect from internet
Create a new expense in a workspace with custom report title formula
The report name should still be computed optimistically using the formula
Reconnect to internet
The report name should remain correct after sync
Do we agree 👍 or 👎
Reacted by Nicole Mendonca and Faizan Shoukat Abbasi
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor
Activity
melvin-bot commentedon Dec 5, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eVoloshchak (
External)PiyushChandra17 commentedon Dec 5, 2025
I can work on this
neil-marcellini commentedon Dec 5, 2025
Please post a proposal since this one is a little more involved than similar issues.
abbasifaizan70 commentedon Dec 5, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-12-09 21:51:06 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
We have a thorough function (
compute) for computing report names from formula templates, and we were going to build a system to optimistically compute report names whenever a dependency of the report name formula updated, but scrapped that idea. Now report names will not be optimistically computed at all. When reports are created, they use a simpler function (populateOptimisticReportFormula) that uses basic regex replacements, which may not handle all formula cases correctly and is inconsistent with the more comprehensivecomputefunction used elsewhere in the codebase.What is the root cause of that problem?
The current implementation uses
populateOptimisticReportFormulain three places when creating optimistic reports:buildOptimisticExpenseReportinApp/src/libs/ReportUtils.ts(line 6875)buildOptimisticEmptyReportinApp/src/libs/ReportUtils.ts(line 6907)convertIOUReportToExpenseReportinApp/src/libs/actions/Report.ts(line 5459)The
populateOptimisticReportFormulafunction uses simple regex replacements (e.g.,.replaceAll(/\{report:total\}/gi, ...)) which:computesupports (e.g., functions, field references, proper parsing)computefunction that's already used inOptimisticReportNames.tsfor computing report names when dependencies updateThe
computefunction inApp/src/libs/Formula.tsis a more comprehensive solution that:OptimisticReportNames.tsallTransactionsto be passed in theFormulaContextfor proper computation of fields like{report:expensescount},{report:startdate}, and{report:enddate}What changes do you think we should make in order to solve the problem?
1. Add transactions parameter to build functions
Add an optional
allTransactionsparameter tobuildOptimisticExpenseReportandbuildOptimisticEmptyReportfunctions so transactions can be passed from call sites when available. The transactions should be in the formatRecord<string, Transaction>where the key is the transaction ID.2. Replace
populateOptimisticReportFormulawithcomputein report creation functionsUpdate the three locations where
populateOptimisticReportFormulais called to usecomputeinstead, building the appropriateFormulaContextwith the provided transactions.App/src/libs/ReportUtils.ts-buildOptimisticExpenseReportfunction (around line 6874-6883):Update the function signature to accept transactions:
Add imports at the top of the file:
Update the report name computation (around line 6873-6876):
App/src/libs/ReportUtils.ts-buildOptimisticEmptyReportfunction (around line 6883-6919):Update the function signature to accept transactions:
Update the report name computation (around line 6907-6908):
App/src/libs/actions/Report.ts-convertIOUReportToExpenseReportfunction (around line 5440-5464):Add imports at the top of the file:
Get transactions for the report and update the report name computation (around line 5462-5464):
3. Update call sites to pass transactions when available
Update call sites of
buildOptimisticExpenseReportandbuildOptimisticEmptyReportto pass transactions when they are available. For example, inApp/src/libs/actions/IOU.tswherebuildOptimisticExpenseReportis called (around line 3867), if there are optimistic transactions available, they should be converted to theRecord<string, Transaction>format and passed to the function.4. Remove or deprecate
populateOptimisticReportFormulafunctionAfter replacing all usages, we can either:
populateOptimisticReportFormulafunction entirely (if it's not used elsewhere)5. Update tests
Update the tests in
App/tests/unit/ReportUtilsTest.tsthat testpopulateOptimisticReportFormulato instead test thecomputefunction with appropriateFormulaContextobjects, or remove those tests if they're no longer relevant.6. Verify various report formulas compute correctly
Test that various report formula patterns work correctly when reports are created:
{report:id}- Should show base62 report ID{report:total}- Should show formatted total amount{report:type}- Should show "Expense Report"{report:startdate}- Should show formatted start date (requires transactions){report:enddate}- Should show formatted end date (requires transactions){report:expensescount}- Should show count of expenses (requires transactions){report:status}- Should show human-readable status{report:policyname}or{report:workspacename}- Should show policy name{report:created}- Should show creation date/time{user:email}- Should show user emailReport {report:id} - {report:total}){user:email|frontPart})What alternative solutions did you explore? (Optional)
Keep both functions: We could keep
populateOptimisticReportFormulafor simple cases and usecomputefor complex ones, but this adds unnecessary complexity and inconsistency.Enhance
populateOptimisticReportFormula: We could improvepopulateOptimisticReportFormulato handle more cases, but this would duplicate logic that already exists incomputeand would be harder to maintain.Use
computeonly for complex formulas: We could detect if a formula is "complex" and only usecomputein those cases, but this adds complexity and the simpler approach of always usingcomputeis cleaner.Pass empty transactions object: We initially considered passing an empty
{}forallTransactions, but this would cause incorrect computation of formula fields that depend on transactions (like{report:expensescount},{report:startdate},{report:enddate}). TheFormula.tsfunctions need access to actual transactions to compute these values correctly.The chosen solution (replacing
populateOptimisticReportFormulawithcomputeand passing transactions) is the cleanest approach because:computefunctionNodebrute commentedon Dec 5, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
Optimistically compute report names on creation
What is the root cause of that problem?
Feature request
What changes do you think we should make in order to solve the problem?
Replace the deprecated
populateOptimisticReportFormulafunction with the comprehensive compute function fromFormula.tsto enable full formula support when optimistically computing report names during report creation.App/src/libs/actions/Report.ts
Line 5459 in 7536155
2.We should replace this with
App/src/libs/ReportUtils.ts
Line 6875 in 7536155
3.And here we should replce it with
App/src/libs/ReportUtils.ts
Line 6907 in 7536155
**Testing branch:**https://github.com/Nodebrute/App/tree/replace-optimistic-formula-with-compute. Incase we decide we can also keep
populateOptimisticReportFormulafunctionWorks as expected
https://github.com/user-attachments/assets/b48bbb46-661b-4c82-9fdd-24629548515d
Tests
We can add different types of tests to test complex scenarios
What alternative solutions did you explore? (Optional)
eVoloshchak commentedon Dec 7, 2025
@abbasifaizan70's proposal looks good to me!
🎀👀🎀 C+ reviewed!
melvin-bot commentedon Dec 7, 2025
Current assignee @neil-marcellini is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.
neil-marcellini commentedon Dec 9, 2025
Yes it mostly looks good. One problem is that you pass allTransactions as empty. It is needed in various places within Formula.ts. We should pass the report transactions as a collection from the UI component(s) to these "buildOptimistic" functions and pass that in for the context.
I also don't really understand the problem / solution behind this note.
Please let me know when your proposal is updated @abbasifaizan70
abbasifaizan70 commentedon Dec 9, 2025
@neil-marcellini updated proposal. Please have a look thanks.
27 remaining items
melvin-bot commentedon Jan 24, 2026
@eVoloshchak, @neil-marcellini, @abbasifaizan70 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
melvin-bot commentedon Jan 27, 2026
Triggered auto assignment to @NicMendonca (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.NicMendonca commentedon Jan 28, 2026
This was deployed 5 days ago, so issuing payment on Thursday Jan 29th
[-][Due for payment 2026-01-21] Optimistically compute report names on creation[/-][+][Due for payment 2026-01-29] Optimistically compute report names on creation[/+]eVoloshchak commentedon Jan 29, 2026
BugZero Checklist:
[Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to comment: N/A, this is a new feature
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: regression wasn't critical
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
Regression Test Proposal Template
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue:
Regression Test Proposal
Precondition:
Test:
Test Case 1: Create New Expense in Workspace
Test Case 2: Offline Mode
Do we agree 👍 or 👎
melvin-bot commentedon Jan 29, 2026
Payment Summary
Upwork Job
BugZero Checklist (@NicMendonca)
NicMendonca commentedon Jan 30, 2026
Payment Summary
Contributor: @abbasifaizan70 paid $250 via Upwork (✅ )
Contributor+: @eVoloshchak due $250 via NewDot
trjExpensify commentedon Mar 4, 2026
approved $250 for @eVoloshchak.