Skip to content

improve: avoid repeated runtime setup for Gateway utility calls - #150706

Merged
steipete merged 2 commits into
mainfrom
codex/perf-recap-generation-5152
Sep 17, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-recap-generation-5152

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Recaps and other utility completions can rebuild the same provider runtime for every agent/model selection on a busy Gateway.

User Impact

Utility calls reuse the Gateway's prepared provider when it already covers the requested selection, reducing repeated setup while preserving credential and reload isolation.

Why This Change Was Made

The lease owner now retains the current configured generation for covered static selections. Requests requiring additional plugins or explicit runtime discovery keep their existing preparation path. Existing lease retention keeps an in-flight call valid across reload.

Evidence

  • 90 focused tests passed across owner selection, auth/reload, completion generation and isolated completion. The new covered-provider regression fails on the original code and passes with this change; it also verifies uncovered-provider preparation.
  • The same synthetic 32-agent fixture completed all 76 utility calls, including an unconfigured model, separate auth/model stores, a held call across reload and complete cleanup.
  • Runtime registrations after 64 calls fell from 66 to 2; total registrations across the fixture fell from 80 to 4.
  • Single before/after fixture-body timing: 8.241s to 2.866s. Whole test command: 46.47s to 36.96s. Peak RSS increased from 3,073,840 to 3,179,276 KiB; those command-level figures include Vitest worker compilation. This is component evidence, not a paired live-Gateway or memory-saving claim.
  • Applied the exact patch to main at 5215fe989ff2dd1cab2a331621d24bb669467816: the same 90 focused tests and two existing configured-model-alias cases passed. The nearby alias changes compose correctly; source and private dependency pins remained unchanged.
  • Independent source review, current-main integration review, formal P2 autoreview and exact-head ClawSweeper review completed without actionable findings. Changed checks and exact-head CI passed. The first CI attempt passed all 1,201 tests in one shard but failed during worker teardown; its unchanged fixture passed on recent main and the single exact-head retry passed. No timeout or test expectation changed.

@clawsweeper

clawsweeper Bot commented Sep 17, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 07:13
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 3:55 AM ET / 07:55 UTC (Revision 3).

ClawSweeper review

What this changes

Gateway utility calls reuse a compatible prepared provider runtime instead of rebuilding it for each model selection, with focused reuse and lease-retention coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from the captured main revision. No actionable correctness or security finding was identified, and the previous review has no outstanding concrete findings.

Priority: P2
Reviewed head: f51e760832f8b7459b28cabf79f1c0c8d7714601

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful regression coverage and scoped benchmark evidence; no blocking defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate; the reported isolated-completion fixture covers reuse, separate stores, reload, and cleanup as component evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate; the reported isolated-completion fixture covers reuse, separate stores, reload, and cleanup as component evidence.
Evidence reviewed 9 items Introduced reuse path: The added branch requires static run admission, a current configured snapshot, matching configuration and owner identity, compatible metadata, and complete plugin coverage. Explicit discovery, read-only requests, skipped credentials, and pinned generations retain their existing paths.
Identity and lifetime boundaries: Owner identity includes agent, credential directory, workspace, environment, and binding mode. Borrowing reaches the existing synchronous generation-retention path before yielding; publication and retirement retain their existing ownership.
Current-main necessity: The captured main implementation proceeds directly from pinned-generation handling to exact-key lookup and preparation; it lacks the proposed configured-generation borrowing branch.
Findings None None.
Security None None.

How this fits together

Prepared model runtimes hold the provider registrations, model information, and credential snapshots used by agent completions. The lease owner matches each request to a suitable runtime and retains its resources until the call finishes.

flowchart TD
  A[Utility completion request] --> B[Admit configured agent context]
  B --> C{Current runtime covers selection?}
  C -->|Yes| D[Borrow configured runtime]
  C -->|No or explicit discovery| E[Prepare requested runtime]
  D --> F[Retain lease and execute completion]
  E --> F
  F --> G[Release runtime resources]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +33, Tests +137. Total +170 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 33 0 +33
Tests 2 227 90 +137
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 260 90 +170

Review metrics

Metric Value Why it matters
Reported component setup reduction 66 → 2 registrations after 64 utility calls The paired synthetic fixture supports reduced setup work without claiming a live-Gateway latency or memory improvement.

Technical review

Best possible solution:

Reuse covered selections through the existing lease owner while preserving separate preparation for explicit discovery and uncovered plugins.

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

Not applicable as a functional failure: this is a performance optimization. Source shows selection-keyed preparation, and the PR reports paired component measurements; this read-only review ran no tests or runtime code.

Is this the best way to solve the issue?

Yes. Extending the existing lease owner avoids a competing cache and preserves the current isolation, discovery, and retirement paths.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 98892be36358.

Labels

Label justifications:

  • P2: This is a bounded Gateway performance improvement with a concrete repeated-setup cost and no demonstrated urgent outage.
  • 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: The maintainer-authored internal optimization is exempt from the external-contributor proof gate; the reported isolated-completion fixture covers reuse, separate stores, reload, and cleanup as component evidence.

Evidence

What I checked:

  • Introduced reuse path: The added branch requires static run admission, a current configured snapshot, matching configuration and owner identity, compatible metadata, and complete plugin coverage. Explicit discovery, read-only requests, skipped credentials, and pinned generations retain their existing paths. (src/agents/prepared-model-runtime-lease.ts:230, f51e760832f8)
  • Identity and lifetime boundaries: Owner identity includes agent, credential directory, workspace, environment, and binding mode. Borrowing reaches the existing synchronous generation-retention path before yielding; publication and retirement retain their existing ownership. (src/agents/prepared-model-runtime.owner.ts:270, f51e760832f8)
  • Current-main necessity: The captured main implementation proceeds directly from pinned-generation handling to exact-key lookup and preparation; it lacks the proposed configured-generation borrowing branch. (src/agents/prepared-model-runtime-lease.ts:230, 98892be36358)
  • Latest-release check: Inspection of the lease source at v2026.9.4 found the existing exact-key preparation path and no configuredSnapshot reuse branch; no shipped equivalent was established. (src/agents/prepared-model-runtime-lease.ts:232, 3a9d69db306c)
  • Focused regression coverage: The new test distinguishes covered-provider reuse from uncovered-provider preparation and verifies that configured publication remains intact. Three existing retention cases move into this suite and explicitly request runtime loading so they continue exercising separate run owners. (src/agents/prepared-model-runtime.gateway-leases.test.ts:38, f51e760832f8)
  • Captured performance and validation evidence: The supplied PR body reports 90 passing focused tests and a synthetic 32-agent fixture completing 76 utility calls, including separate stores and a held call across reload. Registrations after 64 calls fell from 66 to 2, fixture time from 8.241s to 2.866s, and command peak RSS increased. These are reported component measurements, not independently executed live-Gateway or memory-saving proof. The supplied sourceRevision is 5ab8750bc6bacc66c958fa1ae0c329dc23c6c91c949862ab2735570756d3d78f. (f51e760832f8)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-17T07:20:59.639Z sha c038b55 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T07:31:04.399Z sha f51e760 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 2b65ee7 into main Sep 17, 2026
375 of 377 checks passed
@steipete
steipete deleted the codex/perf-recap-generation-5152 branch September 17, 2026 08:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…claw#150706)

* improve: reuse configured runtimes for Gateway utility completions

* test: group Gateway prepared-runtime lease coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant