Skip to content

fix: let CLI commands exit during cache maintenance - #157884

Merged
RomneyDa merged 6 commits into
mainfrom
fix/release-feedback-cache-maintenance
Sep 25, 2026
Merged

RomneyDa merged 6 commits into
mainfrom
fix/release-feedback-cache-maintenance

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Packaged CLI commands can finish their work but remain alive while compile-cache maintenance traverses or removes filesystem entries.

Why This Change Was Made

Run best-effort maintenance in an unreferenced worker using the existing shipped cache module. The maintenance worker starts without inherited CLI preloads or application loaders, preventing a supported --import openclaw/cli-entry invocation from replaying the CLI and creating nested workers. Node permission mode skips maintenance entirely: worker permissions do not inherit the parent's filesystem restrictions, and copying startup grants would not preserve later revocation.

User Impact

Cache cleanup no longer extends command lifetime. Long-lived processes can finish pruning; short commands can exit without waiting for disposable cache I/O. Existing namespace ownership, age, and size maintenance targets remain intact. Cleanup interrupted by exit may leave the cache above its soft maintenance target until a later process runs long enough to complete pruning. Under Node permission mode, cache entries remain until an unrestricted invocation or the operator removes them. This intentional skip neither starts a denied worker nor performs forbidden writes. This repair preserves quick command exit and best-effort cleanup; it does not provide a hard CLI-only retention guarantee.

Evidence

  • The identical event-driven stalled-maintenance fixture reproduced the original command-exit hang at the unchanged 5-second watchdog; the worker repair exited in 0.650 s. Coordination uses events, without timer polling or a production test hook.
  • Both inherited preload paths (--import arguments and NODE_OPTIONS) reproduced CLI replay and nested maintenance before the isolation fix. The bounded regressions now pass, observe only main-thread CLI effects, await real worker completion, and verify stale-cache removal.
  • Before the permission fix, a real Node permission-mode process denied cache writes while its maintenance worker still deleted the retired cache. Afterward, all 16 selected launcher cases pass, including denied-write and denied-worker cases with no maintenance worker and an intact sentinel, plus unrestricted actual pruning. No per-command warning or configuration option was added. Later-revocation safety follows from never creating a worker in permission mode; live permission-drop behavior was not exercised on Node 24.16.
  • Prior preload-fix proof: 13 launcher cases plus 59 cache/SQLite sibling cases passed (72 total). The earlier complete launcher file passed 125 tests with one existing skip; file 159.073 s, Vitest 181.88 s, wrapper 200.57 s on the loaded local host. The final preload additions have focused proof and await hosted full-file coverage.
  • An isolated smoke of the emitted runtime chunk retired an old build, preserved the current build, and exited naturally in 137 ms without starting a Gateway or touching live state.
  • Strict worker fixtures now explicitly declare empty worker data and parent/worker context. The corrected fixture shard subsequently passed 828 tests with one existing skip.
  • Fresh independent P2 reviews of the preload and permission repairs found no actionable findings. The lead also inspected the production and regression boundaries. Targeted type-aware lint, formatting, and diff checks passed. The local broad changed-check was interrupted during a slow repository-wide ratchet scan and is not counted as passing; final hosted checks remain required.
  • The earlier config-patch timeout did not recur on 65862b9d3fa; its exact shard passed. The earlier Gmail timeout also did not recur. Their causes remain unconfirmed, and final-head hosted CI remains required.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@RomneyDa
RomneyDa marked this pull request as ready for review September 25, 2026 04:05
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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 Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 2:01 AM ET / 06:01 UTC (Revision 4).

ClawSweeper review

What this changes

The branch moves packaged CLI compile-cache maintenance to an unreferenced worker, skips maintenance under Node permission mode, documents that lifecycle, and adds launcher regression coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Current main still starts cache maintenance in the CLI process, so this PR remains useful. The earlier preload and timer-polling findings are addressed at the pinned head, and this review found no current-head correctness defect.

Priority: P2
Reviewed head: f0a535a69489393640f38674620865c2b274f8bb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Direct launcher-process scenarios and a focused worker change provide good evidence, with the permission-mode tradeoff documented.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed cache owner is invoked by the packaged launcher. The PR reports that its real Node launcher fixture exited in 0.650 seconds with cache I/O deliberately stalled, while permission-restricted runs preserved a retired-cache sentinel and an unrestricted run pruned it. The diff changes cleanup timing, not a stored-data format or schema.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed cache owner is invoked by the packaged launcher. The PR reports that its real Node launcher fixture exited in 0.650 seconds with cache I/O deliberately stalled, while permission-restricted runs preserved a retired-cache sentinel and an unrestricted run pruned it. The diff changes cleanup timing, not a stored-data format or schema.
Evidence reviewed 8 items Current main behavior: Current main starts asynchronous maintenance from the CLI process; its cache owner calls the filesystem walk directly.
Launcher entry point: The packaged launcher invokes cache maintenance without awaiting it, so maintenance I/O on current main can still keep the process alive.
Introduced repair: The pinned PR delta starts an unreferenced worker, clears inherited preload arguments and environment options, and skips worker creation when Node permission mode is active.
Findings None None.
Security None None.

How this fits together

The packaged CLI enables a build-scoped Node compile cache before loading commands. Cache maintenance removes old bytecode; its work can affect when a short CLI process exits.

flowchart LR
  CLI[Packaged CLI command] --> Bootstrap[Compile cache bootstrap]
  Bootstrap --> Guard{Node permission mode?}
  Guard -- Yes --> Skip[Skip maintenance]
  Guard -- No --> Worker[Unreferenced maintenance worker]
  Worker --> Cache[Prune old cache entries]
  Bootstrap --> Exit[Command can exit]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +221, Docs +3, Other +25. Total +249 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 221 0 +221
Docs 1 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 29 4 +25
Total 6 256 7 +249

Review metrics

Metric Value Why it matters
Production and test growth production +25 net lines, tests +221 lines The production growth establishes the worker boundary, while the larger test change exercises launcher exit, preload isolation, and permissions.

Technical review

Best possible solution:

Keep one cache-maintenance owner that lets packaged commands exit promptly, prunes during longer-running processes, and never bypasses Node permission restrictions.

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

Yes. Current main invokes the filesystem cleanup in the CLI process, and the event-stalled packaged-launcher fixture directly exercises that path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The existing cache owner retains pruning responsibility, while the unreferenced worker limits command lifetime and the permission-mode guard prevents restricted callers from launching an unrestricted cleanup worker.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed cache owner is invoked by the packaged launcher. The PR reports that its real Node launcher fixture exited in 0.650 seconds with cache I/O deliberately stalled, while permission-restricted runs preserved a retired-cache sentinel and an unrestricted run pruned it. The diff changes cleanup timing, not a stored-data format or schema.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 other.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Cache maintenance can delay packaged CLI exit, but the failure is limited to maintenance activity.
  • merge-risk: 🚨 other: The documented best-effort design can leave old cache entries in short-lived or permission-restricted runs; the member-authored PR explicitly accepts this soft retention target.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 changed cache owner is invoked by the packaged launcher. The PR reports that its real Node launcher fixture exited in 0.650 seconds with cache I/O deliberately stalled, while permission-restricted runs preserved a retired-cache sentinel and an unrestricted run pruned it. The diff changes cleanup timing, not a stored-data format or schema.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed cache owner is invoked by the packaged launcher. The PR reports that its real Node launcher fixture exited in 0.650 seconds with cache I/O deliberately stalled, while permission-restricted runs preserved a retired-cache sentinel and an unrestricted run pruned it. The diff changes cleanup timing, not a stored-data format or schema.

Evidence

What I checked:

  • Current main behavior: Current main starts asynchronous maintenance from the CLI process; its cache owner calls the filesystem walk directly. (node-compile-cache.mjs:55, 1976a166443f)
  • Launcher entry point: The packaged launcher invokes cache maintenance without awaiting it, so maintenance I/O on current main can still keep the process alive. (openclaw.mjs:716, 1976a166443f)
  • Introduced repair: The pinned PR delta starts an unreferenced worker, clears inherited preload arguments and environment options, and skips worker creation when Node permission mode is active. (node-compile-cache.mjs:50, f0a535a69489)
  • Prior findings addressed: The head has preload isolation and a launcher regression coordinated by BroadcastChannel events rather than timer polling. (test/openclaw-launcher.e2e.test.ts:1950, f0a535a69489)
  • Permission-boundary proof: The launcher fixture runs real Node processes in denied-write, denied-worker, and unrestricted modes, checking both worker creation and the final retired-cache sentinel or pruning result. The PR body reports the selected cases passed. (test/openclaw-launcher.e2e.test.ts:1785, f0a535a69489)
  • Documented retention tradeoff: The member-authored PR explicitly chooses best-effort cleanup and documents that restricted processes skip it and short commands may exit before it completes; cache age and size remain soft targets. Public docs: docs/help/environment.md. (docs/help/environment.md:79, f0a535a69489)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (3 earlier review cycles)
  • reviewed 2026-09-25T04:12:16.438Z sha 9b9dff4 :: blocked before merge. :: [P2] Replace timer polling in the launcher regression
  • reviewed 2026-09-25T04:33:36.347Z sha 03de130 :: blocked before merge. :: [P2] Replace timer polling in the launcher regression
  • reviewed 2026-09-25T04:53:02.588Z sha c4caf2b3161088f73eb716f9e693c91866e90ac5 :: blocked before merge. :: [P1] Prevent CLI preloads from starting nested maintenance workers | [P2] Replace timer polling in the launcher regression

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 25, 2026
@RomneyDa
RomneyDa force-pushed the fix/release-feedback-cache-maintenance branch from c4caf2b to c6c81c8 Compare September 25, 2026 05:17
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Head c6c81c8ef3770088b644ea3db0c3758c73340fbc replaces launcher timer polling with a BroadcastChannel handshake between the launcher and its maintenance Worker thread. The same fixture reproduces the original command-exit hang and passes the repair; all 125 launcher cases pass, with one existing skip. The body records measured runtime and the independent review disposition. All four patches rebased unchanged.

The chosen behavior preserves quick command exit and best-effort cleanup: a short-lived CLI may exit before pruning finishes, while a sufficiently long-lived process can complete it. Existing age/size targets are soft maintenance targets; this repair does not promise a hard CLI-only retention bound.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Head 65862b9d3fa addresses the accepted inherited-preload P1. Maintenance workers use empty execArgv and the existing SQLite probe's NODE_OPTIONS/BUN_OPTIONS isolation pattern. Both supported preload routes reproduced CLI replay/nested maintenance before the fix and now pass, including real stale-cache pruning. The stalled-maintenance fixture is event-driven and injects its fault only into its copied fixture module.

All 72 selected launcher/cache/SQLite tests passed, fresh P2 review found no actionable findings, and targeted lint/format checks passed. The body records the interrupted broad local scan and pending final hosted CI accurately. Quick CLI exit and interruptible best-effort pruning remain the documented behavior; no hard CLI-only retention guarantee is introduced.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Head f0a535a6948 fixes the accepted Node permission-mode findings. Disposable cache maintenance is intentionally skipped whenever Node permission mode is active, so it cannot start a denied worker or bypass filesystem restrictions. This also avoids relying on a static grant snapshot after possible revocation. No fallback reintroduces blocking CLI cleanup; no new configuration or command warning is added. The limitation is documented.

Before the fix, a denied-write process's worker deleted a synthetic retired cache. All 16 selected launcher cases now pass, including restricted-mode no-worker/sentinel preservation and unrestricted actual pruning. Fresh P2 review and targeted lint/format checks pass. The previous config-patch CI timeout did not recur on the preceding head; final-head CI remains pending. The body retains the proof limits accurately.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Sep 25, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@RomneyDa
RomneyDa merged commit 1276071 into main Sep 25, 2026
232 checks passed
@RomneyDa
RomneyDa deleted the fix/release-feedback-cache-maintenance branch September 25, 2026 21:26
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
* fix: let CLI commands exit during cache maintenance

* test: declare empty data in synthetic worker fixture

* test: declare thread context in heartbeat fixtures

* test(cli): coordinate stalled cleanup through events

* fix(cli): isolate cache maintenance worker preloads

* fix(cli): respect Node permissions during cache maintenance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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: 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