Skip to content

fix(agents): reduce memory used by background model discovery - #167282

Merged
RomneyDa merged 1 commit into
mainfrom
fix/catalog-worker-harness-scope
Oct 10, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/catalog-worker-harness-scope

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Background provider-model discovery unnecessarily loads native agent-harness execution code into its worker, duplicating runtime graphs and increasing memory use.

User Impact

Less memory during background model discovery, without removing native model choices. No configuration, schema, dependency, or migration changes.

Why This Change Was Made

Keep the catalog worker within its eligible provider-plugin scope. Native harness observations remain with the existing parent owner. Normal agent selection and main’s newer isolated-completion selection are unchanged.

This forward-ports the reviewed release repair, with the condition adapted to preserve main’s additional load purpose.

Evidence

  • Extended the existing four catalog-scope cases with declared harness metadata. They failed on the original release implementation by adding a harness outside the requested provider scope, then passed after the repair.
  • Current-main proof: 78 tests across five owner/sibling files passed, including native catalog preservation, concurrent native/provider renewal, scoped discovery, and isolated-completion registry behavior. Combined wrapper wall time: 126.34 seconds, including its required build.
  • pnpm test src/agents/harness/runtime-plugin.test.ts --maxWorkers=1: 47 passed; 10.11 seconds wall time. CI timing has not yet been observed. No new test cases, timers, or process fixtures were added.
  • Complete changed gate passed; canonical build completed; independent P0–P2 review was clean.
  • Equivalent release-source Linux ARM64 attribution: catalog-worker heap 113.9 → 85.5 MiB; settled Gateway RSS 1064.9 → 1032.3 MiB. This is not strict performance qualification or a measurement of this main head. Budgets are unchanged; the strict release diagnostic finished with 3 failed cells, 1 inconclusive cell, and 1 passed cell. Fresh/onboarded Gateway RSS is within budget and bundled-plugin startup passes; status-CLI resources, many-plugin startup, and agent pre-provider latency still require repair.

Review-ready verification — October 9, 2026

Verified unchanged head e58f73edcb6cc5fe5513dcf2db4bfab0a112ff67; no additional source changes or rebase were necessary.

  • Exact-head CI run passed, including the required openclaw/ci-gate.
  • Fresh independent P0–P2 autoreview: scoped-clean, no accepted/actionable findings.
  • Fresh ClawSweeper review: no findings or before-merge blockers; platinum hermit patch quality. Overall gold remains attributable to the explicitly recorded exact-head Gateway memory-measurement gap, not a code finding.
  • Local command below passed 76 tests across six files, including actual worker-thread provider discovery, parent-native catalog preservation, both concurrent renewal completion orders, restrictive/empty catalog scopes, and isolated-completion plugin selection. Three routed Vitest shards passed; cold build/compiler preparation included. Total wrapper time: 866.64 seconds; not a performance comparison.
node scripts/run-vitest.mjs   src/agents/harness/runtime-plugin.test.ts   src/agents/harness/model-catalog.test.ts   src/agents/prepared-model-catalog-worker.native.integration.test.ts   src/agents/prepared-model-catalog-worker.native-renewal.integration.test.ts   src/agents/prepared-model-catalog-worker.scope.integration.test.ts   src/agents/isolated-completion.plugin-scope.test.ts --maxWorkers=1
  • The wrapper's canonical runtime build passed. Targeted formatting and lint also passed:
node_modules/.bin/oxfmt --check src/agents/harness/runtime-plugin-load-plan.ts src/agents/harness/runtime-plugin.test.ts
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/harness/runtime-plugin-load-plan.ts src/agents/harness/runtime-plugin.test.ts
git diff --check origin/main...HEAD

Best-fix verdict: best. Remove catalog-wide harness activation at its load-plan owner; do not add downstream worker filters or duplicate native discovery. runtime-plugins.ts carries the plan into the loader; prepared-model-catalog.worker.ts supplies eligible provider owners; prepared-model-runtime.catalog-access.ts and harness/model-catalog.ts retain native discovery in the parent. Agent and isolated-completion selection remain canonical. Production delta: −14 LOC; tests: +9 LOC.

The acting reviewer also directly checked sibling Codex source: codex-rs/app-server/src/model_catalog.rs:32–45, codex-rs/app-server/src/request_processors/catalog_processor.rs:178–217,280–330, and codex-rs/app-server-protocol/src/protocol/v2/model.rs:55–65,178–183 (checkout d25c114d494ddb693290b76bf5e5f64ecbdb38fc). No Codex protocol changes.

Remaining proof limitation: the fresh tests exercise real worker/loader and Gateway handler boundaries with synthetic providers; they are not authenticated live-provider proof or exact-head Gateway memory measurements. The earlier release-source memory observations remain explicitly attributed to that source. PR is ready for review, not merged.

Keep provider catalog workers within their eligible provider-plugin scope. Native harness model observations remain parent-owned; normal agent and isolated-completion owner selection stay unchanged.
@clawsweeper

clawsweeper Bot commented Oct 8, 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 Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Background model discovery loads only eligible provider plugins, avoiding unnecessary native agent execution code while preserving native model choices.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair is correct and supported by boundary coverage, while measured runtime improvements are attributed to equivalent release source.
Proof confidence 🦐 gold shrimp (3/6) This MEMBER-authored PR is outside the external-contributor proof gate. Reported exact-head worker/loader and Gateway-handler tests exercise provider scope and parent native continuity with synthetic providers; Linux ARM64 memory improvements belong to equivalent release source, not this head. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Background model discovery consumes extra memory by initializing native agent execution code it does not need.
Reason: The repair restores the established provider-worker boundary with less production code and preserves native model choices. The MEMBER-authored proposal supplies owner direction.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary because current main still contains the catalog-scope defect. The maintainer-authored repair has no actionable findings or additional merge blockers.

Priority: P2
Reviewed head: e58f73edcb6cc5fe5513dcf2db4bfab0a112ff67

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Exact-head Gateway discovery with before/after memory measurements is not supplied; runtime memory observations apply to equivalent release source.
Agent review details

How this fits together

OpenClaw discovers provider models in a background worker and native agent models through a parent-owned catalog. The plugin load planner determines which runtime code each path initializes.

flowchart TD
  A[Model discovery request] --> B[Plugin load planner]
  B --> C{Preparation purpose}
  C --> D[Provider catalog worker]
  C --> E[Agent or isolated completion]
  D --> F[Eligible provider plugins]
  E --> G[Selected provider and harness]
  H[Parent native catalog owner] --> A
Loading

Technical review

Best possible solution:

Keep provider discovery scoped in the existing planner and native model observations in the parent catalog owner.

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

Yes, source establishes that declared harness metadata adds execution owners outside the worker's requested provider scope. The extended cases target that mechanism; no failing run was executed during this read-only review.

Is this the best way to solve the issue?

Yes, removing blanket activation at the load-plan owner repairs the cause without introducing another discovery path, while preserving agent and isolated-completion selection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7b627f476aef.

Provenance checked

  • src/agents/harness/runtime-plugin-load-plan.ts catalog harness activation changes intended behavior with a stated reason (8cd38b0: The installed-agent feature connects native agents to model selection and preserves native choices across reload.)
  • src/agents/harness/runtime-plugin.test.ts catalog scope cases keeps the original intent (201f11a: Catalog workers use explicit provider-discovery scope while agent sessions retain selected capability owners.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 201f11a adds src/agents/harness/runtime-plugin-load-plan.ts:318 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 201f11afefdb; files: src/agents/harness/runtime-plugin-load-plan.ts)
  • Jacqueline Henriksen: Raw commit 072a6b3 adds src/agents/harness/runtime-plugin-load-plan.ts:368 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 072a6b36f53f; files: src/agents/harness/runtime-plugin-load-plan.ts)

PR surface

Source -14, Tests +9. Total -5 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 15 -14
Tests 1 10 1 +9
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 11 16 -5

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Unnecessary background-discovery memory use is a bounded runtime defect without evidence of an urgent outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-08T14:47:20.680Z sha e58f73e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T15:04:09.318Z sha e58f73e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T22:12:47.760Z sha e58f73e :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 6:31 PM ET / 22:31 UTC (Revision 4).

@RomneyDa
RomneyDa marked this pull request as ready for review October 9, 2026 22:08
@RomneyDa
RomneyDa merged commit e39552c into main Oct 10, 2026
217 checks passed
@RomneyDa
RomneyDa deleted the fix/catalog-worker-harness-scope branch October 10, 2026 00:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…aw#167282)

Keep provider catalog workers within their eligible provider-plugin scope. Native harness model observations remain parent-owned; normal agent and isolated-completion owner selection stay unchanged.
ekinnee pushed a commit to ekinnee/openclaw that referenced this pull request Oct 14, 2026
Salvage the catalog registration facts and local callback lifetime repairs from bot-owned PR openclaw#158369 onto current main. Omit the native harness catalog fix already landed in openclaw#167282 and the shared inbound repair from openclaw#160658.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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