Skip to content

fix: keep catalog discovery scoped and execution lazy - #147159

Merged
steipete merged 4 commits into
mainfrom
codex/r21-discovery-isolation
Sep 13, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/r21-discovery-isolation

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Model catalog preparation can acquire agent-only plugin owners and load streaming or compilation code before any model execution. Direct prepared completions can also miss provider stream wrappers when transport setup has not already run.

User Impact

Catalog workers use their explicit provider-discovery scope, while agent sessions retain their selected memory, context-engine, and harness owners. Session and direct-completion execution initialize the provider transport hooks before dispatching requests.

Why This Change Was Made

Complete the boundary between catalog discovery and execution in the existing owners. Catalog registries avoid adopting unrelated active agent registrations. Model compatibility metadata uses a narrow internal AI entrypoint; Ollama loads its shared stream runtime when a stream is invoked, and captured TypeScript acquires the compiler when compilation is needed.

Moving transport initialization to execution includes cancellation and current-owner checks after initialization. The new internal compatibility entrypoint is included in the package exports, build map, and package checks so built artifacts preserve the same import boundary.

Evidence

Original-source controls reproduced the eager streaming import paths and the missing provider header on direct completion. The discovery-isolation controls additionally reproduced two catalog-scope failures and premature TypeScript compiler acquisition.

The import/execution cutover passed 27 focused tests and 81 related tests; four transport-host cases passed again after the fixture typing correction. The discovery-isolation suites passed 312 focused tests, with one existing opt-in Bun case skipped, plus 52 catalog-worker sibling cases. These cover registry scope and reuse, provider wrapping, cancellation, deferred compilation, metadata, secrets, and native catalog behavior.

The production changes at 5484d903 passed final managed reviews, the selected changed-file gates, and a full build. The initial build exposed a missing AI build-map entry; that entry was repaired, reviewed, and verified by subsequent complete builds. The later test-only cancellation fixture correction reproduced the original CI error, then passed all 23 owner tests, formatting, diff checks, and a fresh managed review. Exact-head hosted CI supplies the remaining typecheck and lint proof for that follow-up.

In one audited baseline/candidate comparison, catalog-worker heap after GC was 144.212 MiB versus 129.865 MiB (about 9.95% lower). Idle process RSS was 627.516 MiB versus 610.406 MiB in that same single-pair observation. These are single-pair, workload-specific observations; the worker inspection still found the TypeScript compiler loaded. A separate fixed-order live comparison sampled 1.123% more main-isolate allocation, so it did not demonstrate an allocation reduction. The lower worker heap and the main-isolate allocation sample are separate results.

The combined candidate also passed 12 real OpenAI turns through the normal Gateway entrypoint: ten code-mode and tool-search turns, plus two explicit managed web-search and web-fetch turns. Assistant results, same-session continuity, session listings, and exact tool-result history checks passed. All isolated runtime roots were removed and owned ports released. These were functional proof runs alongside other work; their timing and RSS are excluded from comparisons.

Supplementary Package Acceptance passed for production source 5484d903, which is unchanged by the test-only follow-up. It covered fresh build/pack, package integrity, npm 12 installation, and two upgrades from published [email protected]: custom-plugin siblings and legacy operator state. Both scenarios passed on their first attempt, including JavaScript plugin/Doctor sibling imports, ordinary mocked-provider turns before and after the update, state migration, a clean Doctor check, and an already-current second update. The survivor scenarios used manual restart mode. This run does not independently establish first TypeScript-plugin compilation, explicit prepared-completion provider headers, or catalog membership/exclusion. A separate manifest-driven AI package E2E passed after packing the qualified build and installing it into an external consumer: every declared export, including the new compatibility entrypoint, imported successfully, and runtime compatibility checks plus a strict TypeScript consumer passed.

Exact-head CI passed on d539c104: 135 successful jobs and nine skipped, including successful UI performance and the repaired Node shard. The prior run’s UI budget failure was independently reproduced: Linux builds of the exact CI base and tested merge, using Node 24.20.0, Vite 8.2.2, and Pako 3.0.1, produced byte-identical retained startup files. Both measured 355,770 bytes of startup JavaScript gzip against the unchanged 355,719-byte limit: this UI budget failure is pre-existing, with no PR startup-byte delta. No budget has been changed.

The cancellation fixture now admits the provider with an active signal, cancels through the session API, and throws the same exact synthetic error. The automatic case still covers cancellation before dispatch. Both assert provider call counts, and all existing rejection-identity, aborted-event, compaction-count, and persistence assertions remain. The production cancellation guard is unchanged. No total-allocation or startup-time improvement is claimed here.

Maintainer disposition: the package/update scenarios, external AI consumer, captured-TypeScript first-execution controls, registered provider-header tests, catalog-scope tests, and live Gateway runs provide proportionate coverage of the touched contracts. They are separate proofs; no single installed-upgrade TypeScript/custom-header matrix cell is claimed. The change introduces no new persistence migration or packaged dependency.

Keep catalog compatibility on a narrow internal import and install the existing transport host before session dispatch or completion preparation. Direct SDK completions now apply provider stream wrappers before sending a request, with owner and cancellation checks after initialization.
Use explicit catalog plugin owners without automatic agent slots. Load Ollama payload helpers when their streams run and acquire the TypeScript compiler only when a typed module is actually compiled.
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling extensions: ollama size: L maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 15:51
@clawsweeper

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 1:50 PM ET / 17:50 UTC (Revision 6).

ClawSweeper review

What this changes

The PR limits model discovery to relevant plugins, defers streaming and compiler loading, and initializes provider hooks before model execution.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still lacks the scoped catalog loading and execution-boundary fixes. No actionable defect remains; the corrected cancellation fixture and updated package evidence address the previous review concerns.

Priority: P2
Reviewed head: d539c1046307a7086223974d777cc363270484dd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported repair with no remaining actionable finding or unresolved compatibility decision.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Reported real Gateway turns support session execution; package acceptance, external-consumer checks, and focused compiler, scope, header, and cancellation controls provide complementary coverage accepted in the updated maintainer disposition.
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 PR is exempt from the external-contributor proof gate. Reported real Gateway turns support session execution; package acceptance, external-consumer checks, and focused compiler, scope, header, and cancellation controls provide complementary coverage accepted in the updated maintainer disposition.
Evidence reviewed 8 items Current main still needs the fixes: Fetched main still inherits broader runtime plugin scope, adopts active registrations without a catalog-purpose exception, and prepares direct completions before explicitly initializing the transport host.
Catalog scope preserves ordinary agent behavior: The model-catalog purpose uses explicit plugin IDs, rejects broader reusable registries, and skips active registration adoption. Ordinary agent loading retains its existing behavior. Registered models.list coverage checks that selected unrelated memory/context plugins do not execute in the worker.
Execution and cancellation boundaries: Direct completion initializes the existing transport host before preparation, rechecks owner validity and cancellation, and retains the final stream-facade check. Ollama likewise checks cancellation after deferred loading; its asynchronous return fits the existing StreamFn contract.
Findings None None.
Security None None.

How this fits together

Model catalog preparation turns configuration and plugin metadata into available model choices. Session and direct-completion execution then use the selected provider’s transport hooks to send requests.

flowchart TD
  A[Configuration and plugin metadata] --> B[Catalog preparation]
  B --> C[Scoped provider discovery]
  C --> D[Available model choices]
  D --> E[Session or direct completion]
  E --> F[Initialize transport and check cancellation]
  F --> G[Provider request]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +71, Tests +195, Docs 0, Config +8, Other +6. Total +280 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 13 134 63 +71
Tests 11 258 63 +195
Docs 1 1 1 0
Config 2 8 0 +8
Generated 0 0 0 0
Other 2 6 0 +6
Total 29 407 127 +280

Review metrics

Metric Value Why it matters
Production versus regression coverage Production/tooling net +85 lines; tests/support net +195 lines Production growth supports explicit discovery scope and lazy execution, with regression coverage for exclusion, wrapping, and cancellation.

Technical review

Best possible solution:

Keep discovery confined to its provider owners and initialize existing execution hooks only when needed, preserving agent selection and cancellation contracts.

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

Yes, source inspection identifies catalog scope broadening and direct transport preparation before host initialization on current main; focused regression controls cover these paths. This review did not execute them locally.

Is this the best way to solve the issue?

Yes. The patch repairs the existing loading and execution owners, reuses the compatibility implementation, and preserves public settings and plugin contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This repairs bounded catalog-loading and direct-completion behavior without evidence of an urgent production 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 PR is exempt from the external-contributor proof gate. Reported real Gateway turns support session execution; package acceptance, external-consumer checks, and focused compiler, scope, header, and cancellation controls provide complementary coverage accepted in the updated maintainer disposition.

Evidence

What I checked:

  • Current main still needs the fixes: Fetched main still inherits broader runtime plugin scope, adopts active registrations without a catalog-purpose exception, and prepares direct completions before explicitly initializing the transport host. (src/agents/runtime-plugins.ts:88, ef2861d55a5d)
  • Catalog scope preserves ordinary agent behavior: The model-catalog purpose uses explicit plugin IDs, rejects broader reusable registries, and skips active registration adoption. Ordinary agent loading retains its existing behavior. Registered models.list coverage checks that selected unrelated memory/context plugins do not execute in the worker. (src/agents/runtime-plugins.ts:90, d539c1046307)
  • Execution and cancellation boundaries: Direct completion initializes the existing transport host before preparation, rechecks owner validity and cancellation, and retains the final stream-facade check. Ollama likewise checks cancellation after deferred loading; its asynchronous return fits the existing StreamFn contract. (src/agents/simple-completion-execution.ts:70, d539c1046307)
  • Internal package boundary is complete: The compatibility subpath reexports the existing implementation and is included in package exports, TypeScript resolution, the build map, and tarball checks. The package README explicitly identifies internal subpaths as application-only; no public plugin API is replaced. (packages/ai/src/internal/openai-completions-compat.ts:1, d539c1046307)
  • Prior cancellation finding resolved: The only change after production revision 5484d903 is the compaction test correction. Manual cancellation now occurs after provider admission; exact rejection, event, persistence, and call-count assertions remain. The automatic case still covers cancellation before dispatch. (src/agents/sessions/agent-session-compaction.test.ts:609, d539c1046307)
  • Updated upgrade evidence and maintainer disposition: The captured PR body, sourceRevision 0c2e16377ae0fb86def98972c219eabd6a4007528f65b41608ac3482b58b60a2, reports fresh installation, two published 2026.9.4 upgrade scenarios, an external AI-package consumer, focused first-TypeScript-execution and provider-header controls, and 12 real Gateway turns. It explicitly accepts these complementary proofs without claiming a combined installed-upgrade TypeScript/header scenario. GitHub confirms successful package integrity, npm installation, and published-upgrade-survivor jobs at https://github.com/openclaw/openclaw/actions/runs/34769695719. Detailed log retrieval was blocked by the artifact-host allowlist; candidate-source attribution remains from the captured body.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (5 earlier review cycles)
  • reviewed 2026-09-13T15:58:30.358Z sha 5484d90 :: blocked before merge. :: none
  • reviewed 2026-09-13T16:07:37.216Z sha 5484d90 :: blocked before merge. :: none
  • reviewed 2026-09-13T16:28:56.212Z sha 5484d90 :: blocked before merge. :: none
  • reviewed 2026-09-13T16:53:17.584Z sha 5484d90 :: blocked before merge. :: [P2] Align the manual-compaction fixture with pre-dispatch cancellation
  • reviewed 2026-09-13T17:10:53.196Z sha d539c10 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed 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 13, 2026
Cancel the manual compaction after its provider is admitted so its exact rejection remains observable. Assert that cancellation before dispatch never calls the provider again.
@clawsweeper clawsweeper Bot added 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. and removed 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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 13, 2026
@steipete
steipete merged commit 201f11a into main Sep 13, 2026
213 checks passed
@steipete
steipete deleted the codex/r21-discovery-isolation branch September 13, 2026 17:55
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '201f11afefdb19a9c75e9d3542bf7425c80df7a7': (141 commits)
  fix: keep catalog discovery scoped and execution lazy (#147159)
  fix: serialize reclamation worker shutdown with foreground writes (#147178)
  test(sessions): cover abrupt committed transcript recovery (#143984)
  fix: stop transcript storms during context overflow recovery (#147202)
  fix: reduce CPU overhead for small history and usage reads (#147205)
  fix: resume tasks after tools finish and the model times out (#147203)
  refactor(scripts): share SQLite reliability message waits (#146900)
  feat(exec): configure approval reviewer thinking and fastMode (#147192)
  test: remove redundant Bonjour module headers (#146981)
  refactor: share streaming media tail boundary update (#146989)
  refactor(tui): classify resume candidates once (#146983)
  improve: skip unused toast dismissal work (#147196)
  fix(linux): recover saved remote connections without replacing active sessions (#146047)
  fix: doctor stays silent when Windows state dir is under OneDrive (#123720)
  feat: announce successful Daybreak retries (#147146)
  feat(code-mode): reuse results across code cells (#147154)
  refactor(test): reuse CLI plugin fixture writer (#147186)
  test: skip unused compiler setup in routing fixtures (#147194)
  test: reuse LINE webhook runtime fixture (#146710)
  fix(code-mode): check automation and process result types (#147143)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '2d87daf04b78992382299d552f15ac84a86a23ed': (1815 commits)
  fix(ui): distinguish tool activity with semantic icons (#147207)
  fix(linux): recover completed Quick Chat replies without resending (#146048)
  feat(desktop): unify Tauri title bar and window controls (#147097)
  refactor(test): share plugin fixture server shims (#147225)
  perf(gateway): defer worker workspace execution imports (#143496)
  fix(gateway): post-ack webhook work fails with "Async work scope is closed" (#144801)
  refactor(scripts): centralize upgrade survivor version floors (#146975)
  fix(ci): check publication registries before FRV fanout (#147184)
  fix(qa): align system-agent delegation with channel contracts (#145905)
  improve: reduce repeated chat message identity work (#147210)
  fix(channels): remove stale pre-tool previews from Slack and Telegram (#147106)
  fix: keep catalog discovery scoped and execution lazy (#147159)
  fix: serialize reclamation worker shutdown with foreground writes (#147178)
  test(sessions): cover abrupt committed transcript recovery (#143984)
  fix: stop transcript storms during context overflow recovery (#147202)
  fix: reduce CPU overhead for small history and usage reads (#147205)
  fix: resume tasks after tools finish and the model times out (#147203)
  refactor(scripts): share SQLite reliability message waits (#146900)
  feat(exec): configure approval reviewer thinking and fastMode (#147192)
  test: remove redundant Bonjour module headers (#146981)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
* fix(agents): initialize transport hooks at execution boundaries

Keep catalog compatibility on a narrow internal import and install the existing transport host before session dispatch or completion preparation. Direct SDK completions now apply provider stream wrappers before sending a request, with owner and cancellation checks after initialization.

* build(ai): emit the model compatibility entrypoint

* perf: isolate catalog workers from unused execution code

Use explicit catalog plugin owners without automatic agent slots. Load Ollama payload helpers when their streams run and acquire the TypeScript compiler only when a typed module is actually compiled.

* test(agents): exercise admitted compaction cancellation

Cancel the manual compaction after its provider is admitted so its exact rejection remains observable. Assert that cancellation before dispatch never calls the provider again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: ollama maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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