Repository navigation
fix(gmail): keep forwarding alive across watcher restarts - #130853
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 5:16 AM ET / 09:16 UTC. ClawSweeper reviewWhat this changesThis PR moves foreground Gmail forwarding onto the shared watcher lifecycle so replacement processes restart and clean up consistently. Merge readinessKeep this maintainer-owned repair open. It removes current main’s separate foreground supervisor, whose replacement child is not itself supervised; no actionable patch defect was found. Exact-head CI is still running, and native Windows process behavior remains the main pre-merge evidence gap. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGmail webhook startup launches a local flowchart LR
A[CLI or Gateway startup] --> B[Resolved Gmail watcher config]
B --> C[Shared watcher lifecycle]
C --> D[gog serve process]
D --> E[Webhook forwarding]
D --> F[Exit and cleanup handling]
F --> C
Before merge
Agent review detailsSecurityNone. PR surfaceSource -103, Tests +341, Docs 0, Other +19. Total +257 across 17 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the shared-lifecycle consolidation after exact-head CI, retaining foreground option resolution and signal ownership; obtain native Windows process proof if that platform is release-gated. Do we have a high-confidence way to reproduce the issue? Yes. On current main, the exit listener is attached only to the initial foreground child; after its replacement exits, no handler schedules another child. Is this the best way to solve the issue? Yes. Reusing the existing watcher lifecycle is the canonical fix; retaining a second CLI supervisor would leave restart, renewal, bind, and cleanup policy divergent. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 049f4940b9f9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Verified head: The defect is confirmed before the fix: the foreground runner creates only two children after two exits, while its renewal timer stays alive. Stable Final local verification passed: 221 focused tests across the Gmail owner, CLI/Gateway callers, process handling, and launcher (one opt-in real-Bun test skipped); the relevant core/test TypeScript programs; scoped lint/format/assertion/import-cycle checks; and The actual built Production: +115/-199, net -84; tests: +516/-175; docs: +1/-1. No new configuration keys, schemas, protocols, dependencies, versions, or changelog changes. Current-main reload changes are disjoint and remain untouched. Related #96088 remains outside this repair. Exact-head CI run 33056951623 completed successfully. The latest ClawSweeper review found no actionable patch or security defect. Both Rank-up moves are accounted for: exact-head CI is complete; native Windows process proof is not run. The authorized landing scope explicitly retains modeled Windows coverage, local macOS proof, and no remote-compute offload. I accept that documented platform uncertainty for this bounded owner repair under the standing landing approval. Windows regressions cover the exited-root PID guard and launcher policy, but are not represented as native process proof. No new Windows release gate or mandatory independent approval is present in the live main rules; the required No live Gmail, real gog, Gateway, cloud setup, or email delivery was used, as explicitly required for this task. Windows lifecycle behavior is modeled, not native Windows proof. This is verified process lifecycle behavior, not a claim of end-to-end email delivery. |
|
Merged via squash.
|
…30853) * fix(gmail): keep forwarding alive across watcher restarts * fix(gmail): preserve foreground CLI shutdown ownership
Closes #130852
Additional instructions
This branch is in the main repository and is editable by maintainers.
What Problem This Solves
Fixes an issue where users running
openclaw webhooks gmail runwould silently lose forwarding after the replacement watcher exited: the command stayed alive and renewed Gmail watches with no serve process left. It also fixes recovery getting stuck when an exited watcher leaves descendants holding its output pipes open.Why This Change Was Made
The foreground CLI now uses the existing resolved-config Gmail watcher lifecycle shared with Gateway startup and reload. That owner handles every replacement, bounded output drain, bind-error classification, single-flight renewal, and process-tree cleanup; the CLI still owns option resolution, prerequisites, and signals. This removes the duplicate foreground supervisor and redundant cancellation polling/controller rather than maintaining two restart policies. Built-CLI proof also caught the generic startup wrapper terminating this foreground owner after two seconds, before its three-second cleanup finished. Foreground Gmail now stays in the invoking process across ordinary and compile-cache startup, while one-shot setup keeps its existing wrapper behavior.
Unexpected POSIX leader exits clean up only that active watcher's owned process group. Windows does not run
taskkillagainst an already-exited root PID. Normal shutdown retains its three-second grace period, late stderr still classifies bind conflicts, and CLI overrides remain usable with hooks disabled without rewriting config. Setup registration remains fatal on failure; watcher renewal-error policy is unchanged. No new configuration flags, schemas, protocols, or dependencies.User Impact
Foreground forwarding recovers after repeated unexpected watcher exits using the shared five-second restart delay. Ctrl-C/SIGTERM cancels pending startup, restarts, and renewal work and waits for tree cleanup. Bind conflicts stop restart attempts with an actionable log message. See the webhook CLI reference.
The separate degraded OAuth/renewal-health behavior requested in #96088 is not fixed or closed by this change.
Evidence
The pre-fix regression failed with expected third child, got two, and the same failure reproduced independently from stable tag
v2026.7.1. The inherited-pipe fixture recordedoriginalExited=true,originalClosed=false,spawned=1, and a live resistant helper after seven seconds; no replacement arrived before its twelve-second deadline. The Windows dead-root termination regression also failed before the repair.Final local proof:
gmail-ops.test.ts,gmail-watcher.test.ts,gmail-watcher-lifecycle.test.ts,cli/webhooks-cli.test.ts, andprocess/child-process.test.tsusingnode scripts/run-vitest.mjswith those explicit paths.node scripts/run-vitest.mjs src/gateway/server-startup-post-attach.test.ts src/gateway/server-reload-handlers.test.ts -t 'Gmail watcher|Gmail restart|post-ready sidecar teardown'; 306 unrelated tests were intentionally unselected.OPENCLAW_E2E_SKIP_BUILD=1because it supplies its own entry files.git diff --checkpassed.pnpm buildpassed on final headf2db9972eb855f8d14c0286c9476130bb506876b(11m 0.4s). The actual builtopenclaw.mjs webhooks gmail runthen passed offline process proof on macOS with an isolated HOME/config/state, a fakegogfirst on a minimal PATH, explicit fixture options, and--tailscale off. Kernel sandboxing denied network access to the command and all descendants. Two forced watcher exits produced exactly one replacement each; earlier SIGTERM-resistant pipe-holding helpers were gone before the next watcher became ready. SIGTERM exited the CLI with code 0, all three watchers and all three helpers were already gone before harness cleanup, and config bytes were unchanged. The checked-in launcher fixtures separately cover source and packaged compile-cache startup.Fresh independent Codex autoreview of the combined final patch, including the built-CLI shutdown correction, completed with no actionable P0 findings. Source review covered the CLI producer, shared owner, Gateway cancellation callers, process output drain/tree cleanup, existing sibling tests, current main, and Node's child-process exit/close ordering. A recursive foreground callback was rejected because it would retain divergent renewal, bind, cancellation, and shutdown behavior; a new supervisor abstraction was unnecessary.
Production LOC: +115/-199 (net -84). Tests: +516/-175 (net +341). Twenty production lines are a pure move of launcher bootstrap execution below its existing argument-parser definitions. Docs: +1/-1. The regression tests exercise observable restart/renewal/termination outcomes and add no test-only production seam.
Provenance: carried forward; original introduction unknown. Blame reaches shallow boundary
e357203be5721f55434e7fc9891268e5c6afdd38(2026-07-12, Vincent Koc), which does not establish introduction. Stable-tag source independently exhibits the defect. Current main's unrelated model-runtime reload changes are in disjoint hunks.Proof limits: all account/topic/token values are fixtures. No live Gmail account, real gog, Gateway, cloud setup, or email delivery was used or tested, as explicitly required for this task. Windows behavior is modeled in tests, not verified on native Windows. This is process lifecycle proof, not end-to-end email delivery.
AI-assisted; maintainer reviewed and understood the ownership and behavior changes. No release/version/changelog changes.