Skip to content

refactor(runtime): add prepared runtime foundation#78248

Merged
mcaxtr merged 6 commits into
mainfrom
refactor/prepared-runtime-foundation
May 7, 2026
Merged

refactor(runtime): add prepared runtime foundation#78248
mcaxtr merged 6 commits into
mainfrom
refactor/prepared-runtime-foundation

Conversation

@mcaxtr

@mcaxtr mcaxtr commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Problem: hot reply, tool, outbound, media, provider, TTS, and command paths still have many opportunities to rediscover runtime facts that are already known earlier in the request, such as selected provider, model, channel, target, capability family, or attachment class.
  • Why it matters: repeated request-time rediscovery makes the reply path harder to reason about, encourages broad plugin/provider/channel registry scans, and creates pressure to add scattered cache layers instead of moving canonical runtime facts earlier.
  • What changed: this PR adds the prepared-runtime foundation: reusable contracts, carrier fields, and producers for provider runtime handles, agent runtime plans, scoped model references, outbound channel runtime facts, and TTS/speech runtime facts.
  • What did NOT change: this PR does not migrate existing reply/tool/outbound consumers yet, does not remove legacy resolver behavior, and does not introduce the gateway-runtime loaded registry lookup. That follow-up belongs to the startup loaded/public metadata PR tracked in Tracking: Prepared runtime resolution migration #77700.

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 1 in the prepared runtime resolution migration.

It introduces the shared vocabulary and typed objects that later, smaller migration PRs can consume without each surface inventing its own cache or compatibility wrapper:

  • AgentRuntimePlan gains prepared-runtime slots for auth, prompt, tools, transcript, delivery, outcome, transport, and observability.
  • buildAgentRuntimePlan(...) produces a reusable plan around the selected provider/model/runtime facts.
  • ProviderRuntimePluginHandle carries the selected provider plugin once so provider hook helpers can reuse it.
  • Provider hook helpers accept an existing runtime handle while preserving fallback behavior for callers that do not have prepared facts yet.
  • Scoped model helpers collect configured model references without broad model catalog work.
  • Outbound channel runtime helpers expose prepared channel facts and bundled outbound adapter support.
  • TTS/speech SDK contracts gain the runtime types needed by later loaded-speech migrations.
  • AGENTS.md now names the request-time rediscovery rule directly: if a hot path already knows the provider/model/channel/target/capability/attachment fact, pass that fact forward instead of broad-loading registries to rediscover it.

The important architectural line is that this PR is foundation-only. Existing callers can still omit prepared facts. Later PRs will migrate one surface at a time to consume these objects, prove the prepared path is used, and then remove duplicate lookup branches only when their last migrated caller no longer needs them.

Real behavior proof (required for external PRs)

N/A. Maintainer-authored internal refactor foundation; no user-facing runtime path is migrated in this PR.

Root Cause (if applicable)

  • Root cause: repeated runtime lookup work has been spread across request-time consumers because there was no shared, canonical object for carrying already-known provider/model/channel/tool/runtime facts through the reply path.
  • Missing detection / guardrail: root guidance did not clearly distinguish prepared facts from broad request-time rediscovery, so new code could reasonably call broad loaders even when the request already knew the exact fact.
  • Contributing context: compatibility fallback behavior is still needed for startup, setup, admin, standalone, and legacy callers, so the migration needs additive foundation before consumer behavior can move safely.

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 test or file: src/agents/runtime-plan/build.test.ts
  • Scenario the test should lock in: the runtime plan exposes stable defaults, provider runtime handle reuse, tool schema hooks, transcript policy, transport extra params, and delivery helpers without requiring existing callers to pass prepared facts.
  • Why this is the smallest reliable guardrail: this PR is a foundation PR, so the useful boundary is the plan producer and its default behavior rather than a full reply-path migration.
  • Existing test that already covers this (if any): N/A.

User-visible / Behavior Changes

None. This PR adds foundation contracts and guidance only. Existing runtime consumers continue to work through their current paths.

Diagram (if applicable)

Before:
[selected provider/model/channel known] -> [later consumer broad-loads registry again] -> [uses one fact]

After this PR:
[selected provider/model/channel known] -> [prepared runtime object can carry fact] -> [later PRs consume it]

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 docs:list
  2. pnpm test src/agents/runtime-plan/build.test.ts
  3. pnpm build
  4. git diff --check

Expected

  • Runtime-plan tests pass.
  • Build passes.
  • Diff hygiene is clean.

Actual

  • Runtime-plan tests passed.
  • Build passed.
  • git diff --check 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. The earlier standalone PR1 build failure from referencing the later gateway-runtime surface was resolved by keeping PR1 scoped to existing loaded surfaces and tracking the gateway-runtime handle lookup for PR2.

Human Verification (required)

  • Verified scenarios: runtime-plan unit coverage, full build, diff hygiene, PR branch contains exactly the foundation commit plus changelog/AGENTS guidance.
  • Edge cases checked: existing callers can omit prepared facts; resolveProviderRuntimePluginHandle(...) does not require the later gateway-runtime surface in this PR; unrelated dirty system-prompt local files are not committed.
  • 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: later migration PRs may accidentally depend on a reusable field or helper not present in this foundation.
  • Risk: reviewers may expect this PR to improve request-time performance directly.
    • Mitigation: the scope is explicit: this PR introduces the reusable objects only. Consumer migration and performance proof happen in later PRs.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels May 6, 2026
@clawsweeper

clawsweeper Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR adds prepared-runtime contracts and helper producers for agent runtime plans, provider handles, scoped model refs, outbound channel facts, TTS/speech runtime exports, docs guidance, changelog, and generated SDK metadata.

Reproducibility: not applicable. This PR is an internal foundation refactor, not a report of broken current-main behavior. Source inspection and PR tests cover the prepared-runtime contracts rather than a failing user workflow.

Real behavior proof
Not applicable: Not applicable: the author is a repository MEMBER and the PR is scoped as an internal foundation refactor with no migrated user-facing runtime path.

Next step before merge
This protected maintainer-labeled MEMBER PR needs normal maintainer review and exact-head CI completion; there is no narrow automated repair finding.

Security
Cleared: Cleared: the diff adds TypeScript contracts/helpers, docs/changelog guidance, generated SDK metadata, and tests without new dependencies, workflows, permissions, secret handling, or artifact execution.

Review details

Best possible solution:

Land the additive foundation only after exact-head CI is green and maintainers confirm it stays within the staged PR 1 boundary; keep consumer migrations tracked under #77700.

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

Not applicable: this PR is an internal foundation refactor, not a report of broken current-main behavior. Source inspection and PR tests cover the prepared-runtime contracts rather than a failing user workflow.

Is this the best way to solve the issue?

Yes for the stated scope: the additive contracts and fallback-preserving helpers are a maintainable first step, while consumer migrations remain split into narrower follow-up PRs. Merge should still wait for exact-head CI and maintainer review.

Acceptance criteria:

  • pnpm docs:list
  • pnpm test src/agents/runtime-plan/build.test.ts
  • pnpm build
  • git diff --check
  • Exact-head GitHub Actions checks for 95d7343

What I checked:

  • Protected PR metadata: Live PR metadata shows the PR is open, authored by mcaxtr with author_association: MEMBER, labeled maintainer, based on 6ce1c98b6189c4933adaa8f8632148a2693d0b8b, and headed at 95d73431ddc3257de21b8199817f0510fcd5de44. (95d73431ddc3)
  • Current main lacks the proposed carrier slots: On current main, AgentRuntimePlan does not expose providerRuntimeHandle, prepared tool planning, prompt text transforms, or transformSystemPrompt; those are added by the PR rather than already implemented on main. (src/agents/runtime-plan/types.ts:307, 6ce1c98b6189)
  • Prepared provider handle foundation: The PR head adds ProviderRuntimePluginHandle, resolveProviderRuntimePluginHandle, and ensureProviderRuntimePluginHandle, then threads the resolved handle through runtime-plan prompt, tool, transcript, transport, and delivery helpers. (src/plugins/provider-hook-runtime.ts:233, 95d73431ddc3)
  • Incomplete-handle regression coverage: The PR head includes runtime-plan tests proving incomplete supplied provider handles are resolved before runtime hooks and follow-up routing receive them. (src/agents/runtime-plan/build.test.ts:248, 95d73431ddc3)
  • Related tracking issue remains open: The related tracking issue is open, maintainer-labeled, and explicitly lists this PR as PR 1: the additive prepared-runtime foundation, with later consumer migrations still tracked separately.
  • Exact-head CI still incomplete: At inspection, check runs for head 95d73431ddc3257de21b8199817f0510fcd5de44 grouped as 40 successful, 11 skipped, and 37 still queued. (95d73431ddc3)

Likely related people:

  • 100yenadmin: GitHub commit history for src/agents/runtime-plan/build.ts shows the runtime-plan suite and consolidation were introduced in recent contract-first runtime-plan commits. (role: introduced runtime-plan surface; confidence: high; commits: 860dad268d35, 2c35a6e59976; files: src/agents/runtime-plan/build.ts, src/agents/runtime-plan/types.ts, src/agents/runtime-plan/build.test.ts)
  • steipete: Recent main history shows repeated work on provider hook/cache boundaries, outbound lifecycle routing, and the channel entry SDK surface touched by this PR. (role: recent plugin/outbound/SDK maintainer; confidence: high; commits: 9989512a3710, f43a184103b6, 2ead1502c9bf; files: src/plugins/provider-hook-runtime.ts, src/infra/outbound/channel-resolution.ts, src/plugin-sdk/channel-entry-contract.ts)
  • DmitryPogodaev: Recent provider-hook history includes the startup runtime registry reuse work that this prepared-runtime foundation builds on for loaded runtime lookups. (role: adjacent startup runtime registry owner; confidence: medium; commits: 8283c5d6cc3f; files: src/plugins/provider-hook-runtime.ts)

Remaining risk / open question:

  • Exact-head broad CI is not complete yet; 37 check runs were still queued at inspection.
  • The PR intentionally stops at foundation contracts, so prepared-path performance and migrated consumer behavior remain for follow-up work in Tracking: Prepared runtime resolution migration #77700.
  • Maintainers still need to accept the public SDK and internal contract shape before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 6ce1c98b6189.

@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-foundation branch from df1a408 to 670813d Compare May 6, 2026 03:48
@mcaxtr

mcaxtr commented May 6, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-foundation branch from 670813d to e46b6cd Compare May 6, 2026 04:12
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts labels May 6, 2026
@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-foundation branch from e46b6cd to 4769713 Compare May 6, 2026 04:24
@mcaxtr

mcaxtr commented May 6, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@mcaxtr mcaxtr self-assigned this May 6, 2026
@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-foundation branch 5 times, most recently from 83283be to 95d7343 Compare May 7, 2026 13:07
@mcaxtr
mcaxtr force-pushed the refactor/prepared-runtime-foundation branch from 95d7343 to 1c31ed0 Compare May 7, 2026 21:45
@mcaxtr
mcaxtr merged commit 5df0820 into main May 7, 2026
86 of 88 checks passed
@mcaxtr
mcaxtr deleted the refactor/prepared-runtime-foundation branch May 7, 2026 21:49
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
rogerdigital pushed a commit to rogerdigital/openclaw that referenced this pull request May 9, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
lykeion-dev pushed a commit to lykeion-dev/openclaw--rev that referenced this pull request May 14, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* docs(runtime): document prepared runtime guidance

* refactor(provider-runtime): thread prepared provider handles

* refactor(runtime-plan): add prepared runtime foundation

* refactor(outbound): add prepared channel runtime facts

* refactor(models): add scoped model reference helpers

* refactor(plugin-sdk): expose prepared runtime helper surfaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant