Repository navigation
fix(gmail): reuse labels created earlier in the same modify request - #50675
Conversation
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]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
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.
What Changed
labelIdsinsrc/main/google/google-gmail-write.tsloads 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.existinglist, 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
idsordering 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
mainit 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.tsdrivesmodifyGmailthrough a fakeGoogleApi. 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 carryingaddLabelIds: ['Label_1', 'Label_1', 'Label_existing'].I reverted only
google-gmail-write.tstomain, 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
Notes
Original fix by @Afloat16 in #50601 (authorship preserved via
Co-authored-by). The test was rewritten here as a co-locatedgoogle-gmail-write.test.tswith 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)