Skip to content

fix(gmail): prevent duplicate watch renewals during stalls - #108974

Merged
hxy91819 merged 1 commit into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-gmail-renewal-overlap
Jul 19, 2026
Merged

hxy91819 merged 1 commit into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-gmail-renewal-overlap

Conversation

@zhangguiping-xydt

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where Gmail watch renewal could launch duplicate gog gmail watch start commands when a previous periodic renewal was still stalled. This affects both the gateway-managed watcher and openclaw webhooks gmail run when the configured renewal interval is shorter than the command's two-minute timeout.

Why This Change Was Made

Each Gmail watcher lifecycle now admits only one periodic renewal at a time. Later timer ticks are coalesced until the active command settles, while existing retry timing, failure logging, configuration, and process lifecycle behavior remain unchanged.

User Impact

Operators no longer get overlapping Gmail watch registration commands during slow or stalled renewals. Normal renewals continue on the next interval after the active command settles.

Evidence

  • Focused tests: src/hooks/gmail-watcher.test.ts and src/hooks/gmail-ops.test.ts — 2 files, 12 tests passed.
  • Targeted formatting and lint checks passed for the four changed files.
  • Production-lifecycle proof used the real startGmailWatcher scheduler and actual child processes. With renewEveryMinutes: 1, the first periodic renewal was held for 70 seconds; after 135 seconds exactly two watch-start calls were observed: the initial registration and one renewal. The minute-two tick did not launch a third command.
  • An accelerated repeat of the same child-process scenario was captured by the bounded proof runner and produced the same two-call result.
  • Fresh open-PR recall found Gmail watcher PRs for delivery mode, OAuth failure handling, secret argv handling, and bind diagnostics, but no PR implementing this single-flight renewal invariant.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed. Reviewed July 19, 2026, 7:09 AM ET / 11:09 UTC.

Summary
The branch prevents overlapping Gmail watch-renewal commands in both the gateway watcher and foreground Gmail webhook service while a previous renewal remains stalled.

PR surface: Source +40, Tests +100. Total +140 across 4 files.

Reproducibility: yes. from source: with a renewal interval shorter than an unresolved watch-start command, the former interval callbacks could each start another renewal; the new promise guard directly covers that path.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • [P2] No repair lane is appropriate: the exact head has no actionable defect, sufficient real behavior proof, and an existing member-sponsored automerge path.

Security
Cleared: The four-file TypeScript and test-only change does not add dependencies, secret handling, permissions, downloads, or supply-chain execution paths.

Review details

Best possible solution:

Merge the reviewed exact head through the existing automerge gates so both Gmail watcher lifecycles retain one active periodic renewal at a time.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: with a renewal interval shorter than an unresolved watch-start command, the former interval callbacks could each start another renewal; the new promise guard directly covers that path.

Is this the best way to solve the issue?

Yes. Lifecycle-local single-flight guards at the two scheduler entry points prevent overlap without adding configuration or changing successful renewal scheduling.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3b84a55d9943.

Label changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 🚀 automerge armed: Current PR status no longer selects a status label.

Label justifications:

  • P2: The patch addresses a bounded Gmail watcher reliability bug that can create duplicate external watch registrations during stalls.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies an after-fix production-lifecycle child-process scenario showing a stalled one-minute renewal does not produce a third watch-start command; the reported result directly matches the changed behavior.
Evidence reviewed

PR surface:

Source +40, Tests +100. Total +140 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 54 14 +40
Tests 2 102 2 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 156 16 +140

What I checked:

  • Gateway watcher single-flight and teardown: The branch records the active periodic renewal, skips later interval ticks while it is unsettled, and aborts/awaits it before replacing or stopping the watcher so old work cannot suppress a new watcher. (src/hooks/gmail-watcher.ts:179, 34a3001388bb)
  • Foreground webhook service single-flight: The foreground Gmail service now holds the promise for the active scheduled renewal and returns on subsequent ticks until that promise settles, preserving existing error logging. (src/hooks/gmail-ops.ts:321, 34a3001388bb)
  • Focused regression coverage: The PR adds stalled-renewal coverage for both watcher entry points, including replacement-watcher behavior after a stopped renewal. (src/hooks/gmail-watcher.test.ts:283, 34a3001388bb)
  • Real behavior proof and sponsor signal: The PR body reports an actual child-process scheduler scenario where a 70-second renewal at a one-minute interval yielded only initial registration plus one renewal after 135 seconds; a repository member explicitly enabled and repeatedly sponsored exact-head automerge. (34a3001388bb)
  • Prior exact-head review continuity: The latest completed ClawSweeper review of this same SHA reported no findings, sufficient proof, and no repair lane; the supplied review history contains no unresolved prior finding to re-raise. (34a3001388bb)

Likely related people:

  • hxy91819: A repository member explicitly requested automerge for the exact current head and instructed the production exact-head merge path. (role: review sponsor; confidence: high; files: src/hooks/gmail-watcher.ts, src/hooks/gmail-ops.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (6 earlier review cycles)
  • reviewed 2026-07-16T12:02:28.997Z sha 34a3001 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T21:31:21.615Z sha 34a3001 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T22:16:20.580Z sha 34a3001 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-19T00:00:17.749Z sha 34a3001 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-19T01:01:54.388Z sha 34a3001 :: passed. :: none
  • reviewed 2026-07-19T10:25:32.369Z sha 34a3001 :: passed. :: none

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper automerge is enabled.

  • Head: 34a3001388bb
  • Label: clawsweeper:automerge (pause labels cleared)
  • Action: exact-head review queued (workflow sweep.yml, event repository_dispatch).
  • Flow: review this head, repair/rebase only if needed, then re-review the exact repaired head before merge.

Draft PRs stay fix-only until GitHub marks them ready for review. Pause with /clawsweeper stop.

Automerge progress:

  • 2026-07-19 10:22:24 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:22:16 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:22:07 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 11:13:28 UTC review passed 34a3001388bb (structured ClawSweeper verdict: pass (sha=34a3001388bb99fb4a041a73aad98631c4557...)
  • 2026-07-19 00:56:37 UTC review result reused 34a3001388bb (complete)
  • 2026-07-19 07:44:56 UTC review result reused 34a3001388bb (complete)
  • 2026-07-19 08:39:40 UTC review result reused 34a3001388bb (complete)
  • 2026-07-19 09:22:36 UTC review result reused 34a3001388bb (complete)
  • 2026-07-19 10:22:33 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:22:50 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:22:59 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:23:07 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 10:23:16 UTC review queued 34a3001388bb (queued)
  • 2026-07-19 06:13:21 UTC review result reused 34a3001388bb (complete)
  • 2026-07-19 12:52:07 UTC review queued 34a3001388bb (queued)

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label Jul 17, 2026
@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

Retry the exact current head 34a3001 after ClawSweeper main merged openclaw/clawsweeper#670, #671, and #672. Keep the existing fail-closed validation boundaries and use the production automerge path.

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

Retry the exact current head 34a3001 after openclaw/clawsweeper#679 merged. Use the production direct-behind path, preserve exact-head/check/review gates, and do not rewrite the contributor branch solely for base drift.

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper re-review

Refresh the exact-head verdict after openclaw/clawsweeper#679 landed. Automerge is already enabled; preserve the current head and let the trusted exact-head verdict resume the production direct-behind path.

@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane. clawsweeper:human-review Needs maintainer review before ClawSweeper can continue and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper is pausing this repair loop for human review.

Source: clawsweeper[bot]
Reason: - [P2] No repair lane is needed: the patch has no actionable finding, carries sufficient real behavior proof, and has an explicit member-sponsored automerge path for the exact head.; Cleared: The patch only adds local promise and abort-controller lifecycle coordination; it adds no dependency, credential, command-construction, permission, or supply-chain surface. (sha=34a3001388bb99fb4a041a73aad98631c4557634)

Why human review is needed:
This item has security-sensitive risk. ClawSweeper is pausing instead of making an autonomous change that could affect trust, credentials, permissions, or exposure.

What the maintainer can do as a next step:
If the maintainer accepts the current risk and wants ClawSweeper to continue merge gates, comment @clawsweeper approve. If the security-sensitive detail still needs changes, describe the safe path or push the fix, then comment @clawsweeper automerge. If the risk should not be automated, keep the PR paused for manual review or comment @clawsweeper stop.

I added clawsweeper:human-review and left the final call with a maintainer.

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

Resume the exact current head after openclaw/clawsweeper#680 landed.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. clawsweeper:human-review Needs maintainer review before ClawSweeper can continue and removed clawsweeper:human-review Needs maintainer review before ClawSweeper can continue rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:merge-ready ClawSweeper found the PR merge-ready but a human gate is still closed and removed clawsweeper:merge-ready ClawSweeper found the PR merge-ready but a human gate is still closed labels Jul 19, 2026
@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

Resume the exact current head after openclaw/clawsweeper#691 merged. Reuse and re-dispatch the completed exact-head pass verdict; keep all production merge gates fail-closed.

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

1 similar comment
@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

@clawsweeper clawsweeper Bot added clawsweeper:merge-ready ClawSweeper found the PR merge-ready but a human gate is still closed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed clawsweeper:merge-ready ClawSweeper found the PR merge-ready but a human gate is still closed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane. labels Jul 19, 2026
@hxy91819

Copy link
Copy Markdown
Member

@clawsweeper automerge

Resume the exact current head after openclaw/clawsweeper#702 merged. If the protected merge gate reports the head behind base, route it through the existing cloud rebase repair lane; preserve all exact-head review, CAS, immutable-ledger, and merge safety gates.

@clawsweeper clawsweeper Bot removed the clawsweeper:merge-ready ClawSweeper found the PR merge-ready but a human gate is still closed label Jul 19, 2026
@hxy91819
hxy91819 merged commit b4a206f into openclaw:main Jul 19, 2026
376 of 400 checks passed
@hxy91819

Copy link
Copy Markdown
Member

Merged via squash.

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

Labels

clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants