Repository navigation
Conversation
Greptile SummaryThis PR fixes Google Chat Space messaging by correcting thread/reply-to handling, adding a 60-second in-memory deduplication cache to prevent duplicate bot responses, updating the default Key concerns found during review:
Confidence Score: 2/5
Last reviewed commit: dc91f50 |
| const isValid = crypto.verify( | ||
| header.alg === "RS256" ? "sha256" : "sha256", | ||
| Buffer.from(signedData), | ||
| publicKey, | ||
| signature, |
There was a problem hiding this comment.
Dead ternary and missing algorithm validation in JWT verification
Both branches of the ternary on line 255 evaluate to "sha256", making it dead code that misleadingly suggests algorithm-awareness. More critically, header.alg is never validated before this point — a JWT with alg: "RS512" or alg: "ES256" would proceed through the signature check using sha256 (incorrect algorithm) without being explicitly rejected. For alg: "none", crypto.verify will likely return false and be caught, but the intent to strictly allow only RS256 is not enforced.
The algorithm should be explicitly validated before reaching the signature verification step:
| const isValid = crypto.verify( | |
| header.alg === "RS256" ? "sha256" : "sha256", | |
| Buffer.from(signedData), | |
| publicKey, | |
| signature, | |
| if (header.alg !== "RS256") { | |
| return { ok: false, reason: `unsupported algorithm: ${header.alg}` }; | |
| } | |
| const isValid = crypto.verify( | |
| "sha256", | |
| Buffer.from(signedData), | |
| publicKey, | |
| signature, | |
| ); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/googlechat/src/auth.ts
Line: 254-258
Comment:
**Dead ternary and missing algorithm validation in JWT verification**
Both branches of the ternary on line 255 evaluate to `"sha256"`, making it dead code that misleadingly suggests algorithm-awareness. More critically, `header.alg` is never validated before this point — a JWT with `alg: "RS512"` or `alg: "ES256"` would proceed through the signature check using `sha256` (incorrect algorithm) without being explicitly rejected. For `alg: "none"`, `crypto.verify` will likely return `false` and be caught, but the intent to strictly allow only `RS256` is not enforced.
The algorithm should be explicitly validated before reaching the signature verification step:
```suggestion
if (header.alg !== "RS256") {
return { ok: false, reason: `unsupported algorithm: ${header.alg}` };
}
const isValid = crypto.verify(
"sha256",
Buffer.from(signedData),
publicKey,
signature,
);
```
How can I resolve this? If you propose a fix, please make it concise.| payload?: { iss?: string; aud?: string; email?: string; email_verified?: boolean; exp?: number; sub?: string }; | ||
| reason?: string; | ||
| }> { | ||
| const crypto = await import("node:crypto"); |
There was a problem hiding this comment.
Redundant dynamic import shadows static module-level import
crypto is already statically imported at line 2 (import crypto from "node:crypto"). The dynamic await import("node:crypto") here creates a new local binding that shadows the module-level one, which is confusing and adds unnecessary overhead on every call.
| const crypto = await import("node:crypto"); | |
| // crypto is already available from the top-level static import |
Remove the dynamic import and use the top-level crypto binding directly throughout manualVerifyGoogleJwt.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/googlechat/src/auth.ts
Line: 210
Comment:
**Redundant dynamic import shadows static module-level import**
`crypto` is already statically imported at line 2 (`import crypto from "node:crypto"`). The dynamic `await import("node:crypto")` here creates a new local binding that shadows the module-level one, which is confusing and adds unnecessary overhead on every call.
```suggestion
// crypto is already available from the top-level static import
```
Remove the dynamic import and use the top-level `crypto` binding directly throughout `manualVerifyGoogleJwt`.
How can I resolve this? If you propose a fix, please make it concise.| if (hasAnyMention) { | ||
| console.log(`[googlechat/access] extractMentionInfo: botTargets=${Array.from(botTargets).join(",")}, mentions=${JSON.stringify(mentionAnnotations.map(m => m.userMention?.user))}`); | ||
| } |
There was a problem hiding this comment.
Debug console.log statements left in production code
Several debug console.log / console.warn statements were left in production paths and log sensitive data including user objects, email addresses, space IDs, and message IDs. In a deployed environment these will appear in every applicable log stream and may violate user privacy expectations.
Affected locations across this PR (beyond this line):
extensions/googlechat/src/monitor-access.ts:97— logs all mention user objectsextensions/googlechat/src/monitor-access.ts:112(BOT type match log)extensions/googlechat/src/monitor-access.ts:291— group message policy decision logextensions/googlechat/src/monitor-access.ts:318— sender policy drop logextensions/googlechat/src/monitor.ts:101— ADDED_TO_SPACE logextensions/googlechat/src/monitor.ts:181— logs duplicate message ID onconsole.warnextensions/googlechat/src/monitor.ts:189— logs space ID, type, and message ID on every messageextensions/googlechat/src/monitor.ts:~487— delivery chunk logextensions/googlechat/src/auth.ts:282–296— logs audience, token verification outcome, and email
These should either be removed or replaced with the existing logVerbose helper which is gated behind a flag and does not use console.log.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/googlechat/src/monitor-access.ts
Line: 96-98
Comment:
**Debug console.log statements left in production code**
Several debug `console.log` / `console.warn` statements were left in production paths and log sensitive data including user objects, email addresses, space IDs, and message IDs. In a deployed environment these will appear in every applicable log stream and may violate user privacy expectations.
Affected locations across this PR (beyond this line):
- `extensions/googlechat/src/monitor-access.ts:97` — logs all mention user objects
- `extensions/googlechat/src/monitor-access.ts:112` (BOT type match log)
- `extensions/googlechat/src/monitor-access.ts:291` — group message policy decision log
- `extensions/googlechat/src/monitor-access.ts:318` — sender policy drop log
- `extensions/googlechat/src/monitor.ts:101` — ADDED_TO_SPACE log
- `extensions/googlechat/src/monitor.ts:181` — logs duplicate message ID on `console.warn`
- `extensions/googlechat/src/monitor.ts:189` — logs space ID, type, and message ID on every message
- `extensions/googlechat/src/monitor.ts:~487` — delivery chunk log
- `extensions/googlechat/src/auth.ts:282–296` — logs audience, token verification outcome, and email
These should either be removed or replaced with the existing `logVerbose` helper which is gated behind a flag and does not use `console.log`.
How can I resolve this? If you propose a fix, please make it concise.| const loaded = await runtime.channel.media.fetchRemoteMedia({ | ||
| url: mediaUrl, | ||
| maxBytes: maxBytes ?? (account.config.mediaMaxMb ?? 20) * 1024 * 1024, | ||
| }); |
There was a problem hiding this comment.
Local media loading support silently removed from sendMedia
The previous implementation distinguished between remote URLs and local paths:
const loaded = /^https?:\/\//i.test(mediaUrl)
? await runtime.channel.media.fetchRemoteMedia({ url: mediaUrl, maxBytes: effectiveMaxBytes })
: await runtime.media.loadWebMedia(mediaUrl, { maxBytes: effectiveMaxBytes, localRoots: mediaLocalRoots?.length ? mediaLocalRoots : undefined });The new code unconditionally calls fetchRemoteMedia, meaning any mediaUrl that isn't an http(s):// URL (e.g. a local file path) will be passed to fetchRemoteMedia, which will either throw or return an error. If any callers pass local media paths to this adapter, this is a silent regression. Additionally, mediaLocalRoots was removed from the function signature, discarding that capability entirely.
If local media is no longer a supported use-case for Google Chat, this should be explicitly documented. If it is still supported, the URL-check branch should be restored.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/googlechat/src/channel.ts
Line: 446-449
Comment:
**Local media loading support silently removed from `sendMedia`**
The previous implementation distinguished between remote URLs and local paths:
```ts
const loaded = /^https?:\/\//i.test(mediaUrl)
? await runtime.channel.media.fetchRemoteMedia({ url: mediaUrl, maxBytes: effectiveMaxBytes })
: await runtime.media.loadWebMedia(mediaUrl, { maxBytes: effectiveMaxBytes, localRoots: mediaLocalRoots?.length ? mediaLocalRoots : undefined });
```
The new code unconditionally calls `fetchRemoteMedia`, meaning any `mediaUrl` that isn't an `http(s)://` URL (e.g. a local file path) will be passed to `fetchRemoteMedia`, which will either throw or return an error. If any callers pass local media paths to this adapter, this is a silent regression. Additionally, `mediaLocalRoots` was removed from the function signature, discarding that capability entirely.
If local media is no longer a supported use-case for Google Chat, this should be explicitly documented. If it is still supported, the URL-check branch should be restored.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc91f505b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const loaded = await runtime.channel.media.fetchRemoteMedia({ | ||
| url: mediaUrl, | ||
| maxBytes: maxBytes ?? (account.config.mediaMaxMb ?? 20) * 1024 * 1024, |
There was a problem hiding this comment.
Restore local media loading for Google Chat sendMedia
This path now always uses fetchRemoteMedia, so local file payloads (for example tool outputs under agent workspace roots) are treated as remote URLs and fail instead of being loaded via mediaLocalRoots. The outbound pipeline still forwards local roots to channel adapters, and Google Chat already had explicit local-media coverage, so this change regresses attachment delivery for non-HTTP media paths.
Useful? React with 👍 / 👎.
| if (user?.type === "BOT") { | ||
| console.log(`[googlechat/access] Matched mention by type===BOT: ${userName}`); | ||
| return true; |
There was a problem hiding this comment.
Match mentions against bot identity, not any BOT user
Treating any mention with user.type === "BOT" as a match makes mention-gating over-permissive: in spaces with multiple bots, mentioning a different bot will still mark OpenClaw as mentioned and allow processing even when requireMention is enabled. This can trigger unsolicited replies in group spaces and should be constrained to known bot identifiers (users/app/configured bot user).
Useful? React with 👍 / 👎.
| if (recentlyProcessedMessages.has(msgId)) { | ||
| console.warn(`[googlechat/dedup] Skipping duplicate message: ${msgId} (already processed within ${DEDUP_TTL_MS}ms)`); | ||
| return; | ||
| } | ||
| recentlyProcessedMessages.set(msgId, Date.now()); |
There was a problem hiding this comment.
Add dedup marker only after successful message processing
The message ID is marked as processed before access checks and downstream handling complete. If anything later throws (for example media download or reply dispatch), retries/duplicate webhook deliveries for the same message.name are skipped for the full TTL, which can silently drop user messages instead of allowing a retry path.
Useful? React with 👍 / 👎.
| const cacheKey = account.accountId; | ||
| const cached = accessTokenCache.get(cacheKey); |
There was a problem hiding this comment.
Key access-token cache by credential fingerprint
The manual token cache uses only accountId, so rotating service-account credentials on the same account keeps reusing the previous token until expiry. After config reloads or key revocation, this can cause prolonged auth failures (or continued use of stale credentials) because the cache is not invalidated when credential material changes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8128e100e9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const key = jwks.find((k) => k.kid === header.kid); | ||
| if (!key) { | ||
| return { ok: false, reason: `no matching key found for kid=${header.kid}` }; |
There was a problem hiding this comment.
Refresh JWKS on kid cache miss before rejecting token
When manualVerifyGoogleJwt cannot find the token's kid in the cached JWKS set, it immediately rejects the request instead of forcing a JWKS refresh. Because fetchGoogleJwks serves cache entries for up to 10 minutes, normal Google key rotation can cause valid app-url webhook tokens to fail verification for the full cache window, producing intermittent auth outages until the TTL expires.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| if (!event.space || typeof event.space !== "object" || Array.isArray(event.space)) { | ||
| console.error(`[googlechat/webhook] invalid payload (no space object): type=${eventType} payload=${JSON.stringify(raw).slice(0, 500)}`); |
There was a problem hiding this comment.
Stop logging raw Google Chat webhook payloads
The new parse-error logging dumps raw webhook JSON into logs, which can include authorizationEventObject.systemIdToken and user message content in Add-on requests. In malformed-request scenarios this leaks bearer material and sensitive payload data to log sinks, so these branches should log only sanitized metadata instead of body content.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0f466ca79
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const msgId = message.name ?? ""; | ||
| if (msgId) { | ||
| pruneDedup(); | ||
| if (recentlyProcessedMessages.has(msgId)) { |
There was a problem hiding this comment.
Namespace dedup keys by account before skipping messages
The dedup cache currently keys only on message.name, but this map is module-global and shared across all configured Google Chat accounts. In multi-account deployments, the same space message ID can be observed by different bot accounts, so one account processing it first will cause the other account to drop it as a “duplicate” for 60 seconds. Include account.accountId (or another account-unique discriminator) in the dedup key to avoid cross-account message loss.
Useful? React with 👍 / 👎.
| // Mark as processed only after successful dispatch | ||
| if (msgId) { | ||
| recentlyProcessedMessages.set(msgId, Date.now()); |
There was a problem hiding this comment.
Only mark dedup after a confirmed outbound send
The message is marked processed immediately after dispatchReplyWithBufferedBlockDispatcher returns, but deliverGoogleChatReply swallows send/upload failures and logs them instead of throwing, so dispatch can resolve even when no reply was actually delivered. In that failure path, retries of the same webhook event are suppressed by dedup for the full TTL, which drops recoverable messages; a success signal from delivery (or propagating delivery errors) is needed before inserting into the dedup map. Fresh evidence: deliverGoogleChatReply catches and suppresses send failures in its media/text loops, so dispatch completion is not equivalent to successful delivery.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7762373cb9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (eventType === "ADDED_TO_SPACE" && !event.message) { | ||
| return; |
There was a problem hiding this comment.
Handle ADDED_TO_SPACE events without message payload
parseGoogleChatInboundPayload now maps add-on requests without chat.message to type: "ADDED_TO_SPACE", but processGoogleChatEvent immediately returns when event.message is absent, so those events never reach the pipeline. In practice, ADDED_TO_SPACE callbacks commonly omit a message object, which means the new added-to-space path is effectively dropped and any onboarding/welcome handling tied to that event cannot run.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close this PR as superseded: the central Google Chat Space/DM classification problem is now tracked by the narrower, open, mergeable replacement PR, while this older branch is conflicting and still carries auth, logging, delivery, and compatibility regressions that should not be salvaged as one broad patch. Canonical path: Close this broad conflicting branch and keep the remaining Space/DM classifier work on #58993; any dedupe, reply-default, Add-on, or ADDED_TO_SPACE behavior should return as separate, current-main PRs with explicit tests and proof. So I’m closing this here and keeping the remaining discussion on #58993. Review detailsBest possible solution: Close this broad conflicting branch and keep the remaining Space/DM classifier work on #58993; any dedupe, reply-default, Add-on, or ADDED_TO_SPACE behavior should return as separate, current-main PRs with explicit tests and proof. Do we have a high-confidence way to reproduce the issue? Yes for the PR blockers at source level: the live PR head removes Add-on principal binding, logs raw webhook payloads, keys dedupe only by message.name, and changes reply defaults. The original Space/DM classifier gap is also source-reproducible on current main and is now covered by the narrower replacement PR. Is this the best way to solve the issue? No. The maintainable solution is the focused current-main classifier PR plus separate, reviewed follow-ups for dedupe, Add-on event support, and reply-default policy if maintainers still want those changes. Security review: Security review needs attention: The diff changes Google Chat auth and webhook logging and introduces concrete security-sensitive regressions.
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against ee61f79b901d. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Describe the problem and fix in 2–5 bullets:
replyToModefor Google Chat fromoffto all in src/channels/dock.ts.ADDED_TO_SPACEevents.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
replyToModefor Google Chat now defaults to all instead ofoff.Security Impact (required)
No)No)No)No)No)Repro + Verification
Environment
Steps
Expected
Actual
Evidence
recentlyProcessedMessagescache behavior locally).Human Verification (required)
Review Conversations
Compatibility / Migration
Yes)None)No)Failure Recovery (if this breaks)
extensions/googlechat/src/.Risks and Mitigations