Skip to content

refactor(plugins): expose loaded runtime metadata#79198

Open
mcaxtr wants to merge 3 commits into
mainfrom
refactor/prepared-runtime-startup-metadata
Open

refactor(plugins): expose loaded runtime metadata#79198
mcaxtr wants to merge 3 commits into
mainfrom
refactor/prepared-runtime-startup-metadata

Conversation

@mcaxtr

@mcaxtr mcaxtr commented May 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Problem: later prepared-runtime migrations need loaded provider, channel, public metadata, and outbound adapter facts from Gateway startup, but those facts were not exposed through one stable loaded-runtime surface.
  • Why it matters: without this startup/public metadata layer, later reply, tool, outbound, TTS, and command PRs would either keep broad request-time rediscovery or add scattered cache layers around individual consumers.
  • What changed: this PR makes Gateway startup and plugin runtime state expose loaded/public runtime metadata, pins the Gateway runtime registry beside the channel registry, expands startup plugin selection for configured model/media/speech facts, and lets selected-provider handle lookup reuse the gateway-runtime loaded registry surface.
  • What did NOT change: this PR does not migrate reply/tool/outbound request-time consumers yet and does not remove compatibility fallback behavior needed by setup, startup, admin, standalone, or later migration surfaces.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Details

This is PR 2 in the prepared runtime resolution migration.

It adds the loaded-runtime metadata layer that later migration PRs can consume without rebuilding plugin/provider/channel registries at request time:

  • Active runtime registry lookup now has explicit surfaces for active, channel, Gateway runtime, and HTTP route registries.
  • Gateway startup pins both channel and Gateway runtime registries so later config-schema or status registry churn cannot evict the runtime facts prepared during startup.
  • resolveProviderRuntimePluginHandle(...) now checks the gateway-runtime loaded registry surface introduced here, completing the PR 1 follow-up called out in Tracking: Prepared runtime resolution migration #77700.
  • Runtime plugin metadata exposes loaded provider/channel/public facts needed by later prepared-runtime consumers.
  • Startup plugin id selection includes configured model owner plugins, configured media model owners, configured speech providers, and bundled startup sidecars without broad request-time loading.
  • Bundled channel metadata and outbound adapter loading can answer lightweight public-runtime questions without full channel plugin bootstrap.
  • Web provider public/runtime artifacts reuse the loaded/public metadata path.
  • Tool-result middleware loading checks prepared runtime registries before falling back to broader plugin loading.

The architectural line is the same as PR 1: this PR creates startup/runtime producer surfaces only. It does not redirect normal reply/tool/outbound consumers yet. Later PRs will migrate one surface at a time, prove that prepared facts are used, and remove old lookup branches only after the corresponding prepared path owns the call.

Real behavior proof (required for external PRs)

N/A. Maintainer-authored internal refactor surface; no end-user reply path is migrated in this PR.

Root Cause (if applicable)

  • Root cause: startup already had useful plugin/provider/channel/runtime facts, but later code had no stable loaded-runtime metadata surface to read them from, so hot consumers kept pressure to rediscover those facts through broad loaders.
  • Missing detection / guardrail: registry state was tracked mostly as active/channel/http-route compatibility state, not as an explicit Gateway runtime surface for prepared selected-provider lookup.
  • Contributing context: broad compatibility fallback behavior is still necessary for setup, admin, standalone, and unmigrated callers, so this PR adds a canonical loaded-runtime surface before migrating consumers.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target tests or files:
    • src/plugins/runtime.channel-pin.test.ts
    • src/plugins/channel-plugin-ids.test.ts
    • src/plugins/web-provider-runtime-shared.test.ts
    • src/plugins/agent-tool-result-middleware-loader.test.ts
    • src/gateway/server-startup-post-attach.test.ts
    • src/agents/runtime-plugins.test.ts
  • Scenario the tests should lock in: Gateway startup preserves loaded runtime registries, configured startup plugin ids include the owners later request paths need, provider handles can resolve from pinned Gateway runtime metadata, and middleware/public metadata lookup can use loaded runtime state before broad fallback.
  • Why this is the smallest reliable guardrail: PR 2 is a startup/runtime metadata PR, so the useful boundary is the loaded registry/public metadata seam rather than a full live reply migration.
  • Existing test that already covers this (if any): existing startup and runtime registry tests were extended to cover the new Gateway runtime surface.

User-visible / Behavior Changes

None expected. This PR changes internal startup/runtime metadata plumbing and preserves compatibility fallback behavior for existing callers.

Diagram (if applicable)

Before:
[Gateway startup loads plugins] -> [later code cannot read exact loaded fact] -> [consumer broad-loads registry again]

After this PR:
[Gateway startup loads plugins] -> [loaded Gateway/runtime metadata surface] -> [later PRs can pass prepared fact forward]

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: Node 22 / pnpm
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. pnpm test src/plugins/runtime.channel-pin.test.ts src/plugins/channel-plugin-ids.test.ts src/plugins/bundle-mcp.test.ts src/plugins/web-provider-runtime-shared.test.ts src/plugins/agent-tool-result-middleware-loader.test.ts src/channels/plugins/bundled-root-caches.test.ts src/gateway/server-startup-post-attach.test.ts src/gateway/server-startup.test.ts src/agents/runtime-plugins.test.ts
  2. pnpm build
  3. git diff --check origin/main...HEAD

Expected

  • Focused runtime/startup metadata tests pass.
  • Build passes.
  • Diff hygiene is clean.

Actual

  • Focused runtime/startup metadata tests passed: 4 Vitest shards in 49.57s.
  • Build passed.
  • git diff --check origin/main...HEAD passed.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Evidence is the local targeted test/build proof above. During extraction, the standalone branch exposed two useful guardrails: startup model prewarm must remain metadata-only, and configured model owner plugins should be included in startup metadata alongside implicit runtime owner plugins.

Human Verification (required)

  • Verified scenarios: PR 2 is one commit on top of current main; file scope is startup/runtime metadata plus CHANGELOG.md; focused Gateway/plugins/channels/agents tests pass; build passes; diff hygiene is clean.
  • Edge cases checked: provider handles resolve from the pinned Gateway runtime registry after active registry churn; Gateway startup model prewarm does not import PI runtime model resolution; generated Canvas bundle hash drift from build was kept out of the PR.
  • What you did not verify: live Gateway reply benchmark, because this PR does not migrate the live reply path yet.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: loaded runtime metadata could be mistaken for a request-time consumer migration.
  • Risk: startup might accidentally import heavier provider runtime work while exposing these facts.
    • Mitigation: Gateway startup tests preserve metadata-only primary model prewarm behavior, and build/lazy-loading proof is included.
  • Risk: later PRs could still miss this surface and reintroduce broad lookups.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels May 8, 2026
@clawsweeper

clawsweeper Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 3, 2026, 11:41 PM ET / 03:41 UTC.

Summary
The PR adds a loaded gateway-runtime plugin registry surface, expands startup runtime metadata selection, and updates focused plugin/Gateway/agent tests plus a changelog entry.

PR surface: Source +230, Tests +118, Docs +1. Total +349 across 13 files.

Reproducibility: not applicable. this is an internal refactor PR, not a bug report with a user-level reproduction path. The relevant check is source comparison against current main plus rebase validation of the runtime/startup seams.

Review metrics: 2 noteworthy metrics.

  • Loaded Registry Surface: 1 added: gateway-runtime. A new process-global loaded registry surface changes plugin/runtime lifecycle behavior that maintainers should review before merge.
  • Startup Owner Selection: 3 owner groups touched: model, media/generation, and speech/provider facts. The diff changes which provider/plugin owners may load during startup for existing configurations.

Stored data model
Persistent data-model change detected: vector/embedding metadata: CHANGELOG.md, vector/embedding metadata: src/plugins/runtime.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #77700
Summary: This PR is the open PR 2 implementation candidate for the canonical prepared-runtime resolution migration tracker.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🌊 off-meta tidepool
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rebase against current main and preserve session-extension plus live-registry cleanup/dispatch behavior while adding gateway-runtime.
  • Rerun the focused plugin/runtime/startup tests and pnpm build after the rebase.

Risk before merge

  • [P1] Live GitHub reports the PR head as CONFLICTING, so it cannot merge until the branch is rebased or manually resolved.
  • [P1] The new gateway-runtime surface must join current main's liveness, cleanup/retirement, imported-plugin accounting, and agent-event dispatch paths; otherwise prepared runtime metadata can be dropped or ignored after active-registry churn.
  • [P1] The PR broadens startup provider/plugin owner selection and adds a process-global loaded registry surface, which can affect existing plugin/provider startup behavior even when focused tests pass.

Maintainer options:

  1. Rebase And Preserve Registry Lifecycle (recommended)
    Resolve the conflicts by adding gateway-runtime to current main's live registry set, cleanup/retirement logic, imported-plugin accounting, agent-event dispatch, session-extension startup pinning, and focused tests before merge.
  2. Accept Startup Loading Expansion After Owner Review
    Maintainers can intentionally accept the broader startup owner selection once fresh proof shows existing provider and plugin configurations still upgrade safely.
  3. Replace The Stale Slice
    If the branch has drifted too far, close or replace it with a fresh narrow PR for the still-missing loaded registry surface and matching tests.

Next step before merge

  • [P2] The remaining action is author/owner rebase and architecture review, not a safe automated repair, because the PR is protected and conflicts in compatibility-sensitive plugin runtime lifecycle code.

Security
Cleared: The diff touches TypeScript plugin/runtime startup code, focused tests, and changelog text with no dependency, workflow, secret, download, or package-script changes.

Review findings

  • [P1] Wire gateway-runtime into the live registry lifecycle — src/plugins/runtime.ts:333-339
Review details

Best possible solution:

Keep this as the canonical startup metadata slice, but land it only after a current-main rebase wires gateway-runtime into every live registry lifecycle helper and reruns focused proof.

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

Not applicable: this is an internal refactor PR, not a bug report with a user-level reproduction path. The relevant check is source comparison against current main plus rebase validation of the runtime/startup seams.

Is this the best way to solve the issue?

No as submitted: the staged producer surface is the right shape, but the branch is conflicting and must be integrated with current main's live-registry lifecycle before it is merge-safe.

Full review comments:

  • [P1] Wire gateway-runtime into the live registry lifecycle — src/plugins/runtime.ts:333-339
    The PR adds pinActivePluginGatewayRuntimeRegistry, but current main now decides registry liveness, cleanup, imported-plugin accounting, and agent-event dispatch from the active/http-route/channel/session-extension live set. When resolving conflicts, include the new surface in those lifecycle helpers and tests; otherwise a registry pinned only for runtime metadata can be retired or omitted after active-registry churn.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9d68f877ac3e.

Label changes

Label justifications:

  • P3: This is an internal maintainer runtime migration slice, not an urgent user-facing regression.
  • merge-risk: 🚨 compatibility: The PR changes plugin/provider startup selection and process-global loaded registry reuse, which can affect existing plugin/provider behavior during upgrade.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The external contributor proof gate does not apply because this is a MEMBER-authored internal refactor and no end-user reply path is migrated in this PR.
Evidence reviewed

PR surface:

Source +230, Tests +118, Docs +1. Total +349 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 9 282 52 +230
Tests 3 132 14 +118
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 415 66 +349

What I checked:

  • Repository policy applied: Root and scoped plugin/Gateway/agent policies mark plugin APIs, startup checks, provider routing, fallback behavior, and process-global runtime metadata as compatibility-sensitive review surfaces. (AGENTS.md:31, 9d68f877ac3e)
  • Live PR state: Live GitHub reports this PR open, non-draft, labeled maintainer, P3, merge-risk: 🚨 compatibility, and status: ⏳ waiting on author; mergeable is CONFLICTING and merge state is DIRTY. (c09ff42c55e9)
  • Current main does not implement the central surface: Current main still defines loaded runtime registry surfaces as active, channel, and http-route; there is no gateway-runtime surface on main. (src/plugins/active-runtime-registry.ts:13, 9d68f877ac3e)
  • Provider lookup still lacks the proposed surface on main: Current main's prepared provider runtime lookup checks only the channel loaded registry surface, so the PR's central provider-handle reuse remains unlanded. (src/plugins/provider-hook-runtime.ts:39, 9d68f877ac3e)
  • PR branch adds the requested surface: The PR branch adds pinActivePluginGatewayRuntimeRegistry and a gatewayRuntime state slot, which matches the startup metadata slice requested by the tracker. (src/plugins/runtime.ts:333, c09ff42c55e9)
  • Branch predates current live-registry lifecycle: The PR branch's runtime state lacks current main's sessionExtension surface and collectLivePluginRegistries lifecycle; its agent-event bridge dispatches from state.activeRegistry instead of the composed live set. (src/plugins/runtime.ts:102, c09ff42c55e9)

Likely related people:

  • mcaxtr: Authored the prepared-runtime tracker, the merged foundation PR, and this PR's startup metadata commits. (role: feature owner and recent area contributor; confidence: high; commits: 5df08201ff50, 89b86672ab70, 8211fc69a3aa; files: src/plugins/runtime.ts, src/plugins/active-runtime-registry.ts, src/gateway/server-plugin-bootstrap.ts)
  • mushuiyu886: Recent commits introduced the session-extension registry pinning behavior that the PR rebase must preserve. (role: introduced related current-main behavior; confidence: medium; commits: b85ae9fb1b4e, 0fb0c2cb8e74; files: src/plugins/runtime.ts, src/plugins/runtime-state.ts, src/gateway/server-plugin-bootstrap.ts)
  • vincentkoc: Committed and tested the session-extension registry changes in the same lifecycle surface now conflicting with the PR branch. (role: recent adjacent contributor and committer; confidence: medium; commits: b85ae9fb1b4e, 6ffa0fb34897; files: src/plugins/runtime.ts, src/plugins/runtime.test.ts, src/gateway/server-plugin-bootstrap.ts)
  • amknight: Authored the live hook registry view change that depends on composed live registry surfaces agreeing across dispatch paths. (role: recent adjacent lifecycle contributor; confidence: medium; commits: 23eadfa27783; files: src/plugins/runtime.ts, src/plugins/active-runtime-registry.ts, src/plugins/loader.hook-runner-live-view.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-startup-metadata branch 3 times, most recently from ae37a8c to fbf8472 Compare May 9, 2026 02:01
@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-startup-metadata branch from fbf8472 to 2091074 Compare May 9, 2026 02:12
@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-startup-metadata branch from 2091074 to c09ff42 Compare May 9, 2026 13:05
@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Jun 28, 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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M 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