Skip to content

[$250] Expense - The 'Tag no longer valid' violation appears after deleting the only tag #88338

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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

  1. Navigate to https://staging.new.expensify.com/
  2. Go to workspace settings > Tags
  3. Add "Tag A"
  4. Go to the workspace chat
  5. Create a manual expense using Tag A
  6. Go back to workspace settings > Tags and delete "Tag A"
  7. Go back to the workspace chat
  8. Click in the report preview
  9. Click on the back arrow to go back to the workspace chat

Expected Result:

The 'Tag no longer valid' violation is not shown in the report preview or expense details.

Actual Result:

The 'Tag no longer valid' violation appears in the report preview and expense details.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Video.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022046250585524521937
  • Upwork Job ID: 2046250585524521937
  • Last Price Increase: 2026-04-27
Issue OwnerCurrent Issue Owner: @mukhrr

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Apr 20, 2026
  2. MelvinBot commented on Apr 20, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    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.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Apr 20, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Apr 20, 2026
  5. melvin-bot commented on Apr 20, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @dmkt9 (External)

  6. 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
  7. melvin-bot commented on Apr 20, 2026

    @melvin-bot
  8. wildan-m commented on Apr 20, 2026

    @wildan-m
    Contributor

    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 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:

    function getTagViolationsForSingleLevelTags(
    updatedTransaction: Transaction,
    transactionViolations: TransactionViolation[],
    policyRequiresTags: boolean,
    policyTagList: PolicyTagLists,
    ): TransactionViolation[] {
    const policyTagKeys = Object.keys(policyTagList);
    const policyTagListName = policyTagKeys.at(0) ?? '';
    const policyTags = policyTagList[policyTagListName]?.tags;
    const hasTagOutOfPolicyViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY);
    const hasMissingTagViolation = transactionViolations.some((violation) => violation.name === CONST.VIOLATIONS.MISSING_TAG);
    const isTagInPolicy = policyTags ? !!policyTags[updatedTransaction.tag ?? '']?.enabled : false;
    const hasEnabledTagsInList = hasEnabledTags(policyTags);
    let newTransactionViolations = [...transactionViolations];
    // Add 'tagOutOfPolicy' violation if tag is not in policy and there are enabled tags
    if (!hasTagOutOfPolicyViolation && updatedTransaction.tag && !isTagInPolicy && hasEnabledTagsInList) {
    const tagName = policyTagList[policyTagListName]?.name;
    const tagNameToShow = isDefaultTagName(tagName) ? undefined : tagName;
    newTransactionViolations.push({name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY, type: CONST.VIOLATION_TYPES.VIOLATION, data: {tagName: tagNameToShow}, showInReview: true});
    }
    // Remove 'tagOutOfPolicy' violation if tag is empty, in policy, or there are no enabled tags
    if (hasTagOutOfPolicyViolation && (!updatedTransaction.tag || isTagInPolicy || !hasEnabledTagsInList)) {
    newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
    }
    // Remove 'missingTag' violation if tag is valid according to policy or there are no enabled tags
    if (hasMissingTagViolation && (isTagInPolicy || !hasEnabledTagsInList)) {
    newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.MISSING_TAG});
    }
    // Add 'missingTag violation' if tag is required, not set, and there are enabled tags
    if (!hasMissingTagViolation && !updatedTransaction.tag && policyRequiresTags && hasEnabledTagsInList) {
    const tagName = policyTagList[policyTagListName]?.name;
    const tagNameToShow = isDefaultTagName(tagName) ? undefined : tagName;
    newTransactionViolations.push({name: CONST.VIOLATIONS.MISSING_TAG, type: CONST.VIOLATION_TYPES.VIOLATION, showInReview: true, data: {tagName: tagNameToShow}});
    }
    return newTransactionViolations;
    }

    But that guard only runs when pushTransactionViolationsOnyxData is invoked from a policy-side action (create/delete/enable tag), through getViolationsOnyxData:

    App/src/libs/ReportUtils.ts

    Lines 2165 to 2188 in 4a8ff9a

    // Iterate through all policy reports to find transactions that need optimistic violations
    for (const {transactions, violations} of nonInvoiceReportTransactionsAndViolations) {
    for (const transaction of Object.values(transactions)) {
    const existingViolations = violations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`];
    const optimisticViolations = ViolationsUtils.getViolationsOnyxData(
    transaction,
    existingViolations ?? [],
    optimisticPolicy,
    optimisticTagLists,
    optimisticCategories,
    hasDependentTags,
    false,
    );
    if (!isEmptyObject(optimisticViolations)) {
    onyxData.optimisticData?.push(optimisticViolations);
    onyxData.failureData?.push({
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
    value: existingViolations ?? null,
    });
    }
    }
    }

    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:

    function hasViolation(
    transaction: Transaction | undefined,
    transactionViolations: TransactionViolation[] | OnyxCollection<TransactionViolation[]>,
    currentUserEmail: string,
    currentUserAccountID: number,
    iouReport: OnyxEntry<Report>,
    policy: OnyxEntry<Policy>,
    showInReview?: boolean,
    ): boolean {
    if (!doesTransactionSupportViolations(transaction)) {
    return false;
    }
    const violations = Array.isArray(transactionViolations) ? transactionViolations : transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transaction.transactionID];
    return !!violations?.some(
    (violation) =>
    violation.type === CONST.VIOLATION_TYPES.VIOLATION &&
    (showInReview === undefined || showInReview === (violation.showInReview ?? false)) &&
    !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, iouReport, policy),
    );
    }

    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:

    1. 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.
    2. 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).
    3. 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:

    return violationGroups ?? new Map();
    }, [violations, shouldShowOnlyViolations]);
    const getViolationsForField = useCallback(
    (field: ViolationField, data?: TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string) => {
    const currentViolations = violationsByField.get(field) ?? [];
    const firstViolation = currentViolations.at(0);
    // someTagLevelsRequired has special logic because data.errorIndexes is a bit unique in how it denotes the tag list that has the violation
    // tagListIndex can be 0 so we compare with undefined
    if (firstViolation?.name === CONST.VIOLATIONS.SOME_TAG_LEVELS_REQUIRED && data?.tagListIndex !== undefined && Array.isArray(firstViolation?.data?.errorIndexes)) {
    return currentViolations
    .filter((violation) => violation.data?.errorIndexes?.includes(data?.tagListIndex ?? -1))
    .map((violation) => ({
    ...violation,
    data: {
    ...violation.data,
    tagName: data?.tagListName,
    },
    }));
    }
    // missingTag has special logic for policies with dependent tags, because only one violation is returned for all tags
    // when no tags are present, so the tag name isn't set in the violation data. That's why we add it here
    if (policyHasDependentTags && firstViolation?.name === CONST.VIOLATIONS.MISSING_TAG && data?.tagListName) {
    return [
    {
    ...firstViolation,
    data: {
    ...firstViolation.data,
    tagName: data?.tagListName,
    },
    },
    ];
    }
    // tagOutOfPolicy has special logic because we have to account for multi-level tags and use tagName to find the right tag to put the violation on
    if (firstViolation?.name === CONST.VIOLATIONS.TAG_OUT_OF_POLICY && data?.tagListName !== undefined && firstViolation?.data?.tagName) {
    return currentViolations.filter((violation) => violation.data?.tagName === data?.tagListName);
    }
    // allTagLevelsRequired has special logic because it is returned when one but not all the tags are set,
    // so we need to return the violation for the tag fields without a tag set
    if (firstViolation?.name === CONST.VIOLATIONS.ALL_TAG_LEVELS_REQUIRED && tagValue) {
    return currentViolations.filter((violation) => violation.data?.tagName === data?.tagListName);
    }
    return currentViolations;
    },
    [violationsByField],
    );

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

    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)

    • 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.
  9. mukhrr commented on Apr 20, 2026

    @mukhrr
    Contributor

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

    App/src/libs/ReportUtils.ts

    Lines 2179 to 2186 in 4a8ff9a

    if (!isEmptyObject(optimisticViolations)) {
    onyxData.optimisticData?.push(optimisticViolations);
    onyxData.failureData?.push({
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
    value: existingViolations ?? null,
    });
    }

    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:

    newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.TAG_OUT_OF_POLICY});
    }
    // 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

    App/src/libs/ReportUtils.ts

    Lines 2179 to 2186 in 4a8ff9a

    if (!isEmptyObject(optimisticViolations)) {
    onyxData.optimisticData?.push(optimisticViolations);
    onyxData.failureData?.push({
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
    value: existingViolations ?? null,
    });
    }

                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 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.
  10. github-actions commented on Apr 20, 2026

    @github-actions
    Contributor

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

  11. wildan-m commented on Apr 20, 2026

    @wildan-m
    Contributor

    Proposal updated — added compare branch with implementation.

  12. ProjectNOVACo commented on Apr 20, 2026

    @ProjectNOVACo

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  13. ProjectNOVACo commented on Apr 20, 2026

    @ProjectNOVACo

    📋 Contributor details

  14. 55 remaining items

  15. mukhrr commented on Jun 19, 2026

    @mukhrr
    Contributor

    Deploy Blocker #93945 was identified to be related to the PR #86932 that attempted to fix this issue.

    Not regression. More: https://expensify.slack.com/archives/C01GTK53T8Q/p1781794529544019

  16. melvin-bot commented on Jun 29, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. mallenexpensify commented on Jun 29, 2026

    @mallenexpensify
    Contributor

    What is due here and when @mukhrr ? Link to PRs cuz I found linked to here was already paid here

  18. mukhrr commented on Jun 29, 2026

    @mukhrr
    Contributor

    @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

  19. mallenexpensify commented on Jun 29, 2026

    @mallenexpensify
    Contributor

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

  20. Julesssss commented on Jun 29, 2026

    @Julesssss
    Contributor

    Yep and I think $125 correct. This was raised as follow up and not a blocker.

  21. mallenexpensify commented on Jul 2, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @mukhrr due $125 via NewDot

    thx

  22. flaviadefaria commented on Jul 7, 2026

    @flaviadefaria
    Contributor

    Approved: @mukhrr due $125 via NewDot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions