Skip to content

fix(cli): oversized secrets plans consume unbounded memory - #109652

Merged
steipete merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-secrets-plan-size-limit
Jul 18, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-secrets-plan-size-limit

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators running openclaw secrets apply --from <path> could make the CLI fully allocate and parse an arbitrarily large plan file before its shape was validated. A 32 MiB valid JSON file reached plan validation instead of being rejected at the file boundary, creating avoidable memory pressure before either dry-run or mutation could begin.

Why This Change Was Made

The serialized plan-file boundary now has one 16 MiB contract for both commands that own it. secrets configure --plan-out measures the exact UTF-8 bytes of its pretty-printed JSON before writing, while secrets apply --from opens the path non-blockingly, verifies the pinned descriptor is a regular file, and uses the existing bounded reader. This prevents configure from emitting a plan file that apply would reject solely because of its size, and prevents FIFO paths from stalling before regular-file validation.

The limit is shown in both CLI help paths and documented in the canonical plan contract and Secrets CLI reference for hand-written plans and external generators. Plan schema, target validation, provider behavior, in-memory configure/apply behavior, and apply semantics are unchanged.

A fresh semantic recall checked 26 open pull requests. The closest changes improve malformed-JSON and missing-file diagnostics in the same reader, but neither bounds successful file reads or aligns generated-plan output with an apply-time byte contract.

User Impact

Oversized secrets plans now fail early with a clear byte-limit error instead of being fully loaded and parsed. FIFO and other special-file paths are rejected without waiting for a writer. Plans at or below 16 MiB can still be generated and applied. If interactive configuration would produce a larger file, --plan-out now fails before creating an unusable artifact.

Evidence

Real CLI proof on the fixed apply path:

$ openclaw secrets apply --from small-plan.json --dry-run
Secrets apply dry run: no changes.
exit=0

$ openclaw secrets apply --from 32MiB-plan.json --dry-run
Secrets apply failed: Secrets plan file exceeds 16777216 bytes: ...
exit=1

The 32 MiB fixture was valid JSON (whitespace followed by {}), and the output did not reach the previous Invalid secrets plan file diagnostic. The same real CLI check on the pinned latest-main snapshot still reached Invalid secrets plan file, confirming the problem remained upstream before this patch.

Focused validation after review feedback:

node node_modules/vitest/vitest.mjs run src/cli/secrets-cli.test.ts
Test Files  1 passed (1)
Tests       19 passed (19)

node_modules/.bin/oxfmt --check src/cli/secrets-cli.ts src/cli/secrets-cli.test.ts docs/cli/secrets.md docs/gateway/secrets-plan-contract.md
All matched files use the correct format.

node_modules/.bin/oxlint --quiet src/cli/secrets-cli.ts src/cli/secrets-cli.test.ts
exit=0

pnpm docs:check-mdx
Docs MDX check passed (732 files).

git diff --check 7f50fb6bfec6f686ee4cf7bdc966f8056e2aabc9 HEAD
exit=0

The regression coverage drives the real Commander actions and locks both sides of the serialized contract: configure writes an exact 16 MiB plan, rejects a 16 MiB + 1 byte plan without creating the output file, apply rejects an oversized input before runSecretsApply is called, and a writerless Unix FIFO is rejected within a one-second bound. Gateway startup is not part of this behavior because plan-file serialization and loading complete in the standalone CLI before apply or any Gateway interaction begins.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Jul 17, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 2:14 AM ET / 06:14 UTC.

Summary
The PR limits secrets configure --plan-out and secrets apply --from plan files to 16 MiB, rejects non-regular input paths without blocking, and adds corresponding tests and documentation.

PR surface: Source +28, Tests +141, Docs +10. Total +179 across 5 files.

Reproducibility: yes. with medium confidence: the PR gives a concrete current-main scenario using a valid 32 MiB JSON plan and records the differing apply diagnostic, but this review did not independently execute that path.

Review metrics: 1 noteworthy metric.

  • Plan-file contract: 1 new 16 MiB ceiling enforced by 2 commands. The matched output and input boundary avoids generated plans that apply would reject, but it is a user-visible compatibility decision.

Stored data model
Persistent data-model change detected: serialized state: docs/cli/secrets.md, serialized state: docs/gateway/secrets-plan-contract.md, serialized state: src/cli/secrets-cli.test.ts, serialized state: src/cli/secrets-cli.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Confirm whether the 16 MiB limit is the intended supported ceiling for existing and external plan-generation workflows.

Risk before merge

  • [P1] Merging establishes a new hard public limit: existing operators or generators with valid plans larger than 16 MiB will fail at --plan-out or apply --from rather than continuing through the prior path.

Maintainer options:

  1. Confirm and merge the shared ceiling (recommended)
    Accept 16 MiB as the supported CLI file contract because configure and apply now enforce the same boundary and the documented failure is explicit.
  2. Adjust the compatibility contract first
    Change the ceiling or introduce an approved supported large-plan path before merge if current operator workflows cannot safely be capped at 16 MiB.

Next step before merge

  • [P2] A maintainer must choose whether the new 16 MiB public plan-file ceiling is acceptable for existing operator workflows; there is no concrete mechanical repair to dispatch.

Maintainer decision needed

  • Question: Should OpenClaw adopt a 16 MiB hard ceiling for existing and externally generated secrets plan files in both secrets configure --plan-out and secrets apply --from?
  • Rationale: The implementation is internally consistent, but the numeric ceiling changes an existing public CLI workflow for unusually large valid plans and is not derivable from a purely mechanical correctness check.
  • Likely owner: steipete — The PR is assigned to this reviewer and the latest timeline activity indicates direct involvement with the current head.
  • Options:
    • Adopt the 16 MiB contract (recommended): Accept the documented ceiling and merge the shared configure/apply enforcement with its boundary coverage.
    • Choose a different compatibility boundary: Revise the public ceiling or output behavior before merge if existing large-plan workflows need a different supported path.

Security
Cleared: The patch uses existing local file-descriptor reading, adds no dependency or workflow changes, and introduces no concrete security or supply-chain regression.

Review details

Best possible solution:

Confirm that 16 MiB is the intended long-term serialized secrets-plan contract for existing and external workflows, then retain the matched configure/apply boundary and documentation as the canonical behavior.

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

Yes, with medium confidence: the PR gives a concrete current-main scenario using a valid 32 MiB JSON plan and records the differing apply diagnostic, but this review did not independently execute that path.

Is this the best way to solve the issue?

Unclear until the ceiling is accepted: sharing one bounded serialized-file contract across generation and application is the maintainable implementation, while the chosen 16 MiB value needs maintainer confirmation.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a bounded CLI reliability and memory-pressure improvement with limited blast radius, pending an intentional compatibility decision.
  • merge-risk: 🚨 compatibility: The PR newly rejects existing valid serialized plan files over 16 MiB at two public CLI entry points.
  • 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 (terminal): The PR body supplies after-fix terminal evidence for both an allowed small plan and an oversized valid JSON plan rejected at the new file boundary; focused regression coverage supplements that direct CLI proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix terminal evidence for both an allowed small plan and an oversized valid JSON plan rejected at the new file boundary; focused regression coverage supplements that direct CLI proof.
Evidence reviewed

PR surface:

Source +28, Tests +141, Docs +10. Total +179 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 1 36 8 +28
Tests 1 141 0 +141
Docs 3 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 187 8 +179

What I checked:

  • Shared serialized-plan boundary: The proposed CLI implementation defines one 16 MiB byte limit, applies it before writing generated plans, and validates opened input descriptors as regular files before bounded reading. (src/cli/secrets-cli.ts:50, f37fd3f26798)
  • Public contract documentation: The PR documents that generated plans and external --from inputs must be regular files no larger than 16 MiB, including whitespace. Public docs: docs/gateway/secrets-plan-contract.md. (docs/gateway/secrets-plan-contract.md:12, f37fd3f26798)
  • Boundary regression coverage: The PR adds coverage for exact-limit output, one-byte-over output rejection, oversized apply input before runSecretsApply, and a writerless FIFO rejection bound. (src/cli/secrets-cli.test.ts:384, f37fd3f26798)
  • Real behavior proof: The PR body records successful small-plan dry-run behavior and an oversized valid JSON plan failing with the new byte-limit diagnostic rather than reaching JSON-plan validation. (f37fd3f26798)
  • Maintainer involvement: The provided timeline shows steipete assigned this PR on 2026-07-18 and acting on the latest head update, so the remaining public-contract choice already has active maintainer attention. (src/cli/secrets-cli.ts:50, f37fd3f26798)

Likely related people:

  • steipete: The supplied PR timeline shows assignment and a head-update action at the latest review cycle, making this the strongest available routing signal for the secrets-plan contract decision. (role: assigned reviewer and recent branch-update actor; confidence: medium; commits: f37fd3f26798; files: src/cli/secrets-cli.ts, docs/gateway/secrets-plan-contract.md)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-17T04:53:29.193Z sha 1e9dba6dfc9c9ffadca53fe3da6dede9da21a6a5 :: needs changes before merge. :: [P1] Enforce the same size boundary when generating plans
  • reviewed 2026-07-17T08:11:47.831Z sha 4fe4d1416a9adbc7073e560d717e7333279d347e :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T17:45:42.867Z sha f1151ce8372663e0d5b8d4515379bc6e30f13342 :: needs maintainer review before merge. :: none

@zhangguiping-xydt
zhangguiping-xydt requested a review from a team as a code owner July 17, 2026 08:04
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S and removed size: XS labels Jul 17, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 17, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/problem-secrets-plan-size-limit branch from 4fe4d14 to f1151ce Compare July 17, 2026 17:39
@steipete steipete self-assigned this Jul 18, 2026
@steipete
steipete force-pushed the fix/problem-secrets-plan-size-limit branch from f1151ce to f37fd3f Compare July 18, 2026 06:11
@steipete
steipete merged commit 75982be into openclaw:main Jul 18, 2026
113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…109652)

* fix(cli): reject oversized secrets plan files

* fix(cli): keep generated secrets plans applyable

* fix(cli): reject special plan files without blocking

* docs(cli): refresh secrets plan documentation map
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…109652)

* fix(cli): reject oversized secrets plan files

* fix(cli): keep generated secrets plans applyable

* fix(cli): reject special plan files without blocking

* docs(cli): refresh secrets plan documentation map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime 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: S 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.

2 participants