Skip to content

improve(cli): cut ordinary gateway status startup memory - #133114

Merged
vincentkoc merged 2 commits into
mainfrom
perf/gateway-status-cold-config
Aug 30, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/gateway-status-cold-config

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Related: #132784

What Problem This Solves

Fixes an issue where ordinary openclaw gateway status still loaded the full config runtime and generated schema graph on constrained hosts, even for a missing or plain same-file config. That unnecessary import closure added about 65 MB to cold-process RSS after the earlier duplicate-process fix.

Why This Change Was Made

The status owner now reads missing and plain JSON5 configs through its existing bounded fast path and lazy-loads full config IO only for deep validation, includes, substitutions, root environment blocks, or non-ENOENT read failures.

Lifecycle-only config and service dependencies move out of the presentation helper imported by status. Two daemon helpers that still need full config IO load its runtime owner on demand. Deep status and lifecycle behavior remain unchanged.

User Impact

Ordinary Gateway status checks use materially less transient memory on small hosts while preserving output, RPC probing, malformed-config diagnostics, and full plugin-aware validation for --deep.

Evidence

  • Exact same-clone A/B, five cold runs per config shape:
    • Missing config: median RSS 205.95 MB -> 140.44 MB, down 65.50 MB / 31.81%.
    • Plain config: median RSS 206.91 MB -> 140.41 MB, down 66.50 MB / 32.14%.
  • V8 allocation profiles:
    • Missing config: 57.05 MiB -> 21.82 MiB sampled allocations.
    • Plain config: 56.75 MiB -> 21.29 MiB sampled allocations.
    • Generated schema attribution falls from about 23.5 MiB to 1.5 MiB.
  • Static status import closure: 465 -> 288 built chunks; 4.84 -> 3.09 MiB.
  • Semantic A/B covers missing, plain, include, substitution, root-env, malformed, and deep config paths; normalized status output and exit behavior match.
  • Exact-head focused tests: 178 passed across CLI, daemon, service, lifecycle, status, and cold-import coverage.
  • Exact-head full build: passed.
  • Changed-file gates: all checks passed; the sparse-worktree dead-export scanner was rerun from the hydrated exact-head clone and passed all three scans.
  • Autoreview: Codex Sol/high, no findings; patch rated correct with 0.98 confidence.
  • Complete ARM64 constrained-host matrix: 6/6 passed with zero OOM and OOM-kill events.
    • 1 GB, no swap: 574.65 MB cgroup peak; 393,368 KiB Gateway max RSS; 188,688 KiB status max RSS; zero swap.
    • 1 GB, 2 GB swap: 572.78 MB cgroup peak; 388,988 KiB Gateway max RSS; 186,864 KiB status max RSS; 116.40 MB peak swap.
    • 2 GB, no swap: 1,287.30 MB cgroup peak; 458,132 KiB Gateway max RSS; 237,864 KiB status max RSS; zero swap.
    • 2 GB, 2 GB swap: 1,216.91 MB cgroup peak; 453,200 KiB Gateway max RSS; 239,876 KiB status max RSS; zero swap.
    • 4 GB, no swap: 2,224.07 MB cgroup peak; 557,736 KiB Gateway max RSS; 254,484 KiB status max RSS; zero swap.
    • 4 GB, 2 GB swap: 2,221.26 MB cgroup peak; 550,032 KiB Gateway max RSS; 256,612 KiB status max RSS; zero swap.
  • 1 GB, no-swap soak: 20/20 sequential RPC status calls passed; status max RSS 178,220-209,812 KiB, median 206,390 KiB; zero OOM events and zero swap.
  • ARM gateway status --require-rpc peak RSS fell from about 271 MiB on the prior landed build to 182-251 MiB across the complete matrix; Gateway RSS stayed within the expected host-dependent range.

Production LOC: +54/-47 (net +7) | Tests: +279/-68 (net +211)

The production growth is the lazy owner boundary plus explicit missing-file semantics. Thirty-five production lines are a direct move of lifecycle-only helpers out of the status import closure.

Residual Limits

  • Crabbox artifact transfers were intermittently slow, but all six guest workloads completed and every lease reached terminal cleanup.
  • AWS ARM64 guests approximate Raspberry Pi memory pressure but do not reproduce Raspberry Pi storage latency or firmware exactly.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc vincentkoc self-assigned this Aug 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 3:31 AM ET / 07:31 UTC.

ClawSweeper review

What this changes

This PR keeps ordinary openclaw gateway status on a lightweight config-read path, moves lifecycle-only config helpers out of its import closure, and adds status-path coverage.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: the branch still provides a distinct status-command memory reduction that is absent from current main, and source review found no introduced correctness or security defect.

Priority: P2
Reviewed head: a491a21b60a8319f76b1730f8e70b6024aec4a82

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a bounded owner-level design and focused coverage, pending normal exact-head CI completion.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; supplied constrained-host results support the goal but were not rerun in this read-only review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; supplied constrained-host results support the goal but were not rerun in this read-only review.
Evidence reviewed 6 items Fast-path ownership: The status owner lazily imports full ConfigIO, uses the fast reader for ordinary files, escalates for includes, substitutions, root environment configuration, non-missing read errors, and deep status.
Normal CLI dotenv behavior: Normal CLI startup loads dotenv before route dispatch, so the lightweight status path does not omit the public CLI dotenv loading step.
Missing-config semantics: A missing config is treated as a valid empty fast configuration; the status owner separately supplies bind and port defaults through the config-paths owner.
Findings None None.
Security None None.

How this fits together

Gateway status is a routed CLI command that reads local and service configuration, derives connection details, and reports Gateway health. The change keeps simple status invocations lightweight while retaining full configuration loading for complex or deep inspection paths.

flowchart LR
  A[CLI invocation] --> B[Gateway status route]
  B --> C[Fast config read]
  C --> D{Complex or deep config?}
  D -->|No| E[Derive port and bind defaults]
  D -->|Yes| F[Full configuration loader]
  E --> G[Gateway status report]
  F --> G
Loading

Before merge

  • Complete next step (P2) - The protected maintainer label and unfinished exact-head checks require normal maintainer handling rather than automated repair routing.
Agent review details

Security

None.

PR surface

Source +7, Tests +211. Total +218 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 54 47 +7
Tests 3 279 68 +211
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 333 115 +218

Review metrics

Metric Value Why it matters
Production versus test LOC production +19/-12 after a 35-line move; tests +278/-68 The small semantic production increase establishes the lazy configuration boundary; most production additions relocate lifecycle-only helpers out of status imports.

Stored data model

Persistent data-model change detected: serialized state: src/cli/daemon-cli/status.gather.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

  • Exact-head CI was still running at review time; merge should wait for the required checks and maintainer review.

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused lazy-loading boundary once exact-head checks complete, preserving full ConfigIO escalation for complex and deep status paths.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused lazy-loading boundary once exact-head checks complete, preserving full ConfigIO escalation for complex and deep status paths.

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

Not applicable: this is a PR review; the submitted constrained-host results are supporting evidence, while source review verifies the affected route and its guarded fast path.

Is this the best way to solve the issue?

Yes: route-level lazy loading removes the ordinary status import cost while retaining the existing full-loader contract for configurations that need it.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded CLI performance and constrained-host reliability improvement, with no evidence of an active broad outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; supplied constrained-host results support the goal but were not rerun in this read-only review.

Evidence

What I checked:

  • Fast-path ownership: The status owner lazily imports full ConfigIO, uses the fast reader for ordinary files, escalates for includes, substitutions, root environment configuration, non-missing read errors, and deep status. (src/cli/daemon-cli/status.gather.ts:136, a491a21b60a8)
  • Normal CLI dotenv behavior: Normal CLI startup loads dotenv before route dispatch, so the lightweight status path does not omit the public CLI dotenv loading step. (src/cli/run-main.ts:1200, a491a21b60a8)
  • Missing-config semantics: A missing config is treated as a valid empty fast configuration; the status owner separately supplies bind and port defaults through the config-paths owner. (src/config/paths.ts:465, a491a21b60a8)
  • Regression coverage: Tests cover plain and missing configurations, malformed input, all full-loader escalation triggers, deep plugin-aware status, and the routed cold-import boundary. (src/cli/daemon-cli/status.gather.test.ts:1124, a491a21b60a8)
  • Current-main necessity: The reviewed head differs from fetched current main on the lazy status-config boundary, so the branch's central behavior is not already implemented on main. (src/cli/daemon-cli/status.gather.ts:136, a491a21b60a8)
  • Related merged work: Merged PR 132784 removed the separate duplicate-process respawn cause; this PR addresses the remaining full-config import cost in the same status workflow. (d3c07b02e244)

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-30T06:56:04.465Z sha a491a21 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc marked this pull request as ready for review August 30, 2026 07:24
@vincentkoc
vincentkoc merged commit f1d2c5b into main Aug 30, 2026
325 of 326 checks passed
@vincentkoc
vincentkoc deleted the perf/gateway-status-cold-config branch August 30, 2026 07:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…3114)

* perf(cli): checkpoint lazy gateway status config

* perf(cli): keep gateway status off full config IO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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