Skip to content

improve(googlechat): avoid duplicate DM route reads - #128359

Merged
steipete merged 1 commit into
mainfrom
codex/perf-googlechat-dm-metadata-current
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-googlechat-dm-metadata-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where ordinary Google Chat direct-message sends performed a redundant space lookup while preparing the outbound session route. Resolving a user target already returns the full direct-message Space, but routing discarded that metadata and immediately fetched the same space again only to classify it.

Why This Change Was Made

The private target resolver now carries the provider-returned Space alongside its canonical name so session routing can reuse its type metadata. Explicit space targets and missing or unclassified metadata retain the existing spaces.get fallback; the exported string resolver and the separate send-boundary user-to-space resolution are unchanged.

No cache, retry, idempotency, config, protocol, security, storage, or public SDK behavior changes. AI-assisted implementation and verification.

User Impact

Direct-message session routing uses one provider read instead of two before delivery, reducing route preparation latency and Google Chat API traffic. Message text, cards, thread projection, route identity, and error behavior remain unchanged.

Evidence

  • Exact current-main regression: the focused provider-boundary test failed before the production change with expected vi.fn() to be called once, but got 2 times; it passes with one exact spaces:findDirectMessage request after the change.
  • Controlled route benchmark from the independently frozen defect lane (40 iterations, 5 ms/provider read): 80 → 40 reads and 464.0 → 250.0 ms (50% fewer reads, 46.1% lower route elapsed). Current-main code reproduced the same deterministic 2 → 1 request differential.
  • Owner + action/channel siblings: 3 files, 75 tests passed.
  • Full Google Chat extension: 30 files, 331 tests passed.
  • node scripts/check-changed.mjs -- extensions/googlechat/src/targets.ts extensions/googlechat/src/targets.outbound-session.test.ts passed (format, production/test typechecks, type-aware lint with 0 findings, dead exports, boundaries, guards, and import cycles).
  • git diff --check passed.
  • Build was not classified: no package, build output, dynamic import, or published-surface change.
  • Fresh autoreview: TruffleHog clean; Codex gpt-5.6-sol / high reported no actionable findings and patch is correct at 0.99 confidence.
  • Live provider mutation was not performed because no Google Chat credentials were available; the defect and regression are fully observable before the send boundary.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: googlechat Channel integration: googlechat size: S maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 20:41
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 4:47 PM ET / 20:47 UTC.

ClawSweeper review

What this changes

This PR lets Google Chat outbound session routing reuse direct-message Space metadata to avoid a redundant provider read before delivery.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still performs the direct-message lookup followed by a second space read; this branch reuses the already-returned Space only for route classification while preserving the public string resolver and fallback read.

Priority: P3
Reviewed head: 3d9447ca6dabd1ef67e8d837d2e63d915b29ab70

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with a credible regression test and no actionable correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless describes a focused after-fix transport-boundary test, but no authenticated Google Chat run is attached.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless describes a focused after-fix transport-boundary test, but no authenticated Google Chat run is attached.
Evidence reviewed 6 items Current-main redundant read: Current main resolves a user target through the outbound-space resolver, then unconditionally fetches the resolved space again for classification; the resolver's user branch already obtains the direct-message Space.
Owner-boundary repair: The branch keeps the exported string resolver unchanged, carries the Space only through a private details resolver, and retains the existing fallback read when metadata is absent or unclassified.
Provider response contract in current code: The existing Google Chat API helper returns a GoogleChatSpace from findDirectMessage, whose declared shape includes name and classification fields; this change consumes that same in-process response rather than adding an API call or protocol surface.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/googlechat/src/targets.outbound-session.test.ts

Result: FAIL (partial) — step 2 expect_output reuses direct-message metadata for route classification: expected terminal output was not visible within 30 seconds: "reuses direct-message metadata for route classification"

node scripts/run-vitest.mjs extensions/googlechat/src/targets.outbound-session.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128359-OLYrXh/target$ node scripts/run-vitest.mjs extensions/googlechat/src/targets.outbound-session.test.ts
node scripts/run-vitest.mjs extensions/googlechat/src/targets.outbound-session.test.ts
[test] starting test/vitest/vitest.extension-messaging.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128359-OLYrXh/target

 ✓  extension-messaging  extensions/googlechat/src/targets.outbound-session.test.ts (1 test) 49ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  20:48:41
   Duration  11.27s (transform 8.92s, setup 972ms, import 9.89s, tests 49ms, environment 0ms)

[test] passed 1 Vitest shard in 16.88s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128359-OLYrXh/target$ node scripts/run-vitest.mjs extensions/googlechat/src/targets.outbound-session.test.ts
[test] starting test/vitest/vitest.extension-messaging.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128359-OLYrXh/target

 ✓  extension-messaging  extensions/googlechat/src/targets.outbound-session.test.ts (1 test) 39ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  20:48:58
   Duration  5.56s (transform 3.25s, setup 453ms, import 4.81s, tests 39ms, environment 0ms)

[test] passed 1 Vitest shard in 11.23s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128359-OLYrXh/target$






















Assertions:

  • FAIL expect_output: reuses direct-message metadata for route classification

How this fits together

The Google Chat plugin resolves an outbound target into a session route before the generic channel layer delivers a message. That route supplies direct/group classification and the canonical peer identity used by downstream session handling.

flowchart LR
  A[Outbound target] --> B[Google Chat target resolver]
  B --> C[Direct-message Space lookup]
  C --> D[Session route classification]
  D --> E[Channel session route]
  E --> F[Outbound delivery]
Loading

Before merge

  • Resolve merge risk (P1) - The direct Google Chat documentation and authenticated API path could not be independently reached during this read-only review; the branch relies on the already-existing decoded Space contract and should retain its exact-head focused test evidence.
  • Resolve merge risk (P1) - Production code is net +14 lines; that growth is justified only because the private details resolver preserves the exported string-only resolver and existing send-boundary callers.
  • Complete next step (P2) - This is an active maintainer-authored PR with no concrete repair task for the automation lane.
Agent review details

Security

None.

PR surface

Source +14, Tests +65. Total +79 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 14 +14
Tests 1 65 0 +65
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 93 14 +79

Review metrics

Metric Value Why it matters
Production versus test LOC production +28/-14 (net +14); tests +65/-0 The production addition is a private resolver split that avoids changing the exported string contract; the added test covers the direct-message route boundary.

Stored data model

Persistent data-model change detected: serialized state: extensions/googlechat/src/targets.outbound-session.test.ts, vector/embedding metadata: extensions/googlechat/src/targets.outbound-session.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the private metadata-carrying resolver, retain fallback classification for explicit or unclassified spaces, and land with the focused route test protecting the one-read invariant.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the private metadata-carrying resolver, retain fallback classification for explicit or unclassified spaces, and land with the focused route test protecting the one-read invariant.

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

Yes, from current source: a users/* route performs findDirectMessage and then getGoogleChatSpace before classification. The focused regression test gives a deterministic one-versus-two-read path, although this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the response at the producer is the narrowest fix; caching or changing send-boundary resolution would broaden behavior without addressing the discarded route-classification metadata.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a small latency and API-traffic improvement in the optional Google Chat channel path.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless describes a focused after-fix transport-boundary test, but no authenticated Google Chat run is attached.

Label justifications:

  • P3: This is a small latency and API-traffic improvement in the optional Google Chat channel path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless describes a focused after-fix transport-boundary test, but no authenticated Google Chat run is attached.

Evidence

What I checked:

  • Current-main redundant read: Current main resolves a user target through the outbound-space resolver, then unconditionally fetches the resolved space again for classification; the resolver's user branch already obtains the direct-message Space. (extensions/googlechat/src/targets.ts:103, e4bf24246170)
  • Owner-boundary repair: The branch keeps the exported string resolver unchanged, carries the Space only through a private details resolver, and retains the existing fallback read when metadata is absent or unclassified. (extensions/googlechat/src/targets.ts:71, 3d9447ca6dab)
  • Provider response contract in current code: The existing Google Chat API helper returns a GoogleChatSpace from findDirectMessage, whose declared shape includes name and classification fields; this change consumes that same in-process response rather than adding an API call or protocol surface. (extensions/googlechat/src/api.ts:297, 3d9447ca6dab)
  • Runtime entry point: The bundled Google Chat plugin registers this resolver as its outbound session-route hook, so the changed path is confined to session-route preparation rather than send-boundary target resolution. (extensions/googlechat/src/channel.ts:88, 3d9447ca6dab)
  • Focused regression coverage: The added test exercises the actual local API helper through its guarded transport mock, asserts the direct route shape, and observes one findDirectMessage request. (extensions/googlechat/src/targets.outbound-session.test.ts:33, 3d9447ca6dab)
  • Feature provenance: Blame ties the current-main double-read route to the commit that introduced this target-routing module; this is a likely performance regression, not a user-visible delivery failure. (extensions/googlechat/src/targets.ts:103, 6cde399d5279)

Likely related people:

  • steipete: Current-main blame attributes the route that performs the second lookup to this author, and the introducing commit is retained in the local history. (role: introduced the current routing behavior and recent area contributor; confidence: high; commits: 6cde399d5279; files: extensions/googlechat/src/targets.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

Copy link
Copy Markdown
Contributor Author

Land-ready at exact head 3d9447ca6dabd1ef67e8d837d2e63d915b29ab70.

ClawSweeper before-merge dispositions:

  • API/authenticated-path merge risk: accepted. findGoogleChatDirectMessage already decodes the provider response as the existing GoogleChatSpace contract, including name, spaceType, deprecated type, and singleUserBotDm. The patch consumes that same in-process response only for route classification and retains spaces.get when metadata is missing or unclassified. No Google Chat credentials were available for a live mutation; the exact guarded-fetch boundary reproduces the defect before provider send.
  • Production net +14: accepted. The private details resolver is the smallest canonical prepared-fact propagation that preserves the exported string-only resolver and every existing send/action caller. A cache adds lifecycle semantics, widening the exported result churns unrelated callers, and duplicating target normalization creates a second owner. ClawSweeper independently confirmed this as the best solution.
  • Maintainer-authored next step: complete. Repository-native review artifacts validated READY FOR /prepare-pr with zero findings, and native prepare retained the exact PR head without rebasing.

Two review-report clarifications:

  • The reported live-verification “partial failure” is an output-matcher artifact, not a test failure. Its own transcript shows the focused test passed twice (1 passed, then [test] passed 1 Vitest shard); only the harness search for the individual test title timed out under the non-verbose reporter.
  • The stored-data-model entries are false positives from the new *.test.ts filename. This PR changes no serialization, vector metadata, storage, schema, migration, config, or protocol surface.

Verification:

  • Current-main red: classified DM route made 2 provider reads; exact-head green: 1 exact spaces:findDirectMessage read with the same route.
  • Owner/action/channel siblings: 3 files, 75 tests passed.
  • Full Google Chat plugin: 30 files, 331 tests passed.
  • Changed-file gate passed format, production/test typechecks, type-aware lint (0 findings), dead exports, boundaries, guards, and cycles.
  • Fresh Codex Sol/high autoreview clean at 0.99 confidence; TruffleHog clean.
  • Exact-head CI green: https://github.com/openclaw/openclaw/actions/runs/32665174583
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128359 passed in hosted exact-head mode; no behavior-changing rebase occurred.

No actionable correctness, security, compatibility, or process item remains.

@steipete
steipete merged commit 388e83d into main Aug 23, 2026
170 of 171 checks passed
@steipete
steipete deleted the codex/perf-googlechat-dm-metadata-current branch August 23, 2026 21:05

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: googlechat Channel integration: googlechat maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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