Skip to content

refactor: speed up cold Google policy checks - #140922

Merged
steipete merged 2 commits into
mainfrom
codex/perf-google-policy-classifiers
Sep 7, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-google-policy-classifiers

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where cold Google model-policy checks load unrelated streaming machinery. In a matched source-layout PDF run, the policy lookup alone took 12.65 seconds.

Why This Change Was Made

Move the existing boundary-aware Gemini 3 classifiers into one lightweight AI internal entry shared by policy, thinking-payload normalization, and OpenAI-compatible replay. Delete the equivalent transport helper definitions. Google policy uses the existing narrow thinking SDK entry; historical streaming-SDK exports retain their names and behavior.

The package export, TypeScript path, dedicated AI build entry, and native source-loader alias are wired together. The native alias retains the existing host-parent boundary. No dependency, configuration option, model-policy change, or public SDK subpath is added. Runtime TypeScript grows by three lines; package/build wiring adds nine. The native Google adapter's separate unanchored predicates retain their semantics.

User Impact

Cold policy checks avoid unnecessary streaming imports. Provider selection, thinking mappings, replay signatures, and PDF runtime-generation ownership remain unchanged. Source development and packaged runtimes both resolve the classifier entry. Shard configuration and existing test coverage are preserved.

Evidence

  • Matched source-layout PDF runs: all six original cases passed in order. Direct policy lookup 12,648.85ms → 205.33ms; committed-generation case 12,862ms → 797ms. Whole commands were 51.57s and 57.77s because worker preparation varied; this is a case improvement, not a whole-command speedup claim.
  • Existing policy, thinking-payload, replay-signature, and unchanged PDF tests: 60 passed across four files. The policy test now rejects an import of the broad streaming SDK; restoring the old import produces that exact failure.
  • With generated root and AI build outputs absent: 24/24 passed across PDF, OpenCode context, and native resolver tests. The final PDF case took 199ms. The source alias fixture resolves for host parents and remains unavailable to unrelated plugin parents. Removing the alias reproduces the missing module and OpenCode's incorrect 200,000-token fallback; the repair restores the expected 1,000,000 without changing its assertion.
  • Full pnpm build passed after the source-alias repair, including declarations, SDK exports, and native built control-plane checks. Cold built-policy import passed in 22ms, loading ten files with no streaming/transport/host regions. Built historical SDK exports and isolated Google entrypoint loading also passed.
  • Full changed-code checks passed through typechecking and all three dead-export scans. Import-order lint errors were corrected and focused canonical lint plus the remaining import-cycle check passed. The added source-alias repair passed focused typecheck/lint. Final independent P0–P2 review: no actionable findings.

The first CI head exposed the omitted native source alias, which a local full build had hidden by supplying the compiled file. The source-only controls above specifically reproduce and repair that gap. That run also reported one invalid UI transition frame; the UI assertion is preserved and its cause remains unproven. Exact-head CI must pass before landing. Temporary timing instrumentation is not included. No authenticated provider API call was used as proof; no provider API behavior changed.

Share the existing Gemini classifiers through a lightweight AI entry so policy checks avoid streaming imports. Preserve historical SDK names and thinking/replay behavior; retain the existing policy cases with an import-boundary regression guard.
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 7, 2026 06:25
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 3:21 AM ET / 07:21 UTC.

ClawSweeper review

What this changes

Shares lightweight Gemini model classifiers so Google policy checks avoid loading streaming machinery, while preserving existing exports and supporting source-only loading.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful: fetched main and the latest release still take the broad streaming import path. The source-loader repair addresses the reported follow-up failure, and no actionable patch defect remains.

Likely related people: steipete, supported by prior provider-helper and loader work.

Priority: P2
Reviewed head: 5c9f2ef597c2e15acb6a8a8f3bd715a79c8b17ba

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with relevant reported runtime measurements and a repaired source-loading gap.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports the actual Google policy import path in source and built layouts, including reduced lookup time and a built import without streaming dependencies; source-only alias controls and historical-export checks supplement that directly relevant observation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports the actual Google policy import path in source and built layouts, including reduced lookup time and a built import without streaming dependencies; source-only alias controls and historical-export checks supplement that directly relevant observation.
Evidence reviewed 7 items Optimization remains absent from fetched main: Google policy still imports thinking-api, which re-exports from provider-stream-shared and therefore loads streaming dependencies.
Latest release retains the same import path: The supplied latest release, v2026.9.2, also imports the classifiers through thinking-api; this is not an already-shipped optimization.
Re-review repair is narrowly introduced: Compared with the previously reviewed head, the new commit adds the internal source alias and extends the existing resolver test to verify host resolution and rejection from unrelated plugin parents.
Findings None None.
Security None None.

How this fits together

Google provider policy turns model identifiers and configuration into normalized settings and thinking options. The same model classifiers also guide outgoing thinking payloads and replay formatting.

flowchart TD
  A[Model identifiers and configuration] --> B[Google policy entry]
  B --> C[Lightweight model classifiers]
  C --> D[Normalized settings and thinking options]
  E[Thinking payload preparation] --> C
  F[Conversation replay formatting] --> C
  G[Source loader or packaged entry] --> C
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +14, Docs 0, Config +8, Other +1. Total +26 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 45 42 +3
Tests 2 15 1 +14
Docs 1 1 1 0
Config 2 8 0 +8
Generated 0 0 0 0
Other 1 1 0 +1
Total 15 70 44 +26

Review metrics

Metric Value Why it matters
Reported cold policy lookup 12,648.85ms → 205.33ms The matched measurement supports the targeted import-cost improvement; the body explicitly avoids claiming a whole-command speedup.

Technical review

Best possible solution:

Keep one lightweight classifier implementation with consistent source and packaged resolution, preserving existing policy, replay, and export behavior.

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

Not applicable as a functional bug reproduction: this is a performance refactor, with the broad import chain confirmed in source and matched timing observations supplied in the body.

Is this the best way to solve the issue?

Yes. Consolidating equivalent classifiers behind an existing narrow helper removes unnecessary loading without changing model policy or adding configuration.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement to cold Google policy checks.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports the actual Google policy import path in source and built layouts, including reduced lookup time and a built import without streaming dependencies; source-only alias controls and historical-export checks supplement that directly relevant observation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the actual Google policy import path in source and built layouts, including reduced lookup time and a built import without streaming dependencies; source-only alias controls and historical-export checks supplement that directly relevant observation.

Evidence

What I checked:

  • Optimization remains absent from fetched main: Google policy still imports thinking-api, which re-exports from provider-stream-shared and therefore loads streaming dependencies. (extensions/google/provider-policy.ts:15, 2d58961f33fd)
  • Latest release retains the same import path: The supplied latest release, v2026.9.2, also imports the classifiers through thinking-api; this is not an already-shipped optimization. (extensions/google/provider-policy.ts:15, 3928bad9badf)
  • Re-review repair is narrowly introduced: Compared with the previously reviewed head, the new commit adds the internal source alias and extends the existing resolver test to verify host resolution and rejection from unrelated plugin parents. (src/plugins/plugin-sdk-native-resolver.ts:85, 5c9f2ef597c2)
  • Classifier and compatibility boundary: The shared predicates retain the original boundary-aware regular expressions and string normalization. Existing Google and streaming-SDK export names remain available. Provider-thinking-runtime is documented as a private helper; the AI README explicitly limits internal subpaths to OpenClaw. (packages/ai/src/internal/google-model-family.ts:3, 5c9f2ef597c2)
  • Source and packaged resolution align: Package exports, the dedicated AI build entry, TypeScript paths, and the native alias point to the same classifier module. Native aliases retain the existing OpenClaw-owned parent-root check. (src/plugins/plugin-sdk-native-resolver.ts:315, 5c9f2ef597c2)
  • Behavioral evidence and author follow-up: The complete captured body reports policy lookup improving from 12,648.85ms to 205.33ms and a built-policy import taking 22ms across ten files without streaming regions. It separately reports source-only regression controls, preserved historical exports, and successful build validation. The follow-up explains the missing-alias reproduction and restored context behavior: refactor: speed up cold Google policy checks #140922 (comment). These are contributor-reported observations, not reviewer-executed tests; no omitted body ranges or linked proof artifacts were supplied. (5c9f2ef597c2)

Likely related people:

  • Peter Steinberger: Raw commit a25cd27 adds src/plugin-sdk/provider-thinking-runtime.ts:6 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a25cd272ec65; files: src/plugin-sdk/provider-thinking-runtime.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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-07T06:32:37.817Z sha b93c1d6 :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Sep 7, 2026
Register the new AI internal entry in the native source alias table. Extend the existing host-parent resolution boundary test and verify PDF and provider context behavior without generated root or AI build outputs.
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added the missing native source-loader alias after CI exposed it. With generated root and AI outputs absent, all 24 PDF/context/native-resolver cases pass; removing the alias reproduces the missing module and incorrect context fallback. The full rebuild, focused typecheck/lint, and final independent review pass. Existing UI transition assertions remain unchanged; waiting for the new head's CI.

@clawsweeper

clawsweeper Bot commented Sep 7, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 0771a88 into main Sep 7, 2026
193 checks passed
@steipete
steipete deleted the codex/perf-google-policy-classifiers branch September 7, 2026 07:48
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
* refactor: speed up cold Google policy checks

Share the existing Gemini classifiers through a lightweight AI entry so policy checks avoid streaming imports. Preserve historical SDK names and thinking/replay behavior; retain the existing policy cases with an import-boundary regression guard.

* fix: resolve Google classifiers in source-only plugin loads

Register the new AI internal entry in the native source alias table. Extend the existing host-parent resolution boundary test and verify PDF and provider context behavior without generated root or AI build outputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

1 participant