Skip to content

perf(models): release unused account catalog instructions - #174361

Merged
steipete merged 5 commits into
mainfrom
steipete/perf-micro-catalog-worker-data-retention-20260919
Oct 16, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/perf-micro-catalog-worker-data-retention-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Account model discovery retains unused backend instruction templates, so catalog-worker memory grows with distinct authenticated account catalogs.

User Impact

OpenAI account discovery now retains only projected models and account availability facts. Operators can inspect size-only catalog-worker data through openclaw gateway stability --type diagnostic.memory.sample --limit 1 --json, without heap snapshots, catalog contents, object keys, identities, or secrets.

Why This Change Was Made

The backend response includes both current instruction templates and a legacy rendered instruction field. Projection previously happened after raw rows entered the shared cache. Moving projection inside the loader drops both unused copies while preserving account/token/endpoint isolation, coalescing, expiry, refresh, cancellation, and failures.

The existing cache moves behind its unchanged SDK exports to one internal owner. A bounded census on the existing worker-memory channel covers config, plugin metadata, models, pricing, cached provider results, auth stores, and active requests. Estimates can overlap across categories and do not cover module/closure internals. Only plain records and arrays are traversed; proxies, custom instances, and accessors yield partial estimates without executing plugin code. No schema, configuration, or retention-policy change.

Evidence

A synthetic Linux run exercises the actual prepared-model catalog worker and OpenAI provider, with 12 models per account and two 64 KiB instruction fields per model. Network access is disabled. After collection, worker old space is:

Distinct accounts Before (MiB) After retention fix + census (MiB) Reduction (MiB)
1 152.56 151.13 1.43
10 166.42 151.52 14.90
40 211.66 151.80 59.86

At 40 accounts, old space falls 28.3%. Growth from 1 to 40 accounts falls from 59.10 MiB to 0.67 MiB. All 40 account discoveries fetch once and return the expected catalog. The measured worker census reports one prepared generation, 40 cached provider results totaling approximately 548,380 bytes, and no pending loads or active task input. An OpenAI-only run produces the same reduction within 0.08 MiB, isolating the retention fix from the diagnostics.

This is a synthetic account-breadth sweep, not an exact production reproduction. Source-mode runtime overhead differs from a compiled deployment. Production runtime account breadth and post-deployment old space remain unverified; the census enables that follow-up safely.

  • The regression exercises the actual provider catalog operation: old code retains both observed raw response objects after collection; new code releases them while retaining same-account reuse and account isolation.
  • Focused local tests pass: OpenAI provider (38), shared catalog cache (16), worker memory transport (17), diagnostic bundle sanitization (14), bounded estimator (2), and static-catalog census (2). The new collection regression runs in about 0.1 seconds.
  • Eager-import closure, PR-wrapper source closure, and the matching CI node-test planner pass: 3 files / 163 tests, one worker, 196.51 s total.
  • Changed-file formatting, core changed-file lint, and diff checks pass. Extension type-aware lint attempted to prepare build artifacts and was stopped to respect local compute limits; that check and broad typecheck/build/closure/test gates belong to PR CI. No Testbox/Crabbox lease was used.
  • Independent Codex review is clean. CI caught an undocumented generic cast moved with the cache; its existing key/result-type invariant is now documented, and the same assertion scanner reports zero undocumented assertions for that file. Follow-up helper extraction satisfies the changed-file line-cap ratchet; all 38 OpenAI provider tests pass after fixing a Vitest hoisted-export restriction. The extraction preserves the measured logic. PR review also identified unsafe inspection of opaque plugin values; a shared-cache regression reproduces the original failure, and the corrected plain-data census passes that regression and independent review.

Production delta: +595/-263 (+332 LOC); tests/support: +417/-108 (+309 LOC). Required size-only introspection accounts for the growth; raw response retention and the old cache implementation are replaced, with no parallel cache or speculative fast path.

The static census counts retained provider records rather than reading plugin-owned model arrays. Both proxy and accessor regressions fail at the old direct property read, then pass after removing it (4 ms test time; 35.11 s including cold worker preparation). Independent review is clean. The stale assertion baseline entry for the moved SDK implementation is removed; the actual scanner reports zero undocumented assertions in both the SDK re-export and internal cache owner.

Baseline CI attribution

  • Guided custom-provider onboarding: unchanged main b460ee8d2ab41bf94bb8518e7330290787ea3465, using its CI-built artifact, reproduces 5 failed / 12 passed in the single src/commands/onboard-guided.custom-provider.e2e.test.ts file. Command: OPENCLAW_E2E_USE_PREBUILT_DIST=1 pnpm test src/commands/onboard-guided.custom-provider.e2e.test.ts --maxWorkers=1. All five failures are line 346 expecting undefined for the intentional saved-profile reference. This matches the PR's earlier failed job. The test, model-selection writer, credential/activation owners, and provider-snapshot test have identical blobs on this baseline and CI's later main parent 5aec205816506ceb6983a5ab1c549c9e0b301a61.
  • Duplicate-scanner coverage: node scripts/check-duplicates.mjs --coverage on unchanged main 5aec205816506ceb6983a5ab1c549c9e0b301a61 exits 1 for cli-parent-lifetime.mjs, matching the PR guard failure. Neither the file nor the scanner differs between that baseline and tested merge d144d31abccf4ab7ece17fd3a1bcc1805aa42845.
  • Mock-export ratchet: the existing scanner, restricted to unchanged main's src/flows/doctor-plugin-source-captures.test.ts, reports the ungrandfathered darwin-bun-process-census.js mock at line 32, matching the CI ratchet job. This is separate from this PR's repaired stale assertion entry.

Final CI run 38928137387 completed for head 9d489a6e59556b2cdf87e9a46138c41bf4f4764a. Its tested merge is fef941b9934b60ecc04b8921b63a6af13a9836c2, with ordered parents 0dc31f5f64309d199f12aea643452bfde54f4888 (main) and the PR head. The assertion and line-cap repairs pass, security-fast passes, and all review threads are resolved. PR checks report 85 successes; the remaining failures are these three inherited jobs and their aggregate CI gates:

  • checks-node-changed: the same five onboarding failures at line 346. The failing test and responsible owners remain identical between the replayed main baseline and this exact main parent.
  • check-guards: the same missing duplicate-scan coverage for cli-parent-lifetime.mjs. Scanner and file are unchanged from the reproduced main baseline through the tested merge.
  • checks-fast-baseline-ratchets: only the same missing mock-export isolation in doctor-plugin-source-captures.test.ts. A targeted replay of the actual scanner on the exact main parent and tested merge produces the identical ungrandfathered fingerprint 0f314816d50228e6240f1048998f802dd80d499ba91277a72f2a366e9c574dd2.

Landing uses the authorized inherited-failure exception. No CI reruns, dispatches, or branch updates were used to chase green.

Cache projected OpenAI account catalog facts instead of raw backend model responses, which also carry unused instruction templates. Add bounded size-only catalog worker diagnostics on the existing memory sampling channel.

Focused regressions cover raw response collection, cache reuse and account isolation, cache lifecycle, worker transport, and diagnostic sanitization. Synthetic account breadth measurements show raw response retention is removed; production attribution awaits deployment.
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 16, 2026 15:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T16:02:05.866578Z 9d489a6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: openai and removed security-sensitive-changed labels Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 9d489a6e59556b2cdf87e9a46138c41bf4f4764a
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/runtime-snapshots.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

Move existing Codex row normalization into the row helper owner and existing live catalog test helpers into test support. Preserve the account catalog and retention regression coverage while satisfying the changed-file line-cap ratchet.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 700b987af5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Restrict the size census to plain record and array data properties. Skip proxies, custom instances and accessors with an explicit partial estimate instead of invoking plugin-owned behavior during worker sampling.

The shared-cache regression reproduces proxy trap execution before the fix and verifies safe sampling afterward. Focused cache and estimator tests and independent review pass.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a6385cd62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@steipete
steipete merged commit 1b9fe6a into main Oct 16, 2026
150 of 156 checks passed
@steipete
steipete deleted the steipete/perf-micro-catalog-worker-data-retention-20260919 branch October 16, 2026 16:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged as 1b9fe6a under the authorized inherited-failure exception, pinned to reviewed head 9d489a6.

Final CI run 38928137387 completed. The three remaining failing jobs were unchanged-main defects: five guided custom-provider onboarding assertions at line 346 (reproduced on main: 5 failed / 12 passed), duplicate-scanner coverage missing cli-parent-lifetime.mjs (reproduced with the coverage-only command), and the ungrandfathered darwin-bun-process-census mock in doctor-plugin-source-captures.test.ts (identical scanner fingerprint on the exact main parent and tested merge). Exact commits, job links, commands, and attribution are recorded in the PR body. Aggregate CI gates remained red for those failures; they were not reported as green.

Other applicable checks and security-fast passed. Independent review is clean, both diagnostics findings are fixed, and all review threads are resolved. No CI reruns or green-chasing branch updates were used. Production post-deployment memory confirmation remains a follow-up.

vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '0c6c7ee5837ed93f6fb09ca58b280e76878c21f1': (109 commits)
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  refactor(feishu): reuse streaming merge in dispatcher tests (#174371)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '14e993fff3ecb84eb1d7c9724c4ceda235d797e4': (110 commits)
  fix(decisions): align accounting ratchet evidence
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  ...
vincentkoc added a commit that referenced this pull request Oct 16, 2026
* commit '0c6c7ee5837ed93f6fb09ca58b280e76878c21f1': (109 commits)
  feat(memory): activate PostgreSQL memory search and lifecycle (#174374)
  fix: join process shutdown and isolate runtime fixtures (#174359)
  refactor(ui): scope native gateway observation to Solid (#174367)
  refactor(ui): own canvas widget lifetime in Solid (#174370)
  perf(control-ui): keep agent avatar faces stable across agent publications (#174239)
  perf(models): release unused account catalog instructions (#174361)
  refactor(ui): own composer command menus in Solid stores (#174321)
  refactor(ui): separate sidebar filter state from view lifecycle (#174352)
  test(release): make artifact qualification deadlines deterministic
  fix(codex): preserve sandboxed process inspection and setup errors (#174284)
  fix(gateway): stop worker processes before draining their queues (#174312)
  refactor(agents): reuse prepared tool facts (#174349)
  test(gateway,plugins,ui): remove low-value tests (batch d174) (#174331)
  refactor(ui): replace MCP retirement host adapters with a factory (#174375)
  refactor(logging): remove redundant native success traces (#174330)
  refactor(test): remove dead control-plane fixture branches (#174377)
  refactor(mcp): remove test-only session runtime seams (#174347)
  feat(matrix): account-root state databases follow the selected engine (#174315)
  refactor(discord): collapse private interaction and factory seams (#174322)
  refactor(feishu): reuse streaming merge in dispatcher tests (#174371)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…74361)

* perf(models): release unused account catalog instructions

Cache projected OpenAI account catalog facts instead of raw backend model responses, which also carry unused instruction templates. Add bounded size-only catalog worker diagnostics on the existing memory sampling channel.

Focused regressions cover raw response collection, cache reuse and account isolation, cache lifecycle, worker transport, and diagnostic sanitization. Synthetic account breadth measurements show raw response retention is removed; production attribution awaits deployment.

* refactor(openai): extract catalog helpers within file limits

Move existing Codex row normalization into the row helper owner and existing live catalog test helpers into test support. Preserve the account catalog and retention regression coverage while satisfying the changed-file line-cap ratchet.

* fix(diagnostics): avoid executing opaque catalog values

Restrict the size census to plain record and array data properties. Skip proxies, custom instances and accessors with an explicit partial estimate instead of invoking plugin-owned behavior during worker sampling.

The shared-cache regression reproduces proxy trap execution before the fix and verifies safe sampling afterward. Focused cache and estimator tests and independent review pass.

* docs(models): state the catalog cache type invariant

* fix(diagnostics): count static catalog records without plugin reads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: openai gateway Gateway runtime security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant