Skip to content

fix(googlechat): surface reply send failures instead of silently dropping chunks - #110147

Closed
wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/googlechat-reply-delivery-failure
Closed

wangmiao0668000666 wants to merge 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/googlechat-reply-delivery-failure

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

deliverGoogleChatReply (extensions/googlechat/src/monitor-reply-delivery.ts:79-109 on main) wrapped every chunk send in a try/catch that only logged the error and kept looping. Two silent-loss paths resulted:

  1. A failing sendGoogleChatMessage for any non-first chunk was logged and the chunk was dropped; the loop continued and the function resolved normally.
  2. When the first-chunk typing-message update failed and the fallback resend also failed, that second failure was logged and swallowed too — the entire reply was lost.

The core reply dispatcher contract treats a rejected deliver as a failed delivery and a resolved one as visible delivery: src/auto-reply/reply/reply-dispatcher.ts:476-483 awaits options.deliver(...) and only routes to onError / failed-deliver in .catch. Resolving after a swallowed send error therefore reported the turn as delivered while the user saw nothing (or only part of the reply).

Why This Change Was Made

Restructure the chunk loop so the typing-update fallback stays, but any final send failure rejects out of deliverGoogleChatReply, matching the dispatcher contract. The typing-update catch is kept because a stale typing placeholder is recoverable — the same chunk is immediately resent as a new message, and only that resend failing is a real delivery failure. This mirrors the LINE sibling, which documents that a lost bubble "must surface as a partial delivery, not silent success" (extensions/line/src/auto-reply-delivery.ts:217-219), and the same-channel precedent #96646 ("throw on non-ok instead of parsing error body as success").

Fix classification: channel delivery error-propagation fix, additive behavior change only on the failure path; no config, SDK, or core changes.

User Impact

  • Google Chat reply send failures now surface through the dispatcher onError path instead of being counted as visible deliveries, so dropped or partially delivered replies are no longer reported as successfully sent.
  • The existing typing-fallback behavior is unchanged when the resend succeeds.

Evidence

Integration-backed failure-path proof (real HTTP stack, loopback stub)

New committed regression test extensions/googlechat/src/monitor.reply-delivery-failure.test.ts drives the production stack end to end against a local HTTP impersonator of the Google Chat API: deliverGoogleChatReply → sendGoogleChatMessage → withGoogleChatResponse → fetchWithSsrFGuard → real google-auth-library JWT signing and token exchange. Only global fetch is stubbed (rerouting chat.googleapis.com / oauth2.googleapis.com to 127.0.0.1); the service-account key is a throwaway RSA key generated in-process, the stub issues the token, and the stub answers the second spaces.messages create with a real HTTP 500 error envelope. The deliver/onError wiring mirrors extensions/googlechat/src/monitor.ts:408-429, and the outcome labels follow the dispatcher contract in src/auto-reply/reply/reply-dispatcher.ts:476-483. No real credentials, endpoints, or user data anywhere.

Standalone transcript of the same flow (three-chunk reply, second create → 500), after the fix:

stub: POST /token (grant=jwt-bearer) -> 200 access_token=ya29.stub-token (redacted)
stub: POST /v1/spaces/AAA/messages #1 text="First chunk of the assistant reply." -> 200
stub: POST /v1/spaces/AAA/messages #2 text="Second chunk of the assistant reply." -> 500
runtime.error: [default] Google Chat text reply failed: Error: Google Chat API 500: {"error":{"code":500,"message":"stub: backend unavailable","status":"INTERNAL"}}
dispatcher: deliveryOutcome=failed-deliver
summary: tokenExchanges=1 messageCreates=2 createStatuses=[200,500] patchAttempts=0 onErrorCalls=1

Same stub, same input, pre-fix monitor-reply-delivery.ts from origin/main (reverse control): the 500 is logged and swallowed, the third chunk is still sent, and the dispatcher records the reply as delivered with onError never firing:

stub: POST /v1/spaces/AAA/messages #1 text="First chunk of the assistant reply." -> 200
stub: POST /v1/spaces/AAA/messages #2 text="Second chunk of the assistant reply." -> 500
runtime.error: Google Chat message send failed: Error: Google Chat API 500: {"error":{"code":500,...}}
stub: POST /v1/spaces/AAA/messages #3 text="Third chunk of the assistant reply." -> 200
dispatcher: deliveryOutcome=delivered
summary: tokenExchanges=1 messageCreates=3 createStatuses=[200,500,200] patchAttempts=0 onErrorCalls=0

Second after-fix scenario (typing placeholder already deleted upstream: PATCH .../messages/typing → 404, resend create → 500): the recoverable placeholder failure is logged, the resend failure rejects and reaches onError:

stub: PATCH /v1/spaces/AAA/messages/typing -> 404 (typing placeholder gone)
runtime.error: Google Chat message send failed: Error: Google Chat API 404: {"error":{"code":404,...}}
stub: POST /v1/spaces/AAA/messages #1 text="First chunk of the assistant reply." -> 500
runtime.error: [default] Google Chat text reply failed: Error: Google Chat API 500: {"error":{"code":500,...}}
dispatcher: deliveryOutcome=failed-deliver
summary: tokenExchanges=1 messageCreates=1 createStatuses=[500] patchAttempts=1 onErrorCalls=1
BEFORE (origin/main source) AFTER (this PR)
Stub observed 3 real POST .../messages ([200,500,200]) 2 real POST .../messages ([200,500]), third chunk never attempted
deliver result resolved — reply counted delivered, chunk 2 silently dropped rejected with Google Chat API 500: {...}
Dispatcher outcome delivered, onError never fires failed-deliver, onError fires once with the API error
New integration test 2 of 3 tests fail (reverse-verified) 3/3 pass

Before vs after (same regression tests, same mocks)

Scenario origin/main this PR
Non-first chunk send rejects resolves; chunk dropped, loop continues rejects with the send error
Typing update fails, fallback resend rejects resolves; whole reply lost rejects with the resend error
Typing update fails, fallback resend succeeds resends, resolves (kept) resends, resolves (unchanged)

Contract chain (source verified on main)

Layer File Line Mechanism
Channel deliver extensions/googlechat/src/monitor.ts 408-421 deliver: async (payload) => { await deliverGoogleChatReply(...) }
Channel onError extensions/googlechat/src/monitor.ts 425-429 [accountId] Google Chat <kind> reply failed: <err>
Swallowed failure (pre-fix) extensions/googlechat/src/monitor-reply-delivery.ts 95-107 catch logs, drops chunk / swallows fallback failure, loop resolves
Dispatcher contract src/auto-reply/reply/reply-dispatcher.ts 476-483 await options.deliver(...); only .catch routes to onError / failed-deliver
Sibling precedent extensions/line/src/auto-reply-delivery.ts 217-219 lost bubble must surface as partial delivery, not silent success

Control-red (reverse verification)

Reverting only monitor-reply-delivery.ts to origin/main while keeping the new tests:

$ node scripts/run-vitest.mjs extensions/googlechat/src/monitor.reply-delivery-failure.test.ts
 Tests  2 failed | 1 passed (3)
   × surfaces a failed non-first chunk send as a dispatcher-visible delivery failure
   × rejects when the resend after a typing-placeholder update failure also fails
     → Expected: "failed-deliver" / Received: "delivered" (500 logged and swallowed)

The mock-level suite shows the same inversion (2 failed | 4 passed on pre-fix source). With the fix restored, both suites are green.

Test suite

$ node scripts/run-vitest.mjs extensions/googlechat/src/monitor.reply-delivery-failure.test.ts extensions/googlechat/src/monitor.reply-delivery.test.ts
 Test Files  2 passed (2)
      Tests  9 passed (9)

Full extension suite: node scripts/run-vitest.mjs extensions/googlechat → 211 passed / 1 failed (212 total); the single failure (setup.test.ts:236, service-account setup-wizard flow) also fails on a clean origin/main checkout without this change (pre-existing, unrelated — same failure observed in the previous proof round before this PR touched anything).

What was not tested

  • A real Google Chat workspace send (requires live service-account credentials); the loopback impersonator covers the full production HTTP/auth/guard stack instead, including the real error-envelope parsing that builds the Google Chat API 500: ... message.
  • Full-repo tsgo lanes left to CI.

Impact-surface review

File Change Status
extensions/googlechat/src/monitor-reply-delivery.ts chunk loop restructured; send failures now propagate covered by mock-level + integration regression tests
extensions/googlechat/src/monitor.reply-delivery.test.ts +2 rejection tests; existing fallback test unchanged and green 6/6 pass
extensions/googlechat/src/monitor.reply-delivery-failure.test.ts new integration suite: real HTTP stub, before/after dispatcher-visible outcomes 3/3 pass; 2 fail on pre-fix source

Lint / typecheck / format

$ oxlint extensions/googlechat/src/monitor-reply-delivery.ts extensions/googlechat/src/monitor.reply-delivery.test.ts extensions/googlechat/src/monitor.reply-delivery-failure.test.ts   # exit 0
$ tsgo -p test/tsconfig/tsconfig.extensions.test.json (fresh buildinfo)                                                                                                    # 0 errors
$ oxfmt --check <all touched files>                                                                                                                                         # correct format
$ git diff --check origin/main                                                                                                                                              # clean

Base: 76e97dd (origin/main). Head: a1cb28d8b3253761dd48e36bc51f426cd204787c.

Maintainer edits

Allow edits from maintainers is enabled on this PR.

Maintainer options
  • Land-ready: single commit, 3 files, googlechat-only; no core/SDK/config surface touched.
  • Branch rebased onto current origin/main (76e97dd) during this proof round.
  • Scope discipline: only the swallowed-error path in monitor-reply-delivery.ts plus its colocated tests; the typing-fallback success path is byte-for-byte behavior-preserved.

@openclaw-barnacle openclaw-barnacle Bot added channel: googlechat Channel integration: googlechat size: S labels Jul 17, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 6:17 PM ET / 22:17 UTC.

Summary
The branch makes unrecoverable Google Chat reply-chunk sends reject to the reply dispatcher and adds unit plus loopback HTTP regression coverage for the formerly swallowed failures.

PR surface: Source -4, Tests +286. Total +282 across 3 files.

Reproducibility: yes. in source: the supplied loopback HTTP scenario deterministically makes a later Google Chat create request return 500 and traces the resulting dispatcher outcome. This review did not independently execute that scenario.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: vector/embedding metadata: extensions/googlechat/src/monitor.reply-delivery-failure.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Let the pending required checks complete on the exact final merge result before merging.

Risk before merge

  • [P1] The PR is mergeable but behind its base, and multiple required checks were still in progress in the supplied snapshot; merge only after checks validate the exact final merge result.
  • [P1] This intentionally changes Google Chat failure semantics from partial/silent success to dispatcher-visible failed delivery, so rollback and operator error reporting should be considered as a message-delivery behavior change.

Maintainer options:

  1. Merge after final checks (recommended)
    Rebase or use the current merge result and require the pending checks to pass, then merge the focused Google Chat delivery fix.
  2. Pause for live-provider confirmation
    If maintainers require Google Workspace-specific confidence beyond the loopback stack, request a redacted real-service failure-path observation before merging.

Next step before merge

  • [P2] No concrete repair remains for automation; the remaining action is normal maintainer merge gating on the current merge result.

Security
Cleared: The diff changes only Google Chat delivery control flow and tests; it adds no dependency, credential, workflow, permission, or package-resolution surface.

Review details

Best possible solution:

Land the plugin-local propagation fix after the exact rebased merge result passes required checks, preserving the recoverable typing-placeholder resend path and its focused regression coverage.

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

Yes in source: the supplied loopback HTTP scenario deterministically makes a later Google Chat create request return 500 and traces the resulting dispatcher outcome. This review did not independently execute that scenario.

Is this the best way to solve the issue?

Yes. Restricting recovery to the stale typing-placeholder update while allowing the final new-message send to reject is the narrowest way to honor the existing dispatcher delivery contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5e4107400963.

Label changes

Label justifications:

  • P1: A Google Chat reply can currently be counted as delivered after a failed chunk send, affecting real channel delivery reporting.
  • merge-risk: 🚨 message-delivery: The patch changes whether failed Google Chat chunk sends terminate delivery and reach dispatcher error handling.
  • 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 (terminal): The PR body provides after-fix terminal evidence from a loopback HTTP impersonator that drives the production delivery/auth path, observes a real 500 response, and shows failed-deliver plus one onError call; no private credentials are exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix terminal evidence from a loopback HTTP impersonator that drives the production delivery/auth path, observes a real 500 response, and shows failed-deliver plus one onError call; no private credentials are exposed.
Evidence reviewed

PR surface:

Source -4, Tests +286. Total +282 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 18 -4
Tests 2 286 0 +286
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 300 18 +282

What I checked:

Likely related people:

  • ajwan8998: Authored the earlier Google Chat non-OK response propagation proposal, which is relevant context for the API-error behavior this PR now surfaces; the supplied context does not establish current ownership. (role: adjacent Google Chat error-handling contributor; confidence: low; commits: 199ab99f63e8; files: extensions/googlechat/src/api.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-17T19:45:04.363Z sha 40303f55704276dd5ab8c2ba6726f21758e6fbc6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T21:24:16.293Z sha a1cb28d8b3253761dd48e36bc51f426cd204787c :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T22:06:30.716Z sha a1cb28d8b3253761dd48e36bc51f426cd204787c :: needs maintainer review before merge. :: none

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/googlechat-reply-delivery-failure branch from 40303f5 to a1cb28d Compare July 17, 2026 21:20
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressing the [P1] "needs real behavior proof" finding on commit a1cb28d8b3253761dd48e36bc51f426cd204787c (branch also rebased onto current origin/main 76e97ddcdb).

Integration-backed failure-path proof, committed as extensions/googlechat/src/monitor.reply-delivery-failure.test.ts:

  • Drives the real production stack against a loopback Google Chat API impersonator: deliverGoogleChatReply → sendGoogleChatMessage → withGoogleChatResponse → fetchWithSsrFGuard → real google-auth-library JWT signing + token exchange. Only global fetch is stubbed to reroute the two Google hosts; throwaway in-process RSA key, stub-issued token, no real credentials/endpoints.
  • The stub answers the second spaces.messages create with HTTP 500; the dispatcher-visible outcome is captured through the same deliver/onError wiring as monitor.ts:408-429.

Observed dispatcher outcomes (transcripts in the updated PR body Evidence section):

BEFORE (origin/main source) AFTER (this PR)
Stub observed POST .../messages ×3 [200,500,200] POST .../messages ×2 [200,500] — third chunk never attempted
deliver result resolved — counted delivered, chunk 2 dropped rejected: Google Chat API 500: {"error":{"code":500,...}}
Dispatcher delivered, onError 0 calls failed-deliver, onError 1 call with the API error

Second covered scenario: typing-placeholder PATCH → 404 (recoverable, logged) followed by resend POST → 500 → rejects and reaches onError.

Verification on a1cb28d8b3:

  • node scripts/run-vitest.mjs extensions/googlechat/src/monitor.reply-delivery-failure.test.ts extensions/googlechat/src/monitor.reply-delivery.test.ts — 9/9 pass
  • Reverse control: same integration test against pre-fix monitor-reply-delivery.ts from origin/main — 2 failed / 1 passed (proves the test exercises the fixed behavior)
  • node scripts/run-vitest.mjs extensions/googlechat — 211/212; the single failure (setup.test.ts:236 setup-wizard flow) is pre-existing on clean origin/main and unrelated
  • oxlint / oxfmt / git diff --check clean on all touched files

@clawsweeper

clawsweeper Bot commented Jul 17, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Jul 17, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 17, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Fixed the check-test-types failure (TS2345 at monitor.reply-delivery-failure.test.ts:94): the regex match index is string | undefined under noUncheckedIndexedAccess; the PATCH branch now narrows messageMatch?.[1] before pushing.

Validation on the new head (Node 24.15.0): node scripts/run-vitest.mjs extensions/googlechat/src/monitor.reply-delivery-failure.test.ts — 3/3 passed; run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json — 0 errors.

wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Jul 18, 2026
Drive the production inbound stack end to end: real webhook handler,
real verifyGoogleChatRequest, real cert fetch through fetchWithSsrFGuard,
and google-auth-library RS256 verification of an in-process signed JWT,
with only the Google cert host rerouted to a loopback impersonator.
Asserts durable admission after real verification, exactly-once replay
across a simulated restart, and 401 + no journal for a forged signature.
Same proof standard as the accepted openclaw#110147 reply-delivery proof.
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/googlechat-reply-delivery-failure branch from c23d3a4 to 489f39a Compare July 21, 2026 12:57
@clawsweeper

clawsweeper Bot commented Jul 21, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

1 similar comment
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@steipete

Copy link
Copy Markdown
Contributor

Thank you, @wangmiao0668000666! Your Google Chat delivery fix has been merged via #115638, which preserves both of your original author-attributed commits and lands the same three Google Chat files on current main. We also added an independently verified regression fix so a failing outbound-status callback cannot resend an already delivered message. The real OAuth and Google Chat HTTP failure-and-recovery integration suite passed all 28 tests, and the canonical PR passed all hosted merge gates. Closing this original now that your credited fix is safely merged in 26aa0f5. Thank you for the contribution!

@steipete steipete closed this Jul 29, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thank you for taking care of the merge, @steipete! Glad to see the fix landed with the additional regression guard. Appreciate you preserving the original commits.

@wangmiao0668000666
wangmiao0668000666 deleted the fix/googlechat-reply-delivery-failure branch October 28, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: googlechat Channel integration: googlechat merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. 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