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
[$250] Expense - The 'Tag no longer valid' violation appears after deleting the only tag #88338
Version Number: v9.3.60-17 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:https://test-management.browserstack.com/projects/2219752/folder/13176676/test-cases/95492766 Email or phone of affected tester (no customers):agexptest+wt170426@gmail.com Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Windows 11/ Chrome, Samsung S23FE/ Android 16, iPhone 13 Mini/ iOS 26.3 App Component: Money Requests
Action Performed:
Precondition: Have a workspace with the Tags feature enabled.
Please run this test both ONLINE and OFFLINE
The client-side violation engine in ViolationsUtils.ts:85-89 correctly guards against adding tagOutOfPolicy when there are no enabled tags remaining:
const hasEnabledTagsInList = hasEnabledTags(policyTags);
if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy && hasEnabledTagsInList) {
// Only add violation if there ARE enabled tags to choose from
}
When the only tag is deleted, deletePolicyTags marks the tag as enabled: false optimistically, and the violation computation correctly sees no enabled tags → no violation is added.
However, pushTransactionViolationsOnyxData only pushes optimistic violation data — there is no successData for TRANSACTION_VIOLATIONS (ReportUtils.ts:2179-2186). When the backend responds to the DeletePolicyTags API call, its onyxData overrides the correct optimistic violations. The backend likely computes tagOutOfPolicy without the hasEnabledTags guard, so the violation reappears after the server response arrives.
What changes do you think we should make in order to solve the problem?
There are two complementary approaches:
Primary fix (backend): The backend's violation computation for DeletePolicyTags should check whether any enabled tags remain before adding tagOutOfPolicy. If all tags in the list are deleted/disabled, no tagOutOfPolicy violation should be added.
Client-side hardening (recommended alongside): Add the violations to successData in pushTransactionViolationsOnyxData so the correct client-side computation persists even after the API response is applied. This would mean the correct optimistic violations aren't silently overwritten by the backend.
What alternative solutions did you explore? (Optional)
Filtering violations at the display layer (e.g., suppress tagOutOfPolicy when no enabled tags exist) — this would work but is a workaround that masks the backend issue.
Clearing the tag from transactions when the tag is deleted — this changes the data model semantics and is a larger change than needed. The current design intentionally keeps the stale tag on transactions.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
changed the title [-]Expense - The 'Tag no longer valid' violation appears after deleting the only tag[/-][+][$250] Expense - The 'Tag no longer valid' violation appears after deleting the only tag[/+]on Apr 20, 2026
Please re-state the problem that we are trying to solve in this issue.
After a user creates an expense with a tag and then deletes that tag from the workspace settings, the Tag no longer valid violation still appears in the report preview and expense details. It should not — when the workspace has no enabled tags anywhere, a tagOutOfPolicy violation referencing a now-deleted tag is stale and should not be displayed.
What is the root cause of that problem?
The frontend does have a guard for this case in the optimistic write path. getTagViolationsForSingleLevelTags computes hasEnabledTagsInList and uses it both to skip adding tagOutOfPolicy and to remove any existing one when no enabled tags remain:
But that guard only runs when pushTransactionViolationsOnyxData is invoked from a policy-side action (create/delete/enable tag), through getViolationsOnyxData:
After DELETE_POLICY_TAGS succeeds, the backend pushes the authoritative TRANSACTION_VIOLATIONS Onyx update via Pusher. That update is SET blindly into Onyx — the client never re-runs the !hasEnabledTagsInList filter on the incoming violations. The transaction still has tag = "Tag A" and the server-side evaluation re-attaches tagOutOfPolicy against the just-removed tag. When the user opens the report preview (step 7), hasViolation reads that stale violation directly from Onyx and renders Tag no longer valid:
So the frontend fix from commit 7bd2c235867 (align with !hasEnabledTags) covered the optimistic write, but the same invariant is not enforced on the read path for server-pushed violations. That is why the Category no longer valid analog needed its own display-side helper (getIsViolationFixed, currently only consumed by MoneyRequestConfirmationList) — the tag case needs the equivalent coverage in the report preview / expense details path.
What changes do you think we should make in order to solve the problem?
Make the violation readers resilient to stale tagOutOfPolicy (and missingTag) entries by filtering at read time, mirroring the invariants already used by getTagViolationsForSingleLevelTags. Concretely:
In src/libs/TransactionUtils/index.ts, introduce a small helper that, given the transaction, the transaction violations, and the policy tag lists for the transaction's policy, returns a filtered violations array with:
tagOutOfPolicy removed when either the referenced tag is empty, the tag is enabled in the policy tag list, or the policy has no enabled tags in any level; and
missingTag removed when the policy has no enabled tags in any level.
Wire that helper into hasViolation, hasNoticeTypeViolation, hasWarningTypeViolation, and getReportViolations/getTransactionViolations at the boundary where they read from Onyx. Because the helper needs policyTagLists, lift the existing callers to pass the already-available tag list (these call sites already receive policy and commonly have policyTagList nearby — e.g. MoneyRequestView, MoneyRequestReportPreview, and ReportActionItem).
Apply the same filter in useViolations before it groups violations by field, so the tag-field row on the expense detail page no longer emits Tag no longer valid once the underlying tag is gone:
Leave the optimistic write path and the existing getIsViolationFixed helper untouched — the change is strictly additive and does not widen the cases in which the violation is shown.
This guarantees that, regardless of whether the stale tagOutOfPolicy entry in Onyx came from an optimistic legacy state, an older backend response, or a Pusher race, the report preview and expense details will suppress it as long as the policy has no enabled tags or the tag exists and is enabled.
What alternative solutions did you explore? (Optional)
Extend deletePolicyTags to also push an optimistic TRANSACTION_VIOLATIONS SET that strips any existing tagOutOfPolicy for transactions whose tag is the one being deleted. This is narrower but fragile — it only covers the explicit delete path and does not help if a stale violation arrives later via Pusher, or if the same scenario is reached via setWorkspaceTagEnabled with all tags disabled.
Add the filtering only to useViolations. This fixes the tag-field row on the confirm/detail page but the RBR/badge on the report preview is computed via TransactionUtils.hasViolation and would still render the stale violation. Filtering at the TransactionUtils boundary fixes both surfaces in one place.
Please re-state the problem that we are trying to solve in this issue.
When a user creates an expense with a tag and then deletes the only tag from workspace settings, the Tag no longer valid violation continues to appear in the report preview and expense details. Because the workspace no longer has any enabled tags, a tagOutOfPolicy violation is meaningless — there is no valid tag the user could choose — yet it persists and blocks the report workflow.
What is the root cause of that problem?
pushTransactionViolationsOnyxData computes the correct violations using the optimistic tag state (where the deleted tag is marked enabled: false) and pushes the result into optimisticData. The optimistic violations correctly exclude tagOutOfPolicy because hasEnabledTagsInList is false after the tag is removed.
However, the function only pushes to optimisticData and failureData — it never pushes to successData. This means when the DeletePolicyTags API call succeeds and the server response arrives via Pusher, it sets TRANSACTION_VIOLATIONS with the server-computed violations (which still include tagOutOfPolicy) and there is no client-side successData entry to overwrite them with the correct filtered result.
The guard !hasEnabledTagsInList → remove tagOutOfPolicy already exists in getTagViolationsForSingleLevelTags:
// Remove 'missingTag' violation if tag is valid according to policy or there are no enabled tags
It fires correctly on the optimistic write, but that correct state is silently overwritten by the server response because successData for TRANSACTION_VIOLATIONS was never populated in pushTransactionViolationsOnyxData.
What changes do you think we should make in order to solve the problem?
Add the computed violations to successData inside pushTransactionViolationsOnyxData, alongside the existing optimisticData push. This ensures that after the server responds (and potentially re-attaches tagOutOfPolicy), Onyx immediately overwrites those violations with the same client-side filtered result.
1. Push computed violations into successData in pushTransactionViolationsOnyxData
This is a minimal, self-contained change: the same optimisticViolations object (already correctly computed with hasEnabledTagsInList = false) is reused for successData, so no additional computation or new helper is needed. When the server response arrives, Onyx applies successData after the server payload, replacing the stale tagOutOfPolicy with the filtered violations.
What alternative solutions did you explore? (Optional)
Filter at the read/display layer (hasViolation, useViolations, getTransactionViolations): This would suppress the violation at render time regardless of what's in Onyx. It works visually but leaves stale data in Onyx, meaning other consumers (RBR badge count, export, compliance checks) would still see the incorrect violation. Fixing at the write path is the correct layer.
Clear tagOutOfPolicy in deletePolicyTags successData for specific transactions: This would require identifying each affected transaction in the action and nulling out their violations individually. More verbose than reusing the already-computed optimisticViolations in pushTransactionViolationsOnyxData, and doesn't generalise to the setWorkspaceTagEnabled path.
⚠️@mukhrr Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
@mallenexpensify Oh I am about that PR, but didn't count this issue here when asked bounty raise, thinking this can be paid separately since this is different (but related) group of original issue PR fixed. happy with your decision here. thanks
@Julesssss 👀 above. It sounds like @mukhrr might be due additional compensation, I'm unsure of details/discussions though.
If it's a 'follow up', the standard amount for those is $125.
Activity
MelvinBot commentedon Apr 20, 2026
Proposal
What is the root cause of that problem?
The client-side violation engine in
ViolationsUtils.ts:85-89correctly guards against addingtagOutOfPolicywhen there are no enabled tags remaining:When the only tag is deleted,
deletePolicyTagsmarks the tag asenabled: falseoptimistically, and the violation computation correctly sees no enabled tags → no violation is added.However,
pushTransactionViolationsOnyxDataonly pushes optimistic violation data — there is nosuccessDataforTRANSACTION_VIOLATIONS(ReportUtils.ts:2179-2186). When the backend responds to theDeletePolicyTagsAPI call, itsonyxDataoverrides the correct optimistic violations. The backend likely computestagOutOfPolicywithout thehasEnabledTagsguard, so the violation reappears after the server response arrives.What changes do you think we should make in order to solve the problem?
There are two complementary approaches:
Primary fix (backend): The backend's violation computation for
DeletePolicyTagsshould check whether any enabled tags remain before addingtagOutOfPolicy. If all tags in the list are deleted/disabled, notagOutOfPolicyviolation should be added.Client-side hardening (recommended alongside): Add the violations to
successDatainpushTransactionViolationsOnyxDataso the correct client-side computation persists even after the API response is applied. This would mean the correct optimistic violations aren't silently overwritten by the backend.What alternative solutions did you explore? (Optional)
tagOutOfPolicywhen no enabled tags exist) — this would work but is a workaround that masks the backend issue.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 20, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @dmkt9 (
External)[-]Expense - The 'Tag no longer valid' violation appears after deleting the only tag[/-][+][$250] Expense - The 'Tag no longer valid' violation appears after deleting the only tag[/+]melvin-bot commentedon Apr 20, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022046250585524521937
wildan-m commentedon Apr 20, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After a user creates an expense with a tag and then deletes that tag from the workspace settings, the
Tag no longer validviolation still appears in the report preview and expense details. It should not — when the workspace has no enabled tags anywhere, atagOutOfPolicyviolation referencing a now-deleted tag is stale and should not be displayed.What is the root cause of that problem?
The frontend does have a guard for this case in the optimistic write path.
getTagViolationsForSingleLevelTagscomputeshasEnabledTagsInListand uses it both to skip addingtagOutOfPolicyand to remove any existing one when no enabled tags remain:App/src/libs/Violations/ViolationsUtils.ts
Lines 73 to 112 in 4a8ff9a
But that guard only runs when
pushTransactionViolationsOnyxDatais invoked from a policy-side action (create/delete/enable tag), throughgetViolationsOnyxData:App/src/libs/ReportUtils.ts
Lines 2165 to 2188 in 4a8ff9a
After
DELETE_POLICY_TAGSsucceeds, the backend pushes the authoritativeTRANSACTION_VIOLATIONSOnyx update via Pusher. That update is SET blindly into Onyx — the client never re-runs the!hasEnabledTagsInListfilter on the incoming violations. The transaction still hastag = "Tag A"and the server-side evaluation re-attachestagOutOfPolicyagainst the just-removed tag. When the user opens the report preview (step 7),hasViolationreads that stale violation directly from Onyx and rendersTag no longer valid:App/src/libs/TransactionUtils/index.ts
Lines 1959 to 1979 in 4a8ff9a
So the frontend fix from commit
7bd2c235867(align with!hasEnabledTags) covered the optimistic write, but the same invariant is not enforced on the read path for server-pushed violations. That is why theCategory no longer validanalog needed its own display-side helper (getIsViolationFixed, currently only consumed byMoneyRequestConfirmationList) — the tag case needs the equivalent coverage in the report preview / expense details path.What changes do you think we should make in order to solve the problem?
Make the violation readers resilient to stale
tagOutOfPolicy(andmissingTag) entries by filtering at read time, mirroring the invariants already used bygetTagViolationsForSingleLevelTags. Concretely:src/libs/TransactionUtils/index.ts, introduce a small helper that, given the transaction, the transaction violations, and the policy tag lists for the transaction's policy, returns a filtered violations array with:tagOutOfPolicyremoved when either the referenced tag is empty, the tag is enabled in the policy tag list, or the policy has no enabled tags in any level; andmissingTagremoved when the policy has no enabled tags in any level.hasViolation,hasNoticeTypeViolation,hasWarningTypeViolation, andgetReportViolations/getTransactionViolationsat the boundary where they read from Onyx. Because the helper needspolicyTagLists, lift the existing callers to pass the already-available tag list (these call sites already receivepolicyand commonly havepolicyTagListnearby — e.g.MoneyRequestView,MoneyRequestReportPreview, andReportActionItem).useViolationsbefore it groups violations by field, so the tag-field row on the expense detail page no longer emitsTag no longer validonce the underlying tag is gone:App/src/hooks/useViolations.ts
Lines 90 to 140 in 4a8ff9a
getIsViolationFixedhelper untouched — the change is strictly additive and does not widen the cases in which the violation is shown.This guarantees that, regardless of whether the stale
tagOutOfPolicyentry in Onyx came from an optimistic legacy state, an older backend response, or a Pusher race, the report preview and expense details will suppress it as long as the policy has no enabled tags or the tag exists and is enabled.Compare branch: https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/88338-stale-tag-violation-after-tag-delete?expand=1
What alternative solutions did you explore? (Optional)
deletePolicyTagsto also push an optimisticTRANSACTION_VIOLATIONSSET that strips any existingtagOutOfPolicyfor transactions whose tag is the one being deleted. This is narrower but fragile — it only covers the explicit delete path and does not help if a stale violation arrives later via Pusher, or if the same scenario is reached viasetWorkspaceTagEnabledwith all tags disabled.useViolations. This fixes the tag-field row on the confirm/detail page but theRBR/badge on the report preview is computed viaTransactionUtils.hasViolationand would still render the stale violation. Filtering at theTransactionUtilsboundary fixes both surfaces in one place.mukhrr commentedon Apr 20, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user creates an expense with a tag and then deletes the only tag from workspace settings, the
Tag no longer validviolation continues to appear in the report preview and expense details. Because the workspace no longer has any enabled tags, atagOutOfPolicyviolation is meaningless — there is no valid tag the user could choose — yet it persists and blocks the report workflow.What is the root cause of that problem?
pushTransactionViolationsOnyxDatacomputes the correct violations using the optimistic tag state (where the deleted tag is markedenabled: false) and pushes the result intooptimisticData. The optimistic violations correctly excludetagOutOfPolicybecausehasEnabledTagsInListisfalseafter the tag is removed.App/src/libs/ReportUtils.ts
Lines 2179 to 2186 in 4a8ff9a
However, the function only pushes to
optimisticDataandfailureData— it never pushes tosuccessData. This means when theDeletePolicyTagsAPI call succeeds and the server response arrives via Pusher, it setsTRANSACTION_VIOLATIONSwith the server-computed violations (which still includetagOutOfPolicy) and there is no client-sidesuccessDataentry to overwrite them with the correct filtered result.The guard
!hasEnabledTagsInList → remove tagOutOfPolicyalready exists ingetTagViolationsForSingleLevelTags:App/src/libs/Violations/ViolationsUtils.ts
Lines 97 to 100 in 4a8ff9a
It fires correctly on the optimistic write, but that correct state is silently overwritten by the server response because
successDataforTRANSACTION_VIOLATIONSwas never populated inpushTransactionViolationsOnyxData.What changes do you think we should make in order to solve the problem?
Add the computed violations to
successDatainsidepushTransactionViolationsOnyxData, alongside the existingoptimisticDatapush. This ensures that after the server responds (and potentially re-attachestagOutOfPolicy), Onyx immediately overwrites those violations with the same client-side filtered result.1. Push computed violations into
successDatainpushTransactionViolationsOnyxDataApp/src/libs/ReportUtils.ts
Lines 2179 to 2186 in 4a8ff9a
if (!isEmptyObject(optimisticViolations)) { onyxData.optimisticData?.push(optimisticViolations); + onyxData.successData?.push(optimisticViolations); onyxData.failureData?.push({ onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, value: existingViolations ?? null, }); }This is a minimal, self-contained change: the same
optimisticViolationsobject (already correctly computed withhasEnabledTagsInList = false) is reused forsuccessData, so no additional computation or new helper is needed. When the server response arrives, Onyx appliessuccessDataafter the server payload, replacing the staletagOutOfPolicywith the filtered violations.What alternative solutions did you explore? (Optional)
hasViolation,useViolations,getTransactionViolations): This would suppress the violation at render time regardless of what's in Onyx. It works visually but leaves stale data in Onyx, meaning other consumers (RBR badge count, export, compliance checks) would still see the incorrect violation. Fixing at the write path is the correct layer.tagOutOfPolicyindeletePolicyTagssuccessData for specific transactions: This would require identifying each affected transaction in the action and nulling out their violations individually. More verbose than reusing the already-computedoptimisticViolationsinpushTransactionViolationsOnyxData, and doesn't generalise to thesetWorkspaceTagEnabledpath.github-actions commentedon Apr 20, 2026
wildan-m commentedon Apr 20, 2026
Proposal updated — added compare branch with implementation.
ProjectNOVACo commentedon Apr 20, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
ProjectNOVACo commentedon Apr 20, 2026
📋 Contributor details
55 remaining items
mukhrr commentedon Jun 19, 2026
Not regression. More: https://expensify.slack.com/archives/C01GTK53T8Q/p1781794529544019
melvin-bot commentedon Jun 29, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)mallenexpensify commentedon Jun 29, 2026
What is due here and when @mukhrr ? Link to PRs cuz I found linked to here was already paid here
mukhrr commentedon Jun 29, 2026
@mallenexpensify Oh I am about that PR, but didn't count this issue here when asked bounty raise, thinking this can be paid separately since this is different (but related) group of original issue PR fixed. happy with your decision here. thanks
mallenexpensify commentedon Jun 29, 2026
@Julesssss 👀 above. It sounds like @mukhrr might be due additional compensation, I'm unsure of details/discussions though.
If it's a 'follow up', the standard amount for those is $125.
Julesssss commentedon Jun 29, 2026
Yep and I think $125 correct. This was raised as follow up and not a blocker.
mallenexpensify commentedon Jul 2, 2026
Payment Summary
Contributor+: @mukhrr due $125 via NewDot
thx
flaviadefaria commentedon Jul 7, 2026
Approved: @mukhrr due $125 via NewDot