refactor: internalize OpenClaw agent runtime#85341
Conversation
Dependency Changes DetectedThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddf38a8da3
ℹ️ 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".
| function getDefaultAgentDir(): string { | ||
| return getAgentDir(); |
There was a problem hiding this comment.
Use the canonical default agent directory
When callers use the new public createAgentSession() default without passing agentDir, this helper falls back to the copied runtime getAgentDir(), which defaults to ~/.openclaw/agent; OpenClaw’s canonical default agent directory is resolved through resolveDefaultAgentDir({}) (src/agents/agent-scope-config.ts:211-215) as ~/.openclaw/agents/<default>/agent. In that default SDK path, existing models.json, auth profiles, settings, and sessions are missed, so createAgentSession() can report no usable models or create state in the wrong directory even though the normal OpenClaw agent is configured.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3de7163da9
ℹ️ 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".
| @@ -57,7 +57,7 @@ function resolveAnthropicEphemeralCacheControl( | |||
| cacheRetention: AnthropicPayloadPolicyInput["cacheRetention"], | |||
| ): AnthropicEphemeralCacheControl | undefined { | |||
| const retention = | |||
| cacheRetention ?? (process.env.PI_CACHE_RETENTION === "long" ? "long" : "short"); | |||
| cacheRetention ?? (process.env.OPENCLAW_CACHE_RETENTION === "long" ? "long" : "short"); | |||
There was a problem hiding this comment.
Preserve PI_CACHE_RETENTION in Anthropic cache policy
When an upgraded environment still sets PI_CACHE_RETENTION=long and does not pass an explicit cacheRetention, this resolver now falls back to short because it only checks OPENCLAW_CACHE_RETENTION. This payload policy is used by the Anthropic transport/shared provider wrappers, so existing deployments silently lose long-lived cache-control TTLs until operators rename the env var; keep the legacy alias during the migration window to avoid changing token/cache behavior.
Useful? React with 👍 / 👎.
|
In the status information of version 2026.05.28, I found that the Runtime declaration has changed from OpenClaw Pi Default to OpenClaw Default. I did some research on this and eventually found this Merged PR. Goodbye Pi. |
Summary
This PR removes the old Pi-shaped agent/runtime architecture from OpenClaw and re-integrates that functionality as OpenClaw-owned core, plugin, and SDK surfaces.
The main result is that OpenClaw no longer treats Pi as an embedded dependency or organizing concept. Agent execution, model/provider handling, sessions, compaction, transcript storage, provider startup, plugin runtime loading, and docs/tests now use OpenClaw names, OpenClaw ownership boundaries, and OpenClaw package/runtime contracts.
At a high level this PR:
@openclaw/agent-corepackage from the previously embedded agent runtime code.Why
The previous structure still had Pi concepts in places where OpenClaw should own the abstraction directly:
That made the refactor look like a dependency shuffle instead of a real integration. This PR makes the structure look like Pi had never existed as a separate internal dependency: OpenClaw owns the runtime core, providers own provider behavior, plugins cross into core through the SDK/manifest contracts, and compatibility is explicit/deprecated at the public boundary only.
Architectural Changes
OpenClaw Agent Core
Adds a new workspace package at
packages/agent-core.This package now owns the reusable agent runtime primitives that were previously internalized from the Pi dependency shape:
The package is exported as
@openclaw/agent-coreand wired into root package/build config, workspace config, TypeScript config, and package manager metadata.Core OpenClaw code now imports the shared runtime contracts from this package instead of reaching through Pi-named local modules or dependency shims.
Agent Runtime Naming And Ownership
Renames Pi-era agent files and tests under
src/agentsinto OpenClaw-owned names.Examples of the broad rename/integration:
pi-auth-*becameagent-auth-*pi-bundle-*becameagent-bundle-*pi-hooksbecameagent-hookspi-settingsbecameagent-settingspi-tools*becameagent-tools*pi-project-settings*becameagent-project-settings*pi-model-discovery*becameagent-model-discovery*pi-agent-core.d.tsbecameagent-core.d.tsThe goal is not just cosmetic. The renamed modules now sit behind OpenClaw runtime ownership:
Runtime And Plugin Boundary Cleanup
The PR tightens the boundary between core and plugins.
Core remains plugin-agnostic and no longer carries provider/plugin behavior simply because the old dependency needed it. Provider-specific defaults, catalogs, auth choices, discovery, and stream behavior move toward provider-owned packages or focused SDK seams.
Important changes include:
Provider And Model Refactor
This PR removes the old static model-catalog shape from core and replaces it with OpenClaw/provider-owned registry behavior.
Key points:
The new LLM area under
src/llmowns core model/provider contracts and built-in provider implementations:Provider Dependencies Move To Owning Extensions
Provider-only dependencies are moved out of root/core and into the owning provider/plugin packages.
The most visible case is AWS/Bedrock:
Other provider packages and shrinkwraps are updated similarly where dependencies were previously inherited from the Pi/root dependency shape.
Session And Transcript Unification
This PR consolidates session storage and transcript writing around OpenClaw-owned config/session modules and the new agent-core session abstractions.
Changes include:
This is intended to remove the old split between a Pi session stack and an OpenClaw session stack.
Compaction And Context Runtime Cleanup
Compaction and context-engine code is updated to use the OpenClaw agent-core/runtime shape.
The PR:
packages/agent-coreACPX Runtime Turn Deduplication
The ACPX plugin had duplicated lazy turn/run-turn adapter logic in both registration and service paths.
This PR extracts that into
extensions/acpx/src/runtime-turn.tsand updates both callers to use the shared helper.That shared helper now owns:
startTurnrunTurnruntimes tostartTurnThe behavior stays equivalent, but the implementation is now one path.
Google And Vertex Stream Projection Deduplication
src/llm/providers/google.tsandsrc/llm/providers/google-vertex.tshad near-identical streaming loops.This PR moves the shared projection into
consumeGoogleGenerateContentStream(...)insrc/llm/providers/google-shared.ts.The shared path handles:
toolUsewhen tool calls are presentA new focused test,
src/llm/providers/google-shared.test.ts, locks the shared projection behavior across text, thinking, tool calls, response ids, stop reasons, and usage/cost accounting.Unsafe Integer JSON Parser Deduplication
Ollama had a local copy of the unsafe-integer-preserving JSON parser that already existed in core agent transport code.
This PR promotes that parser to a narrow generic SDK subpath:
src/plugin-sdk/json-unsafe-integers.tsopenclaw/plugin-sdk/json-unsafe-integersThe Ollama extension now imports the shared parser through the SDK boundary instead of duplicating the implementation or reaching into core internals.
Package exports, SDK entrypoint metadata, SDK docs, and plugin SDK export checks are updated for the new subpath.
Test Fixture Deduplication
src/agents/sandbox/workspace-skills-bridge-readonly.test.tsrepeated the same remote shell runner fixture in multiple cases.This PR extracts that fixture into one typed local helper inside the test file. The tests keep the same assertions, but the duplicate shell runner setup is gone.
Duplicate Scan Cleanup
After the final cleanup pass, duplicate scanning reports zero clones across the configured duplicate scan targets:
This specifically removed the remaining ACPX, Google/Vertex, Ollama JSON parser, and sandbox test fixture duplicate reports.
Plugin SDK And Compatibility
The plugin SDK is updated to expose only intentional OpenClaw seams.
Changes include:
agent-coreand agent-session SDK forwarding surfacesjson-unsafe-integersas a generic parser utility for plugin-owned runtime codeCompatibility is kept where it is a real public/plugin boundary, not where it was merely internal implementation convenience.
Old public compatibility paths are represented through explicit compatibility/deprecation metadata and tests instead of being treated as current internal architecture.
Legacy Pi Cleanup
This PR removes Pi as an internal runtime/package concept.
Removed or renamed areas include:
Remaining compatibility is intentionally narrow and boundary-owned:
Documentation Changes
The documentation is updated to describe the new OpenClaw-owned architecture.
Major doc changes include:
docs/agent-runtime-architecture.mddocs/pi-dev.mdtodocs/openclaw-agent-runtime.mddocs/pi.mdLicensing And Notices
Because this PR internalizes code that originated in the Pi dependency shape, it updates repository notices:
LICENSEgets the relevant additional copyright/provenance text.THIRD_PARTY_NOTICES.mdrecords incorporated Pi-derived code.macOS App Cleanup
The macOS app no longer carries its own static model catalog loader path from the old model-catalog architecture.
Removed:
apps/macos/Sources/OpenClaw/ModelCatalogLoader.swiftapps/macos/Tests/OpenClawIPCTests/ModelCatalogLoaderTests.swiftThe app should consume the current OpenClaw model/provider surfaces instead of maintaining a parallel static catalog loader.
Build, Tooling, And CI Metadata
The PR updates build/test/tooling metadata to match the new package/runtime layout:
packages/agent-coretsconfigandtsdownpackage/build wiringReview Shape
The branch is organized as a stack of focused commits rather than one giant mechanical blob.
Commit themes:
Behavior Notes
Expected behavior should stay the same for normal OpenClaw users, except that internal ownership, docs, diagnostics, and developer-facing names now reflect OpenClaw instead of Pi.
Intentional behavior/architecture changes:
Verification
Behavior addressed: fully internalize the old Pi-shaped agent runtime into OpenClaw-owned core/plugin/SDK surfaces; remove Pi-era runtime/provider/session duplication; keep only explicit deprecated compatibility at public/plugin boundaries; confirm no duplicate scan findings remain.
Real environment tested: local macOS checkout on branch
refactor/openclaw-agent-runtime-cleanupat pushed headf650426d547d8d2b15d2cef3ca228dddd51dbdc3; AWS Crabbox Linux runner for broad changed gate before the final rebase, provideraws, leasecbx_9b165c987860, runrun_958f0472af21.Exact steps or command run after this patch:
node scripts/run-vitest.mjs src/agents/sandbox/workspace-skills-bridge-readonly.test.ts src/llm/providers/google-shared.test.ts extensions/acpx/register.runtime.test.ts extensions/acpx/src/service.test.ts extensions/ollama/src/stream.test.ts src/plugin-sdk/api-baseline.test.ts src/plugin-sdk/channel-message.test.tspnpm buildnode scripts/check-plugin-sdk-subpath-exports.mjsnode scripts/sync-plugin-sdk-exports.mjs --checknode scripts/check-extension-plugin-sdk-boundary.mjsgit diff --check origin/main...HEADpnpm dup:check:json.agents/skills/autoreview/scripts/autoreview --mode local --no-web-searchpnpm crabbox:run -- --idle-timeout 90m --ttl 240m --timing-json --shell -- "env CI=1 NODE_OPTIONS=--max-old-space-size=4096 OPENCLAW_TEST_PROJECTS_PARALLEL=6 OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=900000 pnpm check:changed"Evidence after fix:
autoreview clean: no accepted/actionable findings reportedpnpm check:changed: exit 0 on runrun_958f0472af21, leasecbx_9b165c987860Observed result after fix: OpenClaw builds with the new
@openclaw/agent-corepackage and renamed runtime surfaces; focused ACPX/Ollama/Google/plugin-SDK/sandbox tests pass; SDK exports are consistent; plugin boundary guards pass; duplicate scanner reports zero clones across all configured targets; broad changed gate passed on AWS Crabbox before the final rebase; the branch is rebased onto currentorigin/mainand pushed atf650426d547d8d2b15d2cef3ca228dddd51dbdc3.What was not tested: full release packaging, full live provider authentication against every provider, macOS app UI runtime behavior, and a successful post-rebase Crabbox rerun. A post-rebase Crabbox attempt was made, but one AWS lease lost SSH after sync before command start and a retry lease never opened SSH during bootstrap; those were infrastructure failures before tests executed, not test failures. Post-rebase local focused tests and build passed.