Skip to content

improve(xai): defer optional capability runtimes - #119374

Merged
vincentkoc merged 1 commit into
mainfrom
perf/xai-lazy-capabilities-20260804
Aug 5, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/xai-lazy-capabilities-20260804

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Loading the bundled xAI plugin eagerly pulled image, video, speech, transcription, realtime voice, and OAuth runtimes into ordinary startup even when none of those optional capabilities were used. That made xAI one of the largest avoidable contributors to plugin import time and RSS.

Root Cause And Owner

The xAI registration entrypoint owned runtime construction, static capability metadata, config validation, auth routing, and realtime startup buffering in one eager import graph. The architectural owner is the xAI plugin boundary. Core only gains a narrow production-private audio-queue SDK seam needed by lazy bundled-provider facades.

Canonical Fix

The plugin now registers lightweight metadata-compatible facades synchronously and loads each heavy capability runtime once, on first use. Synchronous validation, provider routing, bounded pre-connect buffers, and close-before-load cleanup stay at the owning xAI boundary.

Realtime voice uses one provider bridge per explicit wrapper generation. All provider callbacks are generation-bound, stale bridges cannot notify or mutate their replacements, startup operations drain in original order, and flush failures emit one terminal error before closing. Audio, user-message, and tool-result queues remain byte/count bounded until direct forwarding begins.

Connected eager policy was removed from the registration path and split into metadata, routing, auth-runtime, and capability-runtime owners. Non-goals: no config, protocol, auth choice, model routing, or storage contract changes. The separate realtime retention work in #116201 is not claimed by this PR.

User Impact

Operators who enable xAI but do not use its optional media, speech, or realtime capabilities pay substantially less startup cost. First capability use loads the same runtime implementation and subsequent calls reuse it.

Evidence

  • Exact current head 31283a6ea3eb86841a7a9a2a1478bc47a2cf080c, rebased onto 866dade2462f0cbb4b6a617cabe09dd5cc6dd2ea: 21 lazy-lifecycle tests and 10 shared realtime SDK tests passed. Formatting and git diff --check are clean.
  • Rebase integrity: the binary patch hash is unchanged at 22accece326d518a28a3a0228a6b5990f8c1850378dc1550553c7e0dec83cba4; the rewritten commit remains signed and retains its Punchcard trailer.
  • Full patch proof before the byte-identical rebase: 149 xAI tests, 26 websocket-session tests, 17 talk-session tests, 10 realtime SDK tests, and 26 SDK/package-boundary contracts passed. The connect-handoff race passed 10/10 bounded repetitions.
  • Build proof: plugin assets, AI/packages/unified bundles, CLI bootstrap imports, runtime postbuild, all 149 public plugin-SDK subpaths, Control UI build, 704 finalized sidecars, and Control UI performance checks passed. The initial UI tail failure was sparse-checkout-only; materializing tracked ui/config files resolved it without a source change.
  • Branch autoreview reported no actionable P0-P2 findings. The final rebase changed no patch bytes and the focused lifecycle/package tests were rerun afterward.
  • Same-host measurement of the lazy import topology: direct xAI import median fell from 2545.38 ms to 1235.46 ms, a 51.46% reduction. The lifecycle repairs do not change the import graph.
  • Kova: 10/10 scenarios and 230/230 obligations passed with no regression, finding, or warning. End-to-end medians remain noisy, so this PR claims the isolated import improvement rather than a stable whole-run speedup.
  • Exact-head hosted CI run 30971443364 is in progress. Exact-head ClawSweeper dispatch 30971442098 succeeded; its current-head Before merge and Rank-up moves remain a hard pre-merge gate.
  • At this refresh, current main 17ef7771a66d21af51d26558a9a01ec7d01a227d adds two post-base commits with zero touched-file overlap; git merge-tree --write-tree produced a clean merge result.
  • Diff accounting against the rebased base: production code +1431/-644 (net +787); tests +900/-13 (net +887); all non-test files +1444/-644 (net +800). The positive production delta is the explicit metadata/runtime ownership split plus bounded, generation-safe realtime lifecycle behavior.

Merge Gate

Do not merge until exact-head required CI is green and the latest ClawSweeper comment has no unresolved Before merge or Rank-up moves items. Every move must be applied or answered in the PR before merge.

AI-assisted: yes. The implementation was manually reviewed, focused and broad tests were run, and structured autoreview completed cleanly.

Punchcard-Session: coral-workshop-workshop-3f

@vincentkoc vincentkoc self-assigned this Aug 4, 2026
@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch from 0cdd90a to 00db86b Compare August 4, 2026 23:47
@vincentkoc
vincentkoc marked this pull request as ready for review August 4, 2026 23:50
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 5, 2026
@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch from 00db86b to c320b61 Compare August 5, 2026 00:04
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 11:18 PM ET / August 5, 2026, 03:18 UTC.

ClawSweeper review

What this changes

The branch replaces eager xAI media, OAuth, speech, video, transcription, and realtime-voice runtime imports with cached lazy facades, plus a narrow private audio-queue SDK seam.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This maintainership-owned PR is still necessary: current main eagerly constructs optional xAI capabilities at registration, while the proposed facades defer those runtimes until use. No actionable patch defect was found, but exact-head CI and maintainer sign-off remain required.

Priority: P2
Reviewed head: 31283a6ea3eb86841a7a9a2a1478bc47a2cf080c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A substantial but coherent owner-boundary refactor with focused lifecycle coverage and stated direct import measurements.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body additionally records direct import measurements and focused lifecycle validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body additionally records direct import measurements and focused lifecycle validation.
Evidence reviewed 6 items Current-main behavior: Current main statically imports and registers xAI image, media, speech, video, transcription, and realtime-voice providers, so the central startup-cost problem remains on main.
Lazy owner boundary: The proposed facade keeps static metadata synchronous and loads each heavy provider only from its capability method, preserving plugin-local ownership.
Lifecycle coverage: The added tests cover deferred builders, ordered startup input, close-before-load handling, generation fencing, and terminal flush failure behavior.
Findings None None.
Security None None.

How this fits together

OpenClaw registers the bundled xAI plugin at startup so its provider metadata can be discovered. Optional capability requests then invoke the relevant xAI runtime, including realtime voice and transcription session setup.

flowchart LR
  A[OpenClaw startup] --> B[xAI plugin registration]
  B --> C[Lightweight capability metadata]
  C --> D[Optional capability request]
  D --> E[Cached lazy runtime]
  E --> F[Media result or realtime session]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind the checkout’s main and hosted exact-head checks are still in progress; refresh mergeability and required checks before landing, without treating base drift alone as a regression.
  • Complete next step (P2) - This protected maintainer-authored PR needs ordinary maintainer approval and completion of exact-head checks, not an automated repair job.
Agent review details

Security

None.

PR surface

Source +790, Tests +887, Docs +1, Config +7, Other +2. Total +1687 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 22 1434 644 +790
Tests 5 900 13 +887
Docs 1 1 0 +1
Config 2 7 0 +7
Generated 0 0 0 0
Other 2 2 0 +2
Total 32 2344 657 +1687

Review metrics

Metric Value Why it matters
Production versus test delta production +1431/-644 (net +787); tests +900/-13 (net +887) The production growth is tied to splitting metadata from capability runtimes and adding bounded, generation-safe lazy lifecycle ownership.

Stored data model

Persistent data-model change detected: serialized state: extensions/xai/lazy-capability-providers.ts, unknown-data-model-change: extensions/xai/capability-provider-metadata.ts, unknown-data-model-change: extensions/xai/speech-provider-metadata.ts, vector/embedding metadata: extensions/xai/capability-provider-metadata.ts, vector/embedding metadata: extensions/xai/image-generation-provider.ts, vector/embedding metadata: extensions/xai/lazy-capability-providers.ts, and 7 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Finish exact-head validation (recommended)
    Land only after the current head’s required checks complete successfully and the clean GitHub merge result is refreshed.
  2. Pause on a first-use regression
    Pause this PR if exact-head validation exposes a failed lazy capability load or realtime lifecycle regression.

Technical review

Best possible solution:

Merge after exact-head CI is green and a maintainer accepts the first-use lifecycle behavior as preserving xAI capability semantics.

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

Not applicable: this PR improves optional xAI startup behavior rather than repairing a reported current-main failure.

Is this the best way to solve the issue?

Yes. Current main eagerly creates the optional providers, while the plugin-local facades retain synchronous metadata and defer only capability runtimes; this is preferable to a provider-specific core workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded optional-provider performance and lifecycle improvement with no demonstrated widespread failure.
  • merge-risk: 🚨 availability: A lazy-load or first-use lifecycle regression could prevent an enabled xAI optional capability from starting.
  • 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. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body additionally records direct import measurements and focused lifecycle validation.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Authored the current PR and recent xAI/Google realtime queue-order work. (role: recent area contributor; confidence: high; commits: 31283a6ea3eb, 213c05182f29, 24e6354ec2c6; files: extensions/xai/lazy-capability-providers.ts, extensions/google/index.ts, src/talk/realtime-session-lifecycle.ts)
  • steipete: Introduced the shared realtime voice session harness that owns the queue implementation exposed by this PR. (role: shared realtime harness introducer; confidence: high; commits: e3618454f245; files: src/talk/realtime-session-lifecycle.ts)
  • omarshahine: Recently maintained the shared realtime lifecycle and authorization path adjacent to this seam. (role: recent shared lifecycle contributor; confidence: medium; commits: 5db7e1c4ecae; files: src/talk/realtime-session-lifecycle.ts)

Rank-up moves

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

  • Let exact-head hosted CI complete and refresh the final mergeability check before landing.

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 (4 earlier review cycles)
  • reviewed 2026-08-05T00:11:47.833Z sha c320b61200b76ffe2ac8ee6f617d332c4d4876bf :: found issues before merge. :: [P2] Bound pending user-message bytes | [P2] Bound pending tool-result payloads
  • reviewed 2026-08-05T01:03:09.475Z sha e53a266 :: needs changes before merge. :: [P2] Keep facade input bounded until voice connect completes | [P3] Document the private realtime audio queue seam
  • reviewed 2026-08-05T02:04:44.546Z sha cd6f6bc012df0bd101e6cc677ef0f0e57a296b90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T03:04:59.097Z sha cdb3bcb4ee7cb074fb8c21b868ab44fb59f94036 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch 5 times, most recently from e53a266 to e509f1b Compare August 5, 2026 01:16
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 5, 2026
@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch 2 times, most recently from 351eaba to cd6f6bc Compare August 5, 2026 01:49
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 5, 2026
@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch from cd6f6bc to cdb3bcb Compare August 5, 2026 02:34
Punchcard-Session: coral-workshop-workshop-3f
@vincentkoc
vincentkoc force-pushed the perf/xai-lazy-capabilities-20260804 branch from cdb3bcb to 31283a6 Compare August 5, 2026 03:09
@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper merge-gate resolution for reviewed head 31283a6ea3eb86841a7a9a2a1478bc47a2cf080c:

  • Resolve merge risk: resolved. The exact-head CI run completed successfully, all 130 checks are complete with 0 failures and 0 pending, and required openclaw/ci-gate passed: https://github.com/openclaw/openclaw/actions/runs/30971443364
  • Refresh mergeability: resolved. Against current main bf1bdb429ece74655e0ebcfca1dc1273432b702b, the merge tree is clean and the base-to-main/base-to-head touched-file intersection is 0: bf1bdb4
  • scripts/pr merge-verify 119374 passes. Its advisory drift is the unrelated TUI PTY CI ownership change in fix(ci): stabilize TUI PTY proof ownership #119420; that change does not touch the xAI, plugin SDK, or realtime-session surfaces in this PR and does not alter their validation contract.
  • Complete next step: resolved. This is a maintainer-authored PR, and the maintainer has explicitly accepted the first-use lifecycle behavior and requested landing. GitHub cannot record a separate self-approval on an author-owned PR; this note records that acceptance. Exact-head checks are complete.
  • Rank-up move: applied. Hosted CI completed and final mergeability was refreshed immediately before landing.
  • The exact-head ClawSweeper review reports no findings: improve(xai): defer optional capability runtimes #119374 (comment)

All listed Before merge items and the Rank-up moves item are resolved. Proceeding with the repo-native squash merge.

@vincentkoc
vincentkoc merged commit e35d228 into main Aug 5, 2026
130 checks passed
@vincentkoc
vincentkoc deleted the perf/xai-lazy-capabilities-20260804 branch August 5, 2026 03:26
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 5, 2026
* origin/main:
  fix(channels): honor explicit preview streaming settings
  refactor(telegram): consolidate outbound contracts and targets (#119438)
  fix(qa): retry transport cleanup and always stop owned labs (#119442)
  fix(mcp): guard stdio stdout frame parsing against oversized-buffer crash (#119379)
  refactor(auto-reply): centralize delivery deduplication and routing (#119436)
  fix(qa): preserve scenario isolation in serial suites (#119439)
  perf(xai): lazy-load optional capability runtimes (#119374)
  refactor(browser): consolidate browser CLI and normalization helpers (#119432)
  fix(qa): require ready transport accounts (#119431)
  refactor(media): share image and video geometry normalization (#119416)
  fix(config): preserve plugin metadata for missing config (#119421)
  fix: retry delivery when outbound adapter is unavailable (#119371)
  fix(cli): retire invalid secret flags and prove doctor recovery (#118926)
  refactor(signal): share outbound and reaction transport (#119415)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
Punchcard-Session: coral-workshop-workshop-3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: google extensions: xai maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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