Repository navigation
fix(cli): keep gateway-backed agent turns cold - #117705
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 8:24 PM ET / August 2, 2026, 00:24 UTC. ClawSweeper reviewWhat this changesThe branch makes gateway-backed Merge readiness⛔ Blocked until stronger real behavior proof is added - 5 items remain This PR remains necessary: the supplied current main commit does not contain its cold-start boundary changes. The source review found a coherent gateway-first design and no discrete patch defect, but this compatibility-sensitive startup change still needs inspectable after-fix CLI proof before merge; the existing Priority: P2 Review scores
Verification
How this fits togetherThe CLI normally runs startup policy that validates local configuration and loads plugin metadata. Gateway-backed agent and channel-status commands instead send an RPC to the running Gateway, which resolves the request and returns a result for CLI output. flowchart LR
A[CLI invocation] --> B[Startup policy]
B --> C{Local or Gateway-backed}
C -->|Gateway-backed| D[Gateway RPC]
C -->|Local| E[Config and plugin runtime]
D --> F[Agent or channel result]
E --> F
F --> G[CLI JSON or text output]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +28, Tests +129. Total +157 across 20 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the Gateway RPC fast path cold, retain the guarded Do we have a high-confidence way to reproduce the issue? No high-confidence executed reproduction was established in this read-only review. Source and the branch’s focused import-guard tests make the eager local-startup path source-reproducible, but inspectable real runtime proof is still missing. Is this the best way to solve the issue? Yes, provisionally: the branch moves work behind the Gateway-versus-local owner boundary instead of adding a cache or fallback path, and it preserves explicit AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ab8090e0d32f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Maintainer landing note: I am skipping the optional terminal-capture Rank-up moves because this is an explicitly authorized, already-reviewed mechanics-only landing, and the task excludes new proof collection or PR-body polish. The exact head has green CI and focused regression coverage for the startup boundary. I accept the reviewed ownership tradeoff for this PR: gateway-backed |
|
Merged via squash.
|
* fix(cli): keep gateway-backed agent turns cold * test(cli): fix agent session test import
What Problem This Solves
Every gateway-backed
openclaw agentturn paid a large fixed startup tax before the request ever reached the Gateway. On a production host (Hetzner, 48 cores, Node 26.5, ~150 installed plugins, idle) an ordinary turn took 13.0 s wall while the Gateway-measured turn itself (meta.durationMs) was only 3.3–4.9 s. Roughly 9 s was pure client-side startup for a command whose work happens in another process.Genuinely cold CLI commands on the same host show what the baseline should be:
openclaw --versionopenclaw automations list --jsonopenclaw gateway status --jsonopenclaw gateway call healthopenclaw agent … --jsonopenclaw channels status --json(no probe)A CPU profile of one
agentrun (13.6 s sampled) showed ~5 s of module transform/compile plus filesystem walking:jiti2540 ms,package_json_reader.get913 ms,compileSourceTextModule531 ms,node:vm Script496 ms,lstat683 ms, GC 693 ms, alongside a legitimate 3451 ms idle wait for the Gateway's answer.This is not the jiti transform cache underperforming. That cache (#117355) is populated and effective:
~/.cache/openclaw/jiti/<version>holds 9221 files and a repeatplugins listadds zero new files, yet three consecutive runs still take 9.6 / 9.9 / 9.8 s with no warming. The remaining cost is reading, compiling, and executing plugin modules in every short-lived CLI process. Caching transforms cannot remove that; not importing them can.This is a default-path cost: every scripted turn, cron-invoked turn, and operator
openclaw agentcall pays it.Why This Change Was Made
The eager work came from the global pre-action hook, not from anything the turn needs:
src/cli/program/preaction.ts→command-execution-startup.ts→command-bootstrap.ts→config-guard.ts→doctor-config-preflight.ts→doctor-state-migrations.ts→state-migrations.doctor.tsconfig-guard.tsclassified everyagentinvocation as migration-sensitive. The doctor migration module then eagerly imported bundled channel registries and plugin doctor contracts; the contract registry scanned installed manifests and loaded their modules through the jiti-backed loader.Two edges compounded it: text-mode agent calls selected full plugin activation, and
agent-via-gateway.tsunconditionally loaded the session resolver, whose re-export chain reached SQLite session maintenance and the bundled channel runtime.For a remote turn the Gateway — not the CLI — owns config migration, plugin resolution, and session-key derivation. The already-cold commands prove the intended shape:
gateway callexplicitly skips state migration, andautomationsbypasses local Gateway config bootstrap.The fix follows the existing catalog-policy convention rather than adding a new mechanism.
bypassConfigGuardbecomes invocation-aware (the same predicate formloadPluginsandnetworkProxyalready use), so remote turns skip config migration and plugin activation while--localretains both. The session resolver moves behind a real*.runtime.tslazy boundary; ordinary--agentturns omitsessionKeybecause the Gateway already derives it fromagentId. Explicit session IDs, recipients, and non-agent session keys still load it. The same owner fix covers successful JSONchannels status, which returns the Gateway payload before loading local rendering; text formatting and the unreachable-Gateway fallback stay behind the runtime boundary.plugins listis intentionally unchanged: it is a local plugin-inventory command, not an RPC-only client.User Impact
Gateway-backed
openclaw agentturns and successfulopenclaw channels status --jsonrequests no longer pay local config-migration and plugin-runtime startup. Local cold repro (isolated state dir, unreachable loopback Gateway): 5.38 s → 0.52 s. That machine does not have the production fleet's ~150 plugins, so the production win should be larger.No behavior change to
--localruns,--deliver, reply channel/account routing, best-effort delivery, the JSON envelope, or text rendering. Delivery fields are untouched.Evidence
channels statussuccess paths. These are the scale-independent proof; they fail if the eager import returns.pnpm buildpassed includingcheck-cli-bootstrap-imports, with zero[INEFFECTIVE_DYNAMIC_IMPORT]warnings.git diff --checkand targetedoxfmtclean.gpt-5.6-sol, high): clean, no accepted/actionable findings, "patch is correct" (0.87).Known proof gap: the broad
node scripts/run-vitest.mjs src/clidirectory composition did not finish cleanly on the authoring host — an unconstrained run produced unrelated cross-file failures and hung. The first reported failures pass independently at 195/195 and 181/181, indicating order-dependent shared suite-state contamination rather than a changed-path failure. Remote confirmation was unavailable (Blacksmith Testbox binary missing; AWS Crabbox broker login unavailable), so CI is the arbiter for the full composition.Production delta
+293/-265, net +28 lines; most churn is a 249-line channels formatter moving behind its runtime boundary. Tests+146/-17.