Skip to content

fix(gmail): reuse labels created earlier in the same modify request - #50675

Merged
nwparker merged 1 commit into
mainfrom
bugbash/pr-50601
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/pr-50601

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you ask Orca to add the same new Gmail label twice in one action (for example "Project" and " project "), it now creates that label once and uses it for both mentions. Before, it tried to create it a second time, Gmail said "that label already exists", and the whole action failed.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

What Changed

  • Before: labelIds in src/main/google/google-gmail-write.ts loads the account's labels once, then resolves each requested name against that list. When a name was missing it created the label but never added it to the list, so a later mention of the same name (matched case-insensitively after trimming) tried to create it again. Gmail answered with a name-conflict error. That aborted the message/thread modify and left the new label behind with nothing applied.
  • After: each newly created label is pushed onto the same existing list, so later mentions in the same request resolve to its id. The label is created once and applied, along with any existing labels in the request.

Why

This is the smallest fix that keeps the existing matching rules (trim, case-insensitive, user labels only). It adds no extra API calls; it actually removes the failing duplicate POST. Deduplicating the input names first would have changed the returned ids ordering and the response shape, and this fix avoids that.

Linked Issue

Fixes #50600

Visual Proof

N/A: main-process Gmail tool behavior with no UI change. The before/after is shown by the regression test: on main it fails with the 409 conflict, and with the fix it passes with a single label create.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • New src/main/google/google-gmail-write.test.ts drives modifyGmail through a fake GoogleApi. The fake rejects a second label whose name matches case-insensitively, the same way Gmail does. The test asks to add ['Project', ' project ', 'Existing'] and checks for exactly one label POST, created: ['Project'], and the final modify call carrying addLabelIds: ['Label_1', 'Label_1', 'Label_existing'].

  • I reverted only google-gmail-write.ts to main, and the test failed. I restored the fix, and it passed.

  • Passed: oxlint, oxfmt, the anti-slop oxlint, the native-plugin oxlint, ast-grep, and check-changed-code-quality (0 findings).

  • Platform: macOS (unit level; the code has no platform-specific paths).

Performance

None, because this runs only when an agent tool modifies Gmail labels, and that call is bound by network time. The change adds one array push per newly created label and removes a duplicate network POST. In a microbenchmark with a fake API (old vs new, ms per call), the typical case (50 labels, 3 names) measured 0.011/0.006 old vs 0.009/0.008 new. The adversarial case (5000 labels, 200 new names) measured 8.97/8.62 old vs 10.53/7.35 new. Both are within noise.

Risk

Level: Low

This only affects label resolution within a single Gmail modify request. Existing-label matching and the response shape are unchanged. A plain revert backs it out.

Review

Reviewed the caller (modifyGmail) and the label matching rules. The change adds no new endpoints, IPC, or remote protocol fields.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @Afloat16 in #50601 (authorship preserved via Co-authored-by). The test was rewritten here as a co-located google-gmail-write.test.ts with an inline fake, replacing the original separate HTTP fixture file.

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

When one modify request named a new label more than once (for example
"Project" and " project "), labelIds created it on the first mention but
never added it to the lookup list, so the second mention tried to create
it again. Gmail rejected that as a name conflict, which aborted the
message/thread modification after leaving the new label behind.

Push each newly created label onto the same list used to match existing
labels so later mentions resolve to its id.

Fixes #50600

Co-authored-by: Afloat <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

After creating a Gmail label, labelIds adds it to the in-memory list of existing labels. Later matching names in the same request reuse that label. A new test checks label creation and the labels applied in the message update.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 466f5

This fixes a Gmail label modification that failed when the same new label was requested more than once in a single call. The change is small and tested, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: labels created earlier in the same modify request are now reused. It is specific and matches the summary, objectives, and code change. It uses the conventional fix(sco…
Description check Passed The description follows the repository template. It has ELI5, What Changed, Why, a linked issue (Fixes #50600), Visual Proof marked N/A with a reason, Testing, Performance with a one-line reason, Risk…
Linked Issues check Passed Linked issue #50600 requires that a modifyGmail call with repeated equivalent new label names (for example ['Project', ' Project ', 'Existing']) create the label once and apply it without a second cre…
Out of Scope Changes check Passed The whole-PR summary lists two changed files. src/main/google/google-gmail-write.ts adds one line (existing.push(made)) inside labelIds, which is the fix for #50600. src/main/google/google-gmail-w…
Full details: Title check

Explanation

The title names the main change: labels created earlier in the same modify request are now reused. It is specific and matches the summary, objectives, and code change. It uses the conventional fix(scope) prefix, which is acceptable.

Full details: Description check

Explanation

The description follows the repository template. It has ELI5, What Changed, Why, a linked issue (Fixes #50600), Visual Proof marked N/A with a reason, Testing, Performance with a one-line reason, Risk with level and rollback, AI Disclosure, Review, and Notes. The Testing section gives concrete steps. Some template items remain open: the Risk section does not name the riskiest part explicitly, and the final checklist item for pnpm lint, typecheck, test, and build is unchecked. The Notes section gives CI coverage as a possibility. These are minor gaps and do not make the description largely incomplete.

Full details: Linked Issues check

Explanation

Linked issue #50600 requires that a modifyGmail call with repeated equivalent new label names (for example ['Project', ' Project ', 'Existing']) create the label once and apply it without a second creation attempt. At the reviewed head, src/main/google/google-gmail-write.ts labelIds pushes each made label into the existing lookup list (existing.push(made)) right after created.push(made.name). A later name is trimmed, lowercased, and matched against existing before any create call, so it resolves to the same id and skips the POST. The existing found logic and the trim and case-insensitive matching are unchanged. The author reports a regression test in src/main/google/google-gmail-write.test.ts that asserts one label POST, created: ['Project'], and addLabelIds: ['Label_1', 'Label_1', 'Label_existing']. I could not read the test file because the changed blobs were unavailable, so the test result rests on the PR description and summary, not on direct inspection. The issue's coding requirement is met by the source change at head.

Full details: Out of Scope Changes check

Explanation

The whole-PR summary lists two changed files. src/main/google/google-gmail-write.ts adds one line (existing.push(made)) inside labelIds, which is the fix for #50600. src/main/google/google-gmail-write.test.ts adds a Vitest regression test for that same path. The response shape, the public signatures, and the matching rules are unchanged per the summary and the head source. No unrelated change was identified. The diff itself could not be read, so this verdict relies on the summary for the absence of other hunks.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c242d79-31df-4996-a8b3-b4fc2c2080cd
Commits

Reviewing files that changed from the base of the PR and between 767b930 and 466f502.

Files selected for processing: 2

  • src/main/google/google-gmail-write.test.ts
  • src/main/google/google-gmail-write.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit c31a942 into main Nov 27, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/pr-50601 branch November 27, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Repeated new labels make one Gmail modify operation fail

1 participant