Skip to content

improve(agents): reduce model-catalog worker memory overhead - #167461

Closed
RomneyDa wants to merge 1 commit into
mainfrom
perf/catalog-worker-young-heap
Closed

RomneyDa wants to merge 1 commit into
mainfrom
perf/catalog-worker-young-heap

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 8, 2026

Copy link
Copy Markdown
Member

What Problem This Solves

Model discovery can retain an oversized young-generation heap in its catalog worker on high-memory hosts.

User Impact

Bounds the catalog worker’s young-generation allowance to 32 MiB while preserving its existing 512 MiB old-generation allowance. No config changes, migrations, worker-count changes, or lifecycle changes.

Why This Change Was Made

The existing catalog pool owns both native heap limits. The existing custody test verifies those limits on the actual Worker for configured Gateway and standalone owners.

Evidence

  • Both custody cases fail on main before the policy change: the native worker reports 192 MiB young generation, rather than 32 MiB. Both pass after the change.
  • All 31 existing production catalog, custody, and workspace-heap cases pass. The changed custody file’s pnpm test <file> --maxWorkers=1 run took 92.36 s including a fresh runtime build and compiled workers; Vitest duration was 14.72 s. No new test or fixture was added. Hosted CI seconds are not yet available.
  • Fresh independent P0–P2 review: scoped-clean.
  • A release-branch, single-pair 80-plugin diagnostic completed real health/status checks with both policies. Gateway RSS peak was 1161.906 → 1083.441 MiB; catalog heap allocation was 230.086 → 132.289 MiB. This is ARM64 diagnostic evidence, not strict Linux qualification, a statistical performance result, or a latency claim.
  • Main scoped changed gate: all pre-deadcode checks pass, including core and all 27 core-test type graphs. The original gate exits 1 only for the inherited Talk ClientVoiceToolEffect unused export. Its file is byte-identical to the pinned main baseline; this patch changes no import/export edges. All nine unreached planned commands pass separately, including targeted two-file type-aware lint. No unrelated export, baseline, or guard change is included.

Draft only; not submitted for merge. Strict release qualification remains owned by the release campaign.

Keep the catalog pool’s existing 512 MiB old-generation allowance and add
an explicit 32 MiB young-generation allowance in the same owner policy.
Extend existing custody coverage to verify both limits on the native Worker.

The two custody cases fail before this change at the young-generation
limit (192 rather than 32 MiB) and pass afterward. All 31 existing catalog,
custody, and workspace-heap cases pass. Fresh P0-P2 review is scoped-clean.
The scoped changed gate fails only on the inherited, untouched Talk
ClientVoiceToolEffect unused export; all nine unreached planned commands
pass independently. No unrelated exports, limits, or baselines change.

Single-pair release-branch RSS diagnostics support this policy; strict
Linux performance qualification remains with the release campaign.
@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

The PR gives model-discovery workers a 32 MiB young-generation heap allowance while retaining their existing 512 MiB old-generation allowance.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, apparently correct optimization with useful bounded runtime evidence, capped by the unresolved heap-policy choice.
Proof confidence 🐚 platinum hermit (4/6) This MEMBER-authored PR is outside the external-contributor proof gate. Its body reports real Gateway health/status checks with both policies on an ARM64 release branch and lower catalog allocation; native custody coverage additionally verifies the changed production pool option. Those observations are diagnostic rather than exact-head Linux performance qualification, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Needs a maintainer decision
User problem: Model discovery can leave the Gateway using more memory than necessary on high-memory hosts.
Reason: The implementation is small and the reported diagnostic supports its value, but it selects a new default allowance for an owner-built worker policy.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this maintainer-authored PR contains a focused optimization absent from current main, with no concrete correctness defect found. Selecting the new heap allowance needs the catalog area owner's decision.

Priority: P2
Reviewed head: 36fd806e179ba7b3aa1f0b125fa3d32ce25c5561
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should catalog workers use a fixed 32 MiB young-generation allowance rather than Node's host-derived allowance?
  • Recommendation: Adopt 32 MiB: Accept the catalog-specific allowance based on the native-worker coverage and bounded ARM64 diagnostic evidence.
  • Why: The prior recorded decision covers the 512 MiB old-generation budget; the new young-generation choice trades memory allowance against garbage-collection behavior, and no area-owner acceptance of that choice is recorded.

Before merge

  • Complete next step (P2) - Have the catalog area owner select the young-generation allowance.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

OpenClaw discovers available models in a background worker so plugin loading does not block the Gateway. Gateway and standalone catalog owners use the same pool to send discovery requests and receive model and authentication facts.

flowchart TD
 A[Gateway catalog requests] --> C[Catalog pool owner]
 B[Standalone catalog requests] --> C
 C --> D[Apply worker heap allowances]
 D --> E[Background model discovery]
 E --> F[Model and authentication facts]
Loading

Technical review

Best possible solution:

Keep heap budgeting in the existing catalog-pool owner and adopt the measured young-generation allowance if the area owner accepts its capacity tradeoff.

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

Not applicable to a performance-policy proposal; the body reports native-worker before/after checks and a real Gateway memory comparison, which this read-only review did not rerun.

Is this the best way to solve the issue?

Yes for implementation placement: the shared catalog-pool owner is the narrowest path and covers both production callers; whether 32 MiB is the desired allowance remains an owner choice.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 35c70e08c7d6.

Provenance checked

  • src/agents/prepared-model-catalog-worker.pool.ts heap policy changes intended behavior with a stated reason (fix(models): stop catalog worker heap growth across refreshes #154568: Bound catalog-specific old-generation capacity while allowing source loading and overlapping generations; the later diagnostics change moved that policy into the shared pool module.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced production change: The introduced diff changes only the existing pool's resource limits and extends the existing native-Worker assertion; worker count, retirement, recovery, and authentication behavior are untouched. (src/agents/prepared-model-catalog-worker.pool.ts:16, 36fd806e179b)
  • Current main remains distinct: Pinned main sets only the 512 MiB old-generation allowance. REST comparison found no intervening changes to either touched file, and the verified test merge preserves exactly the two introduced file changes. (src/agents/prepared-model-catalog-worker.pool.ts:33, 35c70e08c7d6)
  • Shared production owner: Both configured Gateway and standalone catalog requests construct CatalogWorkerTaskPool. The native host passes its explicit resource limits through; singleton pools do not acquire a competing generic heap policy. (src/agents/prepared-model-catalog-worker.ts:593, 36fd806e179b)
  • Native worker coverage: The existing configured-Gateway and standalone custody cases locate the actual Worker used for discovery and verify both heap allowances. This protects native option propagation without adding a test-only production seam. (src/agents/prepared-model-catalog-worker.custody.integration.test.ts:122, 36fd806e179b)
  • Reported runtime diagnostic: The complete PR body reports real health/status checks for an ARM64 release-branch 80-plugin comparison: Gateway RSS peak 1161.906 to 1083.441 MiB and catalog heap allocation 230.086 to 132.289 MiB. It explicitly makes no statistical, Linux-qualification, or latency claim. Reported native custody cases fail before and pass after, with all 31 focused cases passing; these runs were not independently executed during this review. (36fd806e179b)
  • Prior capacity decision: fix(models): stop catalog worker heap growth across refreshes #154568 explicitly accepted the catalog-specific 512 MiB old-generation budget and acknowledged process-wide flag overrides and unverified large-provider capacity. That acceptance does not select a 32 MiB young-generation budget. (f5f0457314fb)

PR surface

Source 0, Tests +3. Total +3 across 2 files. Added test files: 0.

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

Review metrics

Metric Value Why it matters
Heap policy Young generation: explicit 32 MiB; old generation: unchanged 512 MiB The substantive choice is one internal memory allowance, with no new operator setting.

Labels

Label changes:

  • add P2: This is a bounded model-discovery memory improvement with diagnostic evidence and no demonstrated urgent regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a bounded model-discovery memory improvement with diagnostic evidence and no demonstrated urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed October 8, 2026, 5:28 PM ET / 21:28 UTC.

@RomneyDa

Copy link
Copy Markdown
Member Author

Closing as already incorporated in #174718. Current main retains both the 512 MiB old-generation / 32 MiB young-generation catalog worker limits and the corresponding custody regression assertion. No distinct change from this two-file PR remains to land.

Canonical merge: 6c050f8

@RomneyDa RomneyDa closed this Oct 26, 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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant