Skip to content

fix(hooks): kill gog process tree on gmail-watcher shutdown - #112452

Merged
vincentkoc merged 5 commits into
openclaw:mainfrom
NarahariRaghava:fix/gmail-watcher-kill-process-tree
Jul 29, 2026
Merged

vincentkoc merged 5 commits into
openclaw:mainfrom
NarahariRaghava:fix/gmail-watcher-kill-process-tree

Conversation

@NarahariRaghava

@NarahariRaghava NarahariRaghava commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

gog gmail watch serve can spawn child processes (e.g. credential helpers).
stopGmailWatcher previously sent SIGTERM only to the direct child via
proc.kill(), leaving any descendants orphaned on shutdown.

Why This Change Was Made

src/process/kill-tree.ts already provides killProcessTree, which sends
SIGTERM to the entire process group on Unix (process.kill(-pid, ...)) and
uses taskkill /T on Windows, then escalates to SIGKILL after a grace period.
The fix wires this into the gmail-watcher shutdown path.

Two changes are required together:

  • Spawn gog with detached: process.platform !== "win32" so it gets its own
    process group on Unix otherwise the group signal would reach the parent
    OpenClaw process too.
  • Replace the manual SIGTERM → SIGKILL timer in settleProcess with a single
    killProcessTree call. A proc.kill("SIGTERM") fallback is kept for the
    edge case where spawn fails before a pid is assigned.

User Impact

Gmail hook users who see stale gog credential-helper processes surviving after
OpenClaw restarts will have those descendants cleaned up correctly on shutdown.

Evidence

Exact head: b30a81ff4385accd8f3f3060e1b18726b100e18d

  • 18 focused Gmail watcher unit tests passed.
  • The opt-in integration test passed against a real detached process tree and descendant.
  • Targeted oxlint, oxfmt, and git diff --check passed.
  • Fresh post-rebase autoreview found no actionable issues at 0.94 confidence.

Process-group mechanism proof - the screenshot below reproduces the
direct-child vs. process-group termination difference using the same Node.js
spawn/process.kill(-pid) primitives that spawnGogServe and
killProcessTree use internally. A live gog environment is not available
for end-to-end watcher proof; the test suite covers the settleProcess path
directly.

Screenshot 2026-07-21 at 7 21 43 PM

@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 22, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 26, 2026, 4:04 AM ET / 08:04 UTC.

ClawSweeper review

What this changes

The PR starts the Gmail gog watcher in its own Unix process group and routes shutdown through OpenClaw’s shared process-tree terminator so credential-helper descendants are stopped too.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

The PR remains useful: it applies the existing cross-platform process-tree terminator to the Gmail watcher and has credible after-fix integration proof. No concrete patch defect is visible from the supplied diff and review context; rebase onto current main and refresh the three-way validation before landing because the branch is behind.

Priority: P2
Reviewed head: c650313c23d9423de92e704d2b6a73928fbbb2a3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation follows an existing process-tree pattern, includes targeted coverage, and has credible after-fix integration evidence.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The contributor supplied a terminal screenshot of an after-fix integration run using the real watcher start/stop functions and a fake gog process whose helper deliberately survives direct SIGTERM; both processes are shown terminated after shutdown.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The contributor supplied a terminal screenshot of an after-fix integration run using the real watcher start/stop functions and a fake gog process whose helper deliberately survives direct SIGTERM; both processes are shown terminated after shutdown.
Evidence reviewed 5 items Watcher shutdown change: The PR changes the Gmail watcher spawn options to create a separate Unix process group and replaces the watcher-local signal/escalation timer with the shared process-tree terminator, retaining a direct-child fallback only when no PID exists.
Shared termination contract: The supplied PR rationale and existing sibling pattern identify src/process/kill-tree.ts as the shared graceful-termination implementation: Unix signals the negative process-group ID and Windows uses tree termination, with later escalation if needed.
Focused unit coverage: The watcher tests add coverage that shutdown calls killProcessTree for a spawned PID and does not also call direct proc.kill in that normal path.
Findings None None.
Security None None.

How this fits together

The Gmail hook registers and starts a long-running gog gmail watch serve subprocess when Gmail hooks are configured. Gateway shutdown or watcher replacement must stop that process and any helper descendants without signalling the parent OpenClaw process.

flowchart LR
  A[Gmail hook configuration] --> B[Start gog watcher]
  B --> C[Dedicated Unix process group]
  C --> D[Gateway or watcher shutdown]
  D --> E[Shared process-tree terminator]
  E --> F[Gog process exits]
  E --> G[Credential helpers exit]
Loading

Before merge

  • Resolve merge risk (P1) - The PR is mergeable but behind current main; rebase and re-check the resulting three-way merge before landing, especially around the shared termination helper and watcher lifecycle.
  • Complete next step (P2) - No mechanical repair is identified; a maintainer should refresh the branch against current main and review the resulting three-way merge before landing.
Agent review details

Security

None.

PR surface

Source +9, Tests +161. Total +170 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 11 +9
Tests 2 179 18 +161
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 199 29 +170

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the Gmail watcher on the shared process-tree shutdown path, then land a rebased head after the updated merge result preserves the focused tests and the demonstrated descendant-cleanup behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the Gmail watcher on the shared process-tree shutdown path, then land a rebased head after the updated merge result preserves the focused tests and the demonstrated descendant-cleanup behavior.

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

Yes — the added integration scenario provides a high-confidence path: run the watcher against a gog process that leaves a helper child alive on SIGTERM, then verify both PIDs are gone after stopGmailWatcher. The contributor supplied after-fix terminal evidence, but this review did not execute the scenario locally.

Is this the best way to solve the issue?

Yes — using the established shared tree-termination helper is the narrowest maintainable repair, and creating a dedicated Unix process group prevents the group signal from reaching the OpenClaw parent process.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0c8f070c92a8.

Labels

Label justifications:

  • P2: This is a bounded Gmail-hook lifecycle bug that can leave helper processes running, but the supplied evidence does not show a broad outage or immediate security boundary failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The contributor supplied a terminal screenshot of an after-fix integration run using the real watcher start/stop functions and a fake gog process whose helper deliberately survives direct SIGTERM; both processes are shown terminated after shutdown.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor supplied a terminal screenshot of an after-fix integration run using the real watcher start/stop functions and a fake gog process whose helper deliberately survives direct SIGTERM; both processes are shown terminated after shutdown.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The contributor supplied a terminal screenshot of an after-fix integration run using the real watcher start/stop functions and a fake gog process whose helper deliberately survives direct SIGTERM; both processes are shown terminated after shutdown.

Evidence

What I checked:

  • Watcher shutdown change: The PR changes the Gmail watcher spawn options to create a separate Unix process group and replaces the watcher-local signal/escalation timer with the shared process-tree terminator, retaining a direct-child fallback only when no PID exists. (src/hooks/gmail-watcher.ts:82, c650313c23d9)
  • Shared termination contract: The supplied PR rationale and existing sibling pattern identify src/process/kill-tree.ts as the shared graceful-termination implementation: Unix signals the negative process-group ID and Windows uses tree termination, with later escalation if needed. (src/process/kill-tree.ts:46, 0c8f070c92a8)
  • Focused unit coverage: The watcher tests add coverage that shutdown calls killProcessTree for a spawned PID and does not also call direct proc.kill in that normal path. (src/hooks/gmail-watcher.test.ts:3, c650313c23d9)
  • After-fix integration proof: The contributor’s July 26, 2026 proof runs the actual watcher start/stop functions against a fake gog binary that deliberately leaves a helper alive on SIGTERM; the attached terminal result shows both the watcher and helper gone after shutdown. (src/hooks/gmail-watcher.integration.test.ts:1, c650313c23d9)
  • Current merge state: GitHub reports the PR as mergeable but behind main; the reviewed head is based on 5451f48b824216f92a13400080aa6b63b61753b9, while the supplied current-main SHA is 0c8f070c92a8bbc3a9d967415a9d031ee1212e69, so the final three-way result has not yet been reviewed. (0c8f070c92a8)

Likely related people:

  • steipete: The supplied PR timeline routes the reviewed ready-for-maintainer state to this person; direct local history inspection was unavailable in this read-only environment, so this is only a routing signal. (role: likely follow-up owner; confidence: low; files: src/hooks/gmail-watcher.ts, src/process/kill-tree.ts)
  • jverdi: The supplied PR timeline also routes the ready-for-maintainer review to this person; no direct feature-history attribution could be established from the available read-only inspection. (role: likely follow-up owner; confidence: low; files: src/hooks/gmail-watcher.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and refresh validation for the resulting merge head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (7 earlier review cycles)
  • reviewed 2026-07-25T01:13:19.566Z sha e13702c0ed8467492a4b034edf12d1114cd44f63 :: needs real behavior proof before merge. :: [P1] Do not close the host-hook runtime report
  • reviewed 2026-07-25T20:56:16.565Z sha e13702c0ed8467492a4b034edf12d1114cd44f63 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-26T03:26:34.763Z sha e13702c0ed8467492a4b034edf12d1114cd44f63 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-26T03:50:47.936Z sha e13702c0ed8467492a4b034edf12d1114cd44f63 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-26T05:13:43.794Z sha e54326c2bf0566675301a6e9562c147c1643bc7b :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-26T05:19:19.140Z sha e54326c2bf0566675301a6e9562c147c1643bc7b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-26T05:31:55.036Z sha c650313c23d9423de92e704d2b6a73928fbbb2a3 :: needs maintainer review before merge. :: none

@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

After-fix proof using repo's actual killProcessTree - since a live gog environment is not available, a fake gog binary was used that mirrors the real behavior: it spawns a credential-helper child process and deliberately does not kill it on SIGTERM (simulating the real bug where gog's descendants survive shutdown). The proof script calls killProcessTree directly from packages/agent-core/dist/harness/env/kill-tree.js - the same compiled function the fixed settleProcess path invokes - with detached: true matching the updated spawn option. The credential-helper exits even though gog's own SIGTERM handler did not clean it up, proving the process-group signal reaches descendants correctly.
Screenshot 2026-07-25 at 10 19 10 PM

@clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 26, 2026
@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

Integration test (gmail-watcher.integration.test.ts) - calls the actual startGmailWatcher and stopGmailWatcher functions with no mocks for spawn or killProcessTree. A fake gog binary spawns a sleep 99999 credential-helper child and deliberately skips killing it on SIGTERM, simulating the real bug. Both the gog process and its descendant are gone after stopGmailWatcher completes, proving the patched watcher lifecycle cleans up the full process tree.

Screenshot 2026-07-26 at 12 11 27 AM

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 26, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 26, 2026
@NarahariRaghava

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 26, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@vincentkoc
vincentkoc force-pushed the fix/gmail-watcher-kill-process-tree branch 3 times, most recently from 66d9090 to 748a48c Compare July 29, 2026 06:56
@vincentkoc
vincentkoc force-pushed the fix/gmail-watcher-kill-process-tree branch from 748a48c to d79f832 Compare July 29, 2026 07:00
@vincentkoc
vincentkoc force-pushed the fix/gmail-watcher-kill-process-tree branch from d79f832 to 4cc1e64 Compare July 29, 2026 07:36
@vincentkoc
vincentkoc force-pushed the fix/gmail-watcher-kill-process-tree branch from 4cc1e64 to b30a81f Compare July 29, 2026 07:57
@vincentkoc
vincentkoc merged commit 320c3ad into openclaw:main Jul 29, 2026
123 of 126 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 29, 2026
* origin/main: (100 commits)
  fix(hooks): kill gog process tree on gmail-watcher shutdown (#112452)
  fix(memory): avoid phantom continuation pages (#115722)
  fix(agents): reject cancelled foreground commands (#115694)
  fix(telegram): prevent false empty replies after message-tool delivery (#115588)
  refactor: unify session cost rollup scans (#115749)
  fix(agents): honor completed semantic command exits (#115737)
  feat(agents): persist last-used session model as the agent default (#115717)
  feat(openai): support GPT-Live over backend WebSocket (#115622)
  fix(ui): unify sidebar thread density (#115646)
  feat(ui): path-based agent and panel URLs on Settings > Agents (#115673)
  feat(gateway): serve HTTP byte ranges on media routes (#115667)
  refactor: consolidate Teams and Zoom meeting plugin shells (#115707)
  fix(browser): release unread CDP response streams (#115675)
  feat(ui): move settings save feedback into the sidebar footer (#115679)
  fix(plugins): enforce hook security invariants (#115701)
  refactor: deduplicate extension normalization primitives (#115650)
  feat(gateway): add least-privilege voice-node pairing (#115712)
  fix(ui): restore in-flight assistant replies after reconnect (#115691)
  fix(whatsapp): infer native media from filenames (#115725)
  fix(system-agent): avoid TUI startup catalog preparation (#113136)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
…#112452)

* fix(hooks): kill gog process tree on gmail-watcher shutdown

* fix(hooks): add curly braces for oxlint curly rule

* test(hooks): add integration proof for gmail-watcher process-tree shutdown

* test(hooks): fix integration test lint errors

* fix(hooks): await Gmail watcher tree escalation

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants