Skip to content

improve: copy only the selected model for agent completions - #206287

Merged
vincentkoc merged 1 commit into
mainfrom
perf/selected-store-for-acquired-completions
Nov 27, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
perf/selected-store-for-acquired-completions

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

An agent-scoped simple completion selects a provider and model, then deep-copies every model in the prepared catalog before resolving that one selection. Local model commands and other callers of the same helper pay this cost on each acquisition.

User Impact

The built-in resolver can start with the selected catalog row. A provider that needs a sibling model or enumerates the catalog still receives its captured inventory. Custom resolvers keep the full, mutable request-local registry and credential store they receive today.

Why This Change Was Made

Prepared simple completions already let the built-in resolver open its model stores after normalizing the selection. The agent acquisition path now uses the same option. Credential selection, route materialization and the lifetime of the acquired model still have their existing owners.

Evidence

  • A source-level probe exercised the acquisition context, the built-in store-selection block and the production registry fork with synthetic catalogs. With 1,024 rows, the initial copy went from 1,024 rows to one. With a one-row catalog, both copied one. Later enumeration preserved the selected object and exposed sibling rows. Both versions kept the same full mutable stores on repeated custom resolver calls.
  • The regression assertions cover normalized rows through the public agent acquisition path and store identity across custom route rematerialization.
  • A physical ARM64 device returned all 13 expected replies from a synthetic loopback endpoint, including one seed. With two cold sessions per version in ABBA order, mean launch to visible reply fell from 70.539 s to 67.818 s (3.86%). Both candidate cold sessions were faster than both baseline sessions. The four warm replies per version averaged 5.621 s and 5.544 s. After 45 s idle, the means were 5.399 s and 5.520 s. A warm improvement remains unresolved. The runs excluded real OpenAI network time, recorded no OOMs and left the daily installation in place.
  • The device comparison exercised the foreground local infer model run action and recorded its loopback replies and timing. The registry copy counts above came from the separate instrumented catalog probe. The device run kept the same timing observer in both versions, so it produced no per-row copy log.
  • The exact-head Bun jobs passed 36 tests across the public agent, worker, isolated completion, custom resolver and generation paths. Pinned formatting, the native commit hook and scoped P0–P2 review passed. Selected-model tests · Runtime and generation tests
  • Both Linux Node 24 jobs built the runtime and Control UI with private QA enabled and declaration emission skipped. The planner skipped the standalone package build. This change uses an existing internal option and preserves the public type and package exports. First runtime build · Second runtime build
  • Ready-for-review CI passed on this head. The earlier draft run reported three unused exports also present on scheduled main and a Bun Gateway compaction hot-reload failure during plugin teardown. Ready CI · Draft CI · Scheduled main dependency check

@vincentkoc vincentkoc self-assigned this Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 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: XS labels Nov 27, 2026
@clawsweeper clawsweeper Bot added the P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. label Nov 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 27, 2026 02:04
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR enables selected-row model-store creation for built-in agent completion resolution while preserving full stores for custom resolvers.

Example: Acquire selected-completion/entry from the three-row alias fixture, which selects middle.

  • Before: Preparation initially copies all three catalog rows and completes with middle.
  • After: Preparation initially copies only middle and returns the same completion.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) A minimal, source-supported optimization with passing exact-head CI, limited by an unverified connection between the device report and the changed production path.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Local model commands and other agent completion callers copy an entire prepared catalog when they need only one selected model.
Reason: The maintainer-authored direction removes demonstrable copying through an existing internal option without adding configuration or changing public interfaces.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR makes a focused performance improvement still absent from main, with no concrete correctness or security findings.

Reviewed head: 1f7b428af42968bf5e9ca4f3c37f1ab7415ac2d9

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs from a shipped local model command exercising this acquisition path with a multi-row catalog, showing preserved replies and reduced copying; base-red/head-green execution of the new acquisition assertion is also not shown.
Agent review details

How this fits together

Agent completion acquisition captures a runtime generation, resolves the selected model and credentials, and returns an executable model whose lease lasts through completion.

flowchart LR
  A[Completion caller] --> B[Agent acquisition]
  B --> C[Prepared runtime generation]
  C --> D[Resolver context]
  D --> E[Built-in selected-row stores]
  D --> F[Custom resolver full stores]
  E --> G[Prepared completion]
  F --> G
Loading

Technical review

Best possible solution:

Keep the existing selected-row mechanism enabled at acquisition, preserving custom resolver stores and lazy catalog expansion.

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

Source establishes that main eagerly creates full stores before built-in acquisition resolution; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The one-line production change reuses the existing optimization at the missing entry point and leaves credential, routing, catalog expansion, and lease ownership with their current owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5b6cc381e1d0.

Provenance checked

  • Agent completion store creation changes intended behavior with a stated reason (8610cd6: The prior optimization retained full mutable stores for agent runs and custom SDK resolvers while narrowing isolated completion preparation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4a0be71 adds src/agents/simple-completion-runtime.ts:638 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4a0be71e57ab; files: src/agents/simple-completion-runtime.ts)
  • leilei3167: Raw commit 6e1bc0b adds src/agents/simple-completion-runtime.ts:610 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 6e1bc0b2fffd; files: src/agents/simple-completion-runtime.ts)

PR surface

Source +1, Tests +7. Total +8 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 2 7 0 +7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 8 0 +8

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Attach shipped-entry-point output connecting a multi-row catalog acquisition to the reduced copy count and unchanged completion result.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 26, 2026, 9:33 PM ET / November 27, 2026, 02:33 UTC.

@vincentkoc
vincentkoc merged commit 9a7f128 into main Nov 27, 2026
315 of 319 checks passed
@vincentkoc
vincentkoc deleted the perf/selected-store-for-acquired-completions branch November 27, 2026 02:49
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Nov 27, 2026
* commit '7df6cb759f9e604921536a700e2f527c5516e7de': (185 commits)
  docs: clarify what telemetry OpenClaw sends and how to opt out
  refactor(ui): remove retired stream-follow test seams (#206316)
  fix: distinguish missing command results from unknown outcomes (#206313)
  fix(build): reuse stamps after identical pnpm installs (#206282)
  chore(ci): inventory Gateway model catalog worker lifecycles (#206251)
  fix: keep failed image inspections inside chat activity (#206283)
  fix: clarify sent-message labels and chat activity icons (#206048)
  fix(cron): use the service's free memory for extra automation runs (#206322)
  test(android): reuse the shared TLS fixture (#206280)
  fix(ui): restore New Session recovery during startup (#206319)
  test(macos): align new Gateway URL expectations (#206281)
  feat: let doctor --fix tell when its startup repairs have nothing to do (#206246)
  fix(android): pause idle gateway discovery without blocking consumers (#196209)
  fix(ci): prepare the Android SDK for scheduled CodeQL scans (#203843)
  fix(memory): read delegated cgroup pressure from the mapped leaf (#206308)
  improve(config): reuse plugin metadata during auto-enable (#206289)
  improve: copy only the selected model for agent completions (#206287)
  fix(pr): refresh tooling before preparing reviewed incoming PRs (#206236)
  fix: keep Gateway ready while plugins drain after updates (#206299)
  fix(crabbox): keep unused prepared mirrors reusable (#206267)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS 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