Skip to content

fix(gmail): leave the user's own addresses out of gmail autoreply - #1325

Closed
saariuslystoned wants to merge 4 commits into
openclaw:mainfrom
saariuslystoned:fix/gmail-autoreply-sendas-aliases
Closed

saariuslystoned wants to merge 4 commits into
openclaw:mainfrom
saariuslystoned:fix/gmail-autoreply-sendas-aliases

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

gmail autoreply treated only the account and the sending address as "self". Without --allow-self, which is documented as "Allow replying to messages sent by your own account/alias", it still auto-replied in three cases:

  • a message sent from another of the user's send-as aliases, with the reply going to that alias;
  • a message sent from one of the user's own addresses with an external Reply-To;
  • any self-sent message, if the send-as list couldn't be read, because the error was ignored.

Fix

  • Build the self list with selfEmailsForReply(account, from.sendingEmail, sendAs), as gmail reply-all and gmail send --reply-all do.
  • Without --allow-self, skip a message whose From is any self address (no_reply_recipient), whatever its Reply-To. --allow-self behaves as before.
  • Without --allow-self, if the send-as list can't be read, stop before searching or sending instead of guessing. The API error is wrapped, so exit codes are unchanged. With --allow-self, a failed lookup keeps the previous sender fallback, since replies to your own addresses are allowed anyway.

Tests

internal/cmd/gmail_autoreply_sendas_test.go runs gmail autoreply through the CLI against an httptest Gmail server with send-as me@example.com and alias@example.com. It covers:

  • From the alias: on main (e8428c3) one reply is sent; with this change it's skipped.
  • From "Alias" <ALIAS@EXAMPLE.COM>: skipped.
  • From the alias with Reply-To an external address: skipped, and sent with --allow-self.
  • From the alias with --allow-self: sent.
  • From an external sender: still replied to.
  • settings/sendAs returning 403: the command fails with no send, and with --allow-self it still replies.
  • settings/sendAs is fetched exactly once.

Built gog binaries from main and from this branch were run against a local Gmail stand-in through GOG_GOOGLE_API_BASE_URL. The stand-in is not Google: its send-as list is probe@example.com (primary) and alias@example.com. The result for each case is what messages/send received:

$ gog --json gmail autoreply in:inbox --body thanks
From alias@example.com                           main: sends To alias@example.com        branch: skipped, no send
From alias@, Reply-To victim@external.com        main: sends To victim@external.com      branch: skipped, no send
From alice@example.com                           main: sends To alice@example.com        branch: sends To alice@example.com
settings/sendAs 403, From alias@                 main: sends To alias@example.com        branch: exit 6 (permission_denied), no send
settings/sendAs 403, From alias@, --allow-self   main: sends To alias@example.com        branch: sends To alias@example.com

Every make ci step passed on 36cacee (go1.27.3). The Go test suite ran on a second macOS arm64 machine, and the fmt, lint, deadcode, docs, agent-skills and node checks ran locally.

@saariuslystoned

☁️

🤖 Generated with Claude Code

saariuslystoned and others added 3 commits November 9, 2026 10:27
gmail autoreply excluded only the account and the sending address, so a message sent from another of the user's send-as aliases was auto-replied to that alias even without --allow-self. Build the self list with selfEmailsForReply, as gmail reply-all and gmail send --reply-all do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nnot be read

A message sent from one of the user's addresses with an external Reply-To was still auto-replied to without --allow-self, whose help says it allows replying to messages sent by your own account or alias. Skip those. Also stop before searching or sending if the send-as list cannot be read, instead of silently treating only the account and sending address as self.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: ready, awaiting a maintainer decision.

What this changes

This PR excludes send-as aliases from default autoreplies and stops when alias discovery fails, while preserving the --allow-self fallback.

Example: An account receives mail from alias@example.com with Reply-To victim@external.com.

  • Before: Default autoreply sends a reply to victim@external.com.
  • After: The message is skipped as no_reply_recipient without sending.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused implementation with shipped-CLI and upgrade evidence; readiness is capped by the unresolved discovery-error policy.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Built base and head gog binaries on macOS arm64 exercised autoreply through the production Gmail client against a loopback Gmail stand-in, showing alias and external Reply-To exclusion, ordinary external replies, and discovery failure with and without --allow-self. The added v0.48.0 upgrade output shows unchanged account settings, preserved dedupe labels, no sends during discovery failure, and correct recovery. The environment blocked linked raw release assets; the inline observations cover the changed behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Default autoreplies can reply to another address belonging to the user or follow an external Reply-To on self-originated mail.
Reason: Alias exclusion restores the documented behavior, but removing the existing discovery-error fallback changes an owner-built default without recorded owner approval.

Merge readiness

⏳ Ready, awaiting maintainer decision

Keep open: main still needs the alias-exclusion fix, and no introduced correctness bug was found; changing the discovery-error fallback needs an owner decision.

Priority: P2
Reviewed head: 36caceedea78aaed3af8d3a1b56aa8a9c80eb5cc
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should default gmail autoreply stop before searching or sending whenever the send-as list cannot be loaded?
  • Recommendation: Approve stopping when discovery fails: Accept that complete self-exclusion requires successful discovery and that scheduled runs will stop during discovery errors; retain the existing --allow-self fallback.
  • Why: The existing sender resolver tolerates discovery errors, while this PR makes them fatal without --allow-self, including for external messages; the contributor explains the safety rationale, but no maintainer approval was found.

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gmail autoreply CLI loads account identities and matching messages, filters eligible recipients, sends threaded replies, and labels successfully handled threads for deduplication.

flowchart TD
  A[Autoreply CLI] --> B[Load send-as identities]
  B --> C[Search Gmail messages]
  C --> D[Check labels and sender identities]
  D --> E[Skip excluded messages]
  D --> F[Send threaded replies]
  F --> G[Apply dedupe label]
Loading

Technical review

Best possible solution:

Retain the shared alias-exclusion fix and have the feature owner explicitly settle whether discovery failure must stop default autoreplies.

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

Main's recipient-selection path establishes the alias and external Reply-To failures, and the contributor supplies matching before-and-after CLI observations; this review did not execute target code.

Is this the best way to solve the issue?

Reusing the existing identity helper and checking From before Reply-To is a focused repair; making identity discovery mandatory is a separate compatibility choice.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e8428c36dd31.

Provenance checked

  • Self-address and From filtering keeps the original intent (4067cc6: The original autoreply command documents account-and-alias exclusion through --allow-self while implementing only account-and-selected-sender recipient filtering.)
  • Discovery-error fallback changes intended behavior with a stated reason (0ea6763: The compose-plumbing refactor preserved the earlier sender resolver's fallback after discovery failure; no separate rationale was found in the commit or associated-PR lookup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4067cc6 adds internal/cmd/gmail_autoreply.go:166 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4067cc6e570f; files: internal/cmd/gmail_autoreply.go)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on maintainer.

Label justifications:

  • P2: The fix prevents unwanted automated replies in a specific Gmail workflow without evidence of a broad urgent outage.
  • merge-risk: 🚨 compatibility: Previously tolerated send-as discovery errors now stop default autoreply runs, including runs containing external mail.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Have the feature owner approve or revise the default stop-on-discovery-error behavior.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-09T15:53:37.419Z sha 3492f13 :: needs real behavior proof before merge. :: [P2] Preserve sender fallback when --allow-self is enabled
  • reviewed 2026-11-09T16:35:15.914Z sha 36cacee :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T16:39:14.371Z sha 36cacee :: needs real behavior proof before merge. :: none

Reviewed November 10, 2026, 6:44 PM ET / 23:44 UTC (Revision 4).

--allow-self already permits replies to the user's own addresses, so a failed send-as lookup there falls back as before instead of stopping the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

Real-behavior proof for head 36caceedea78: autoreply leaves the user's own addresses out

  • Environment: macOS arm64, Go 1.27.3. Built gog from base and head. Loopback Gmail stand-in at 127.0.0.1:19661 via GOG_GOOGLE_API_BASE_URL (not Google). No real mailbox and no settings change.
  • Before: merge base e8428c36dd31 — replied to mail from another send-as alias, including when Reply-To was external, and still replied when settings/sendAs returned 403.
  • After: this head — those messages are skipped (no_reply_recipient) with no send. A 403 without --allow-self exits 6 and stops before search or send. External mail still gets a reply. --allow-self still replies, including after a failed send-as lookup.

before.txt after.txt

Hashes: SHA256SUMS

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

Upgrade proof: v0.48.0 to head 36caceedea78, same config and mailbox

Loopback Gmail stand-in at 127.0.0.1:19662 via GOG_GOOGLE_API_BASE_URL (not Google). Isolated GOG_HOME at repo-relative ../proof/home. File keyring; GOG_KEYRING_PASSWORD was a throwaway value. No Google account.

Built from this checkout:

# tag v0.48.0 (f939ed37151a), from that worktree
go build -o ../proof/bin/gog-v048 ./cmd/gog
# this head
go build -o ../proof/bin/gog-head ./cmd/gog

../proof/bin/gog-v048 version prints v0.48.0. ../proof/bin/gog-head version prints v0.48.1-0.20261109161909-36caceedea78.

Stand-in send-as list: probe@example.com (primary) and alias@example.com. Every autoreply run was:

gog --no-input --color=never --json --account inbox gmail autoreply in:inbox --body thanks --label UpgradeProof

1. v0.48.0 writes the account settings and the dedupe label

../proof/bin/gog-v048 --no-input --color=never auth keyring file
../proof/bin/gog-v048 --no-input --color=never config set timezone America/Chicago
../proof/bin/gog-v048 --no-input --color=never auth alias set inbox probe@example.com

../proof/home/config/config.json after setup, and still byte-identical after every later step (sha256 0cd40d356162366368b1dc5b44c15d27e396318d6c9dec3bf12f1b0b76d084b7):

{
  "keyring_backend": "file",
  "default_timezone": "America/Chicago",
  "account_aliases": {
    "inbox": "probe@example.com"
  }
}

v0.48.0 autoreply, exit 0. replied 2, skipped 0. One send to alice@example.com, one send to alias@example.com. Stand-in created UpgradeProof once (Label_1) and stored it on both threads.

2. Head, same config, no new mail

Exit 0. replied 0, skipped 2, both already_labeled (m-ext-old, m-alias-old). No messages/send. Head still reads alias inbox = probe@example.com, timezone America/Chicago, keyring backend file.

3. Alias exclusion on mail v0.48.0 had not labeled

Added m-alias-new (From alias@example.com, Reply-To victim@external.com) and m-ext-new (From carol@example.com).

Head, exit 0. replied 1, skipped 3:

  • m-ext-old, m-alias-old: already_labeled
  • m-alias-new: skipped / no_reply_recipient (no send; victim@external.com is not a recipient)
  • m-ext-new: replied to carol@example.com

Label creates stayed 1 (Label_1). m-alias-new was left unlabeled.

4. Send-as lookup fails

Added m-ext-pending (From dave@example.com). Stand-in then returns 403 for GET /gmail/v1/users/me/settings/sendAs.

Head, exit 6. stdout:

{"error":{"class":"permission_denied","code":6,"message":"Google API error (403 forbidden): Forbidden"}}

stderr: Google API error (403 forbidden): Forbidden

Stand-in saw only that one settings/sendAs GET. No message list and no send. m-ext-pending stayed unlabeled. Send count stayed 3.

5. Lookup recovers

Stand-in settings/sendAs returns the same two identities again. Head, exit 0. replied 1, to dave@example.com only. m-alias-new is still no_reply_recipient. The three previously labeled threads stay already_labeled. Label creates still 1. config.json sha256 unchanged.

Final sends: alice@example.com, alias@example.com (both from v0.48.0), carol@example.com, dave@example.com. Nothing to victim@external.com.

☁️

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 10, 2026
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@steipete

Copy link
Copy Markdown
Collaborator

Thank you for the fix. I reproduced the claim and consolidated excluding send-as aliases from default Gmail auto-replies into #1336, with regression coverage and your coauthor credit retained. The full make ci gate, built-CLI checks for the new request-validation fixes, and exact-head GitHub CI passed. Closing this PR as superseded by the merged implementation in #1336.

@steipete steipete closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants