Repository navigation
fix(hooks): exclude sent and draft Gmail events - #56720
Conversation
Greptile SummaryThis PR restores the missing Key findings:
Confidence Score: 5/5Safe to merge — the core bug fix is correct and all remaining findings are minor style issues (P2). All P0/P1 concerns are absent. The two findings are purely cosmetic: a Zod chain-ordering issue that does not affect runtime behaviour thanks to an explicit fallback, and a redundant null guard on a non-nullable field. Neither blocks correctness or introduces a regression. src/config/zod-schema.hooks.ts — the
|
| Filename | Overview |
|---|---|
| src/hooks/gmail.ts | Adds excludeLabels to GmailHookOverrides, GmailHookRuntimeConfig, resolveGmailHookRuntimeConfig, and buildGogWatchServeArgs — core logic is correct; minor redundant null guard on a required field. |
| src/config/zod-schema.hooks.ts | Adds excludeLabels field with .default().optional() ordering, which means the Zod-level default is never applied at parse time; behaviour is rescued by the runtime fallback but the generated schema annotation is misleading. |
| src/config/types.hooks.ts | Adds optional excludeLabels?: string[] to HooksGmailConfig — straightforward and correct. |
| src/config/schema.base.generated.ts | Auto-generated JSON schema updated with excludeLabels field and default annotation — consistent with the Zod schema definition. |
| src/hooks/gmail.test.ts | Comprehensive tests added covering default labels, custom labels, empty array omission, and resolveGmailHookRuntimeConfig override behaviour — good coverage. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/config/zod-schema.hooks.ts
Line: 132-136
Comment:
**`.default().optional()` order means default is never applied**
In Zod v3 the chain `z.array(...).default(X).optional()` produces a `ZodOptional(ZodDefault(...))`. When the field is absent from the config (input is `undefined`), the outer `ZodOptional` short-circuits and returns `undefined` immediately — the inner `ZodDefault` is never reached. This means `gmail.excludeLabels` will always be `undefined` when the user hasn't set the field, rather than the intended `["SPAM", "TRASH", "DRAFT", "SENT"]`.
The behaviour is still correct end-to-end only because `resolveGmailHookRuntimeConfig` has the extra fallback `?? DEFAULT_GMAIL_EXCLUDE_LABELS`. However, the `"default"` annotation emitted into `schema.base.generated.ts` is therefore misleading: the Zod schema itself never applies it at parse time.
To actually have Zod apply the default, the ordering must be reversed (`.optional()` first, then `.default()`):
```suggestion
excludeLabels: z
.array(z.string())
.optional()
.default(["SPAM", "TRASH", "DRAFT", "SENT"])
.describe("Gmail labels to exclude from webhook notifications"),
```
Alternatively, since every other field in this schema omits a Zod-level default and relies on the resolution function for its fallback, you could simply drop the `.default()` call here to stay consistent — just keep `.optional()` and rely on the `?? DEFAULT_GMAIL_EXCLUDE_LABELS` already present in `resolveGmailHookRuntimeConfig`.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/hooks/gmail.ts
Line: 253-255
Comment:
**Redundant truthiness check on a required field**
`excludeLabels` is typed as `string[]` (non-optional) in `GmailHookRuntimeConfig`, so `cfg.excludeLabels` can never be `null` or `undefined`. The leading `cfg.excludeLabels &&` guard is unnecessary and slightly misleading about the field's nullability.
```suggestion
if (cfg.excludeLabels.length > 0) {
args.push("--exclude-labels", cfg.excludeLabels.join(","));
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(hooks): restore --exclude-labels in ..." | Re-trigger Greptile
| excludeLabels: z | ||
| .array(z.string()) | ||
| .default(["SPAM", "TRASH", "DRAFT", "SENT"]) | ||
| .describe("Gmail labels to exclude from webhook notifications") | ||
| .optional(), |
There was a problem hiding this comment.
.default().optional() order means default is never applied
In Zod v3 the chain z.array(...).default(X).optional() produces a ZodOptional(ZodDefault(...)). When the field is absent from the config (input is undefined), the outer ZodOptional short-circuits and returns undefined immediately — the inner ZodDefault is never reached. This means gmail.excludeLabels will always be undefined when the user hasn't set the field, rather than the intended ["SPAM", "TRASH", "DRAFT", "SENT"].
The behaviour is still correct end-to-end only because resolveGmailHookRuntimeConfig has the extra fallback ?? DEFAULT_GMAIL_EXCLUDE_LABELS. However, the "default" annotation emitted into schema.base.generated.ts is therefore misleading: the Zod schema itself never applies it at parse time.
To actually have Zod apply the default, the ordering must be reversed (.optional() first, then .default()):
| excludeLabels: z | |
| .array(z.string()) | |
| .default(["SPAM", "TRASH", "DRAFT", "SENT"]) | |
| .describe("Gmail labels to exclude from webhook notifications") | |
| .optional(), | |
| excludeLabels: z | |
| .array(z.string()) | |
| .optional() | |
| .default(["SPAM", "TRASH", "DRAFT", "SENT"]) | |
| .describe("Gmail labels to exclude from webhook notifications"), |
Alternatively, since every other field in this schema omits a Zod-level default and relies on the resolution function for its fallback, you could simply drop the .default() call here to stay consistent — just keep .optional() and rely on the ?? DEFAULT_GMAIL_EXCLUDE_LABELS already present in resolveGmailHookRuntimeConfig.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/zod-schema.hooks.ts
Line: 132-136
Comment:
**`.default().optional()` order means default is never applied**
In Zod v3 the chain `z.array(...).default(X).optional()` produces a `ZodOptional(ZodDefault(...))`. When the field is absent from the config (input is `undefined`), the outer `ZodOptional` short-circuits and returns `undefined` immediately — the inner `ZodDefault` is never reached. This means `gmail.excludeLabels` will always be `undefined` when the user hasn't set the field, rather than the intended `["SPAM", "TRASH", "DRAFT", "SENT"]`.
The behaviour is still correct end-to-end only because `resolveGmailHookRuntimeConfig` has the extra fallback `?? DEFAULT_GMAIL_EXCLUDE_LABELS`. However, the `"default"` annotation emitted into `schema.base.generated.ts` is therefore misleading: the Zod schema itself never applies it at parse time.
To actually have Zod apply the default, the ordering must be reversed (`.optional()` first, then `.default()`):
```suggestion
excludeLabels: z
.array(z.string())
.optional()
.default(["SPAM", "TRASH", "DRAFT", "SENT"])
.describe("Gmail labels to exclude from webhook notifications"),
```
Alternatively, since every other field in this schema omits a Zod-level default and relies on the resolution function for its fallback, you could simply drop the `.default()` call here to stay consistent — just keep `.optional()` and rely on the `?? DEFAULT_GMAIL_EXCLUDE_LABELS` already present in `resolveGmailHookRuntimeConfig`.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Good catch — fixed in 5f56d2e. Dropped the Zod-level .default() to stay consistent with the other fields in this schema (all rely on resolveGmailHookRuntimeConfig for defaults rather than Zod parse-time defaults).
| if (cfg.excludeLabels && cfg.excludeLabels.length > 0) { | ||
| args.push("--exclude-labels", cfg.excludeLabels.join(",")); | ||
| } |
There was a problem hiding this comment.
Redundant truthiness check on a required field
excludeLabels is typed as string[] (non-optional) in GmailHookRuntimeConfig, so cfg.excludeLabels can never be null or undefined. The leading cfg.excludeLabels && guard is unnecessary and slightly misleading about the field's nullability.
| if (cfg.excludeLabels && cfg.excludeLabels.length > 0) { | |
| args.push("--exclude-labels", cfg.excludeLabels.join(",")); | |
| } | |
| if (cfg.excludeLabels.length > 0) { | |
| args.push("--exclude-labels", cfg.excludeLabels.join(",")); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hooks/gmail.ts
Line: 253-255
Comment:
**Redundant truthiness check on a required field**
`excludeLabels` is typed as `string[]` (non-optional) in `GmailHookRuntimeConfig`, so `cfg.excludeLabels` can never be `null` or `undefined`. The leading `cfg.excludeLabels &&` guard is unnecessary and slightly misleading about the field's nullability.
```suggestion
if (cfg.excludeLabels.length > 0) {
args.push("--exclude-labels", cfg.excludeLabels.join(","));
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Good catch — fixed in 5f56d2e. Removed the redundant truthiness guard since excludeLabels is typed as string[] (non-optional) in GmailHookRuntimeConfig.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: needs real behavior proof before merge. Reviewed July 3, 2026, 9:51 PM ET / July 4, 2026, 01:51 UTC. Summary PR surface: Source +16, Tests +72, Docs +2, Generated +14. Total +104 across 11 files. Reproducibility: yes. at source level. Current main and Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Land a refreshed fix that restores DRAFT/SENT exclusions by default, either without a new config knob or with accepted, correct, tested config semantics and redacted real watcher proof. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Current main and Is this the best way to solve the issue? No, not as-is. Restoring the default flag in the shared helper is the right fix location, but the new config surface needs maintainer acceptance and the empty-list behavior must match gogcli's contract before merge. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2ffeedf406e7. Label changesLabel justifications:
Evidence reviewedPR surface: Source +16, Tests +72, Docs +2, Generated +14. Total +104 across 11 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
2517985 to
b881300
Compare
|
Thanks for the review. The first update was superseded while main advanced; latest addressed commit is 4088dc12c9f8a560680284e72c69aa53da091d9f. The PR body now has the refreshed before/after and verification logs. |
b881300 to
607a301
Compare
|
Main advanced again while updating the branch, so I removed the non-essential changelog entry to avoid repeated top-of-file conflicts and rebuilt the PR on 8375353. Latest addressed commit is 4088dc12c9f8a560680284e72c69aa53da091d9f, with the PR body refreshed to the new before/after and verification logs. |
607a301 to
4088dc1
Compare
|
@Lidang-Jiang thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward. Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive. Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it. |
Co-authored-by: Lidang Jiang <[email protected]>
4088dc1 to
2bdf9db
Compare
|
Maintainer rewrite is ready on exact head ClawSweeper rank-up moves addressed:
Validation on this exact head:
The local changed-check wrapper could not acquire Blacksmith Testbox because this host is not authenticated. No code proof was skipped: focused local validation and the complete exact-head hosted CI run cover the touched core and test lanes. |
|
Merged via squash.
|
* origin/main: refactor(channels): deduplicate ingress monitor shells (openclaw#115792) feat(ui): first-class chat audio/video player cards (openclaw#115764) fix(qa): use SQLite Matrix E2EE state (openclaw#115748) fix(agents): expose CLI tool summaries in terminal results (openclaw#115797) fix(plugins): recover user turns with scoped reply hooks (openclaw#114836) fix(mattermost): preserve private-channel origin identity (openclaw#115726) fix(line): mark durably accepted webhook deliveries (openclaw#115796) chore: update dependencies across workspace (openclaw#115677) fix(hooks): exclude outbound Gmail labels (openclaw#56720) feat: add Fish Audio S2.1 and local MLX speech (openclaw#115790) feat(agents): add per-session tool overrides (openclaw#115785) fix(plugins): stop repeated manifest realpath scans (openclaw#115783)
Co-authored-by: Vincent Koc <[email protected]>
* origin/main: refactor(channels): deduplicate ingress monitor shells (openclaw#115792) feat(ui): first-class chat audio/video player cards (openclaw#115764) fix(qa): use SQLite Matrix E2EE state (openclaw#115748) fix(agents): expose CLI tool summaries in terminal results (openclaw#115797) fix(plugins): recover user turns with scoped reply hooks (openclaw#114836) fix(mattermost): preserve private-channel origin identity (openclaw#115726) fix(line): mark durably accepted webhook deliveries (openclaw#115796) chore: update dependencies across workspace (openclaw#115677) fix(hooks): exclude outbound Gmail labels (openclaw#56720) feat: add Fish Audio S2.1 and local MLX speech (openclaw#115790) feat(agents): add per-session tool overrides (openclaw#115785) fix(plugins): stop repeated manifest realpath scans (openclaw#115783)
Closes #56635
What Problem This Solves
Fixes an issue where Gmail hook users could have sent messages and draft saves forwarded into OpenClaw because the watcher inherited
gog's narrowerSPAM,TRASHexclusion default.Why This Change Was Made
The shared Gmail watcher argument builder now always passes
--exclude-labels SPAM,TRASH,DRAFT,SENT. This keeps the policy in the single path used by both Gateway auto-start andopenclaw webhooks gmail run.This rewrite intentionally removes the proposed
hooks.gmail.excludeLabelsconfig surface. OpenClaw's Gmail hook is an inbound-mail workflow, so excluding outbound and draft labels is a fixed product default rather than another operator setting.The original report attributed the change to OpenClaw 2026.3.24, but package inspection found that the published 2026.2.24 and 2026.3.24 watcher builders both omitted the flag. The confirmed defect is implicit reliance on
gog, whose current default excludes onlySPAM,TRASH.User Impact
Sent mail, drafts, spam, and trash are filtered by
gogbefore hook delivery. Users no longer have their own outbound messages or draft saves enter the Gmail hook processing path.Evidence
src/hooks/gmail.test.tsfailed because generated watcher args omitted--exclude-labels.gog v0.32.0in isolated--dry-runmode; it exited 0 and reportedexclude_labels: ["SPAM","TRASH","DRAFT","SENT"]withsource: "flags".openclaw/gogclidocuments--exclude-labels, defaults toSPAM,TRASH, and accepts an explicit empty string to disable filtering.oxfmt --check, scopedoxlint, andgit diff --checkpassed.AI-assisted: yes. Maintainer rewrite preserves Lidang Jiang's contribution with a co-author trailer.