Skip to content

perf(cli): keep read-only commands on cold paths - #117932

Merged
steipete merged 2 commits into
mainfrom
codex/perf-cli-cold-paths
Aug 2, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-cli-cold-paths

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

A full read-only CLI sweep on a production host (48 cores, ~150 installed plugins, warm jiti cache) found nine commands taking 9.7–48 s that should take about a second:

command production wall
gateway usage-cost --days 1 --json 48.2 s
channels list --json 17.2 s
models status --json 15.3 s
approvals pending --json 10.1 s
skills list --json 9.9 s
agents bindings --json 9.8 s
skills check --json 9.8 s
gateway stability --json 9.8 s
commitments --json 9.7 s

Baselines on the same host: openclaw --version 43 ms, gateway call health 1.83 s, sessions --json 2.06 s, channels status --json 1.16 s.

CPU profiles showed the familiar plugin-module load storm (jiti ~2.5 s, package_json_reader ~0.9 s, compile/vm ~1 s) — plus, for channels list, an additional ~5.7 s of filesystem walking (lstat 3.8 s). And a decisive measurement for usage-cost: the underlying RPC gateway call usage.cost --params '{"days":1}' returned in 1.77 s while the CLI command took 48.2 s.

This continues the cold-path work in #117705 / #117751 / #117880 / #117900.

Why This Change Was Made

Each command was audited rather than blanket-patched, and two of them turned out not to be another catalog-declaration bug:

Startup declarations (6 commands). approvals pending and gateway stability are gateway RPC reads → skip config validation and plugin loading. agents bindings is a local config projection → still reads config, skips plugin validation (route bindings do not consume plugin runtime). commitments reads the shared SQLite store → its unnecessary config load was removed outright. skills list/check genuinely need skill/manifest metadata → they skip plugin config validation while keeping the gateway-first, manifest fallback; no plugin module execution.

channels list (17.2 s) — declaration was already effective. The real costs were command-local: requireValidConfig performed plugin validation; JSON listing entered setup-backed fallback logic meant for human credential/status output; and manifest projection, trusted-catalog construction, and installed-ID calculation each rediscovered the same plugin filesystem graph. JSON now stays on manifest-backed projections and one immutable metadata snapshot is carried into the read-only channel plugin reader, trusted catalog, and discovery. Human text output keeps setup-backed snapshots, because removing them would change credential/status output.

Notably, the cross-dispatch parity guard added in #117880 could not have caught this: it proves both resolvers interpret the catalog identically, not that a command-local path is cold. The new fixtures close that gap by executing the real route.

models status (15.3 s) — also command-local. loadModelsConfig re-ran plugin validation inside the command; status eagerly imported payload-validation support; and catalog ownership rediscovered providers broadly. The non-probe path now skips plugin validation, imports payload smoke validation only inside actual Codex runtime-availability evaluation, and carries the complete provider/auth use set into the prepared catalog owner. --probe deliberately keeps full validation and live provider probing.

gateway usage-cost (48.2 s) — not startup at all. The CLI was polling usage.cost, waiting for cacheStatus to become fresh, with reconnect and exponential delay. The gateway intentionally serves cached/in-flight summaries and owns background refresh, and cross-agent aggregation is server-side. The CLI now performs exactly one usage.cost RPC and renders the response.

Per the repository's Codex gate, the sibling Codex contract was inspected directly for the models status change: account/read in ../codex/codex-rs/app-server-protocol/src/protocol/common.rs:1192, dispatch at ../codex/codex-rs/app-server/src/message_processor.rs:1372, and account state ownership at ../codex/codex-rs/app-server/src/request_processors/account_processor.rs:121,1010. The lazy payload check and provider scoping do not alter it.

User Impact

Command Before (prod) After (local dist)
gateway usage-cost 48.2 s 0.62 s*
channels list 17.2 s 3.12 s
models status 15.3 s 3.92 s
approvals pending 10.1 s 0.96 s*
skills list / check ~9.9 s ~1.15 s
agents bindings 9.8 s 0.86 s
gateway stability 9.8 s 0.67 s*
commitments 9.7 s 0.59 s

* no local gateway service was available, so these measure full cold startup plus the failure path rather than live RPC latency; the one-RPC assertions are the behavioral proof for usage-cost. On a comparable local bundled-catalog repro, channels list went 9.71 s → 3.12 s and models status 10.91 s → 3.92 s (1.04 s / 1.46 s with bundled plugins disabled). This checkout cannot reproduce the host's ~150-plugin topology, so the real-route module markers are the scale-independent proof.

No output shapes changed; --probe and human rendering paths are preserved.

Evidence

  • 17 focused test files, 329 tests, run individually (the src/cli directory composition has known order-dependent contamination).
  • Two new real-route cold-import fixtures install a generated plugin whose runtime marks or throws if imported, invoke the actual channels list --json / models status --json routes, verify output, and prove the runtime never executed.
  • Usage RPC-count tests assert exactly one usage.cost call across fresh, refreshing, and stale cache-status responses.
  • pnpm tsgo:core, pnpm build (2m50s, CLI bootstrap guard, no [INEFFECTIVE_DYNAMIC_IMPORT]), git diff --check: passed.
  • Autoreview (Codex gpt-5.6-sol, high): clean, correctness 0.99, no actionable findings.
  • Production LOC +173/-147 (net +26 — a prepared-metadata ownership seam replacing repeated filesystem discovery); tests net +282.

@steipete
steipete marked this pull request as ready for review August 2, 2026 09:32
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 5:37 AM ET / 09:37 UTC.

ClawSweeper review

What this changes

The branch keeps nine read-only CLI commands cold by skipping unnecessary plugin validation and loading, reusing a single plugin metadata snapshot for channel listings, and returning the first usage.cost Gateway response instead of polling for cache freshness.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

This PR remains necessary: it extends the recently merged CLI cold-path work to additional read-only commands and removes command-local metadata rediscovery. The manifest-first snapshot design matches the repository’s hot-path guidance, and no concrete patch defect was established, but the maintainer label requires human handling and the local sibling Codex source required to independently verify the models status Codex-runtime contract is unavailable.

Priority: P2
Reviewed head: 5b701d953dd8861ea75740f869e8364285e1a7ee
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The branch has strong focused behavior evidence and coherent manifest-first ownership, with a remaining compatibility decision and unavailable local Codex-contract check.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.
Evidence reviewed 6 items Manifest-first channel-list path: The branch reads valid core configuration while skipping plugin-schema validation, resolves one process-stable metadata snapshot, and passes its discovery/index facts to the channel readers instead of rediscovering plugins per catalog row.
Gateway owns cached usage summaries: The Gateway has a dedicated usage.cost handler and cache-loading path, supporting the branch’s removal of CLI-side freshness polling while preserving the returned cache-status information.
Usage-cost command contract changed deliberately: Current main gives gateway usage-cost a five-minute command default and polls for a fresh cache; the branch instead sends one RPC through the ordinary transport options, retaining explicit --timeout handling but changing the default wait behavior to the standard RPC timeout.
Findings None None.
Security None None.

How this fits together

The CLI’s startup policy decides whether a command performs local config and plugin work before dispatching to a local projection or the running Gateway. This PR keeps read-only commands on manifest-backed control-plane data and lets the Gateway own cached usage-summary refreshes.

flowchart LR
  CLI[Read-only CLI command] --> Policy[Startup policy]
  Policy --> Config[Core config projection]
  Config --> Metadata[Plugin metadata snapshot]
  Metadata --> Local[Local list or status projection]
  Gateway[Gateway RPC] --> Usage[Usage summary]
  Local --> Output[JSON or text output]
  Usage --> Output
Loading

Decision needed

Question Recommendation
Should gateway usage-cost adopt the standard 10-second default RPC timeout now that it returns cached or in-flight summaries immediately, rather than preserve its former five-minute freshness-wait budget? Accept immediate cached summaries: Keep the one-RPC implementation and standard timeout, with the Gateway continuing background refresh ownership.

Why: This is an operator-visible compatibility choice: the branch intentionally changes latency and freshness semantics, and supported high-volume all-agent deployments determine whether the shorter default is safe.

Before merge

  • Resolve merge risk (P2) - gateway usage-cost changes its default transport timeout from five minutes to the standard 10-second RPC timeout while intentionally stopping cache-freshness polling; confirm that cached all-agent summaries remain safely responsive under supported production load.
  • Resolve merge risk (P1) - The models status change touches Codex runtime availability, but this review could not inspect the required sibling Codex source because ../codex is absent.
  • Resolve merge risk (P1) - The protected maintainer label requires explicit human handling before merge.
  • Complete next step (P2) - No mechanical repair is identified; human confirmation is needed for the usage-cost timeout compatibility choice and the required Codex dependency-contract check.
Agent review details

Security

None.

PR surface

Source +26, Tests +282. Total +308 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 17 175 149 +26
Tests 13 375 93 +282
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 550 242 +308

Review metrics

Metric Value Why it matters
Startup-policy changes 9 read-only command paths The branch broadens cold-path startup behavior across several operator commands, making preserved validation and timeout contracts material before merge.

Stored data model

Persistent data-model change detected: persistent cache schema: src/cli/gateway-cli.coverage.test.ts, serialized state: src/cli/models-status-route-cold-imports.test.ts, vector/embedding metadata: src/channels/plugins/read-only.ts, vector/embedding metadata: src/cli/channels-list-route-cold-imports.test.ts, vector/embedding metadata: src/commands/channels.list.test.ts, vector/embedding metadata: src/commands/channels/list.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm one-RPC timeout behavior (recommended)
    Verify a representative all-agent cached and refreshing usage summary under the intended production topology before accepting the shorter default timeout.
  2. Keep the prior timeout default
    Preserve the five-minute command default while removing only the freshness polling if operators need more than the standard RPC window.
  3. Defer the semantic change
    Pause or split the usage-cost portion if the supported latency envelope cannot be demonstrated before merge.

Technical review

Best possible solution:

Merge only after a maintainer confirms the one-RPC usage-cost timeout behavior is acceptable for supported all-agent deployments and a reviewer with the sibling Codex checkout verifies the lazy runtime-availability contract; otherwise retain the manifest-first cold-path changes and narrow only the affected command behavior.

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

Yes for the code-path change: current main polls usage.cost until freshness with a five-minute default, while the branch performs one RPC; the reported large-plugin timing topology was not independently available in this read-only checkout.

Is this the best way to solve the issue?

Mostly yes: the prepared metadata snapshot follows the repository’s manifest-first, process-stable metadata model, but the shorter usage-cost default timeout and Codex runtime contract need explicit confirmation before this is the best complete solution.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded performance improvement across common CLI read paths, without evidence of an urgent current user outage.
  • add merge-risk: 🚨 compatibility: The branch changes plugin-validation startup behavior and changes the default timeout/freshness behavior of an existing CLI command.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.

Label justifications:

  • P2: This is a bounded performance improvement across common CLI read paths, without evidence of an urgent current user outage.
  • merge-risk: 🚨 compatibility: The branch changes plugin-validation startup behavior and changes the default timeout/freshness behavior of an existing CLI command.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix production and local command timings plus route-level cold-import and one-RPC assertions; a maintainer still needs to confirm the supported all-agent timeout envelope before merge.

Evidence

What I checked:

  • Manifest-first channel-list path: The branch reads valid core configuration while skipping plugin-schema validation, resolves one process-stable metadata snapshot, and passes its discovery/index facts to the channel readers instead of rediscovering plugins per catalog row. (src/commands/channels/list.ts:150, 5b701d953dd8)
  • Gateway owns cached usage summaries: The Gateway has a dedicated usage.cost handler and cache-loading path, supporting the branch’s removal of CLI-side freshness polling while preserving the returned cache-status information. (src/gateway/server-methods/usage.ts:1037, c4810336d575)
  • Usage-cost command contract changed deliberately: Current main gives gateway usage-cost a five-minute command default and polls for a fresh cache; the branch instead sends one RPC through the ordinary transport options, retaining explicit --timeout handling but changing the default wait behavior to the standard RPC timeout. (src/cli/gateway-cli/register.ts:580, 5b701d953dd8)
  • Existing public command documentation: The documented gateway usage-cost interface covers day, agent, and all-agent scopes; it does not promise cache freshness before returning. Public docs: docs/cli/gateway.md. (docs/cli/gateway.md:211, c4810336d575)
  • Related feature history: The supplied merged PRs show the same contributor recently landed the startup-policy unification and adjacent cold-path fixes; local log/blame identifies the current Gateway CLI file as introduced in the available shallow history by Vincent Koc. (src/cli/gateway-cli/register.ts:641, 134dcac3c032)
  • Codex dependency gate unavailable locally: The branch changes lazy Codex runtime availability evaluation, but the required sibling ../codex checkout is absent, so this review cannot independently validate the referenced Codex account protocol and runtime ownership contract. (src/commands/models/list.status-command.ts:417, 5b701d953dd8)

Likely related people:

  • steipete: The provided related merged PRs show repeated ownership of the CLI cold-path, routing-policy, and metadata-only listing work that this branch extends. (role: recent area contributor; confidence: high; commits: 681e8c5ab193, a9bbf45d4bb8, 76ec39556ebd; files: src/cli/command-catalog.ts, src/commands/channels/list.ts, src/commands/models/list.status-command.ts)
  • Vincent Koc: Available local blame and shallow history connect this contributor to the current Gateway CLI command-registration surface that the branch modifies. (role: recent area contributor; confidence: medium; commits: 134dcac3c032, 7cc2e6d83003; files: src/cli/gateway-cli/register.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the all-agent gateway usage-cost timeout envelope on a representative production-sized Gateway.
  • Recheck the models status Codex runtime contract from the required sibling Codex source before merge.

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.

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer landing review resolved the ClawSweeper rank-up moves on head 5b701d953dd8861ea75740f869e8364285e1a7ee:

  • Peter explicitly authorized landing this already-reviewed PR, accepting the documented one-RPC gateway usage-cost behavior and its standard transport timeout. The Gateway remains the owner of cached/in-flight refresh; the CLI renders the immediate response.
  • The Codex contract was rechecked directly in sibling source. account/read is declared as typed GetAccountParams / GetAccountResponse in ../codex/codex-rs/app-server-protocol/src/protocol/common.rs:1192; dispatch is ../codex/codex-rs/app-server/src/message_processor.rs:1372; the account processor owns refresh/config/provider account-state resolution in ../codex/codex-rs/app-server/src/request_processors/account_processor.rs:1010; and the response contract is ../codex/codex-rs/app-server-protocol/src/protocol/v2/account.rs:484. The lazy OpenClaw payload check does not change this protocol or ownership.

Exact-head CI run 30741974645 passed 70/70 jobs. No code or changelog changes were made during landing review.

@steipete
steipete merged commit 4d14f29 into main Aug 2, 2026
181 of 203 checks passed
@steipete
steipete deleted the codex/perf-cli-cold-paths branch August 2, 2026 09:54
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to zenglingbiao/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (59 commits)
  fix(agents): reject false success from delegated file mutations (openclaw#117938)
  fix(macos): reopen AI choice, fix daemon error text, hand onboarding off to the dashboard custodian (openclaw#117921)
  fix(qa): tolerate expected Matrix sync long-poll deadlines (openclaw#117807)
  feat(cli): support --json across reporting commands (openclaw#117928)
  perf(cli): keep read-only commands on cold paths (openclaw#117932)
  fix: prevent fractional chunk limits from stalling text splitting (openclaw#117727)
  fix(qqbot): add heartbeat-ACK liveness watchdog (openclaw#114902)
  chore(openai): defer release note to release flow
  fix(pr): join worktree discovery subprocesses
  test(gateway): widen aggregate event-loop budget (openclaw#117931)
  fix: refresh Buzz room targets after reconnect (openclaw#117927)
  fix: invalidate removed Buzz mention members
  fix: align Buzz explicit mention semantics
  test: split Buzz mention delivery coverage
  fix: preserve Buzz reply session threads
  refactor: keep Buzz mention helpers internal
  fix: invalidate stale Buzz room targets
  fix: tighten Buzz mention disambiguation
  perf: keep Buzz plain sends on the fast path
  fix: reject unresolved Buzz mention text
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* perf(cli): keep read-only commands on cold paths

* perf(channels): reuse list metadata snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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