Skip to content

fix(cli): close standalone memory managers after commands - #118500

Merged
steipete merged 1 commit into
mainfrom
codex/qa0803-memory-cli-teardown
Aug 3, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa0803-memory-cli-teardown

Conversation

@steipete

@steipete steipete commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Standalone memory-backed commands such as openclaw wiki get ... --json printed their correct result but never exited because standalone memory managers retained active filesystem watchers.

Why This Change Was Made

The memory-runtime owner records the authoritative standalone-manager activity fact in the existing lightweight runtime-presence owner. The unchanged CLI finalizer can then close both current and retired standalone managers without importing heavy memory code for ordinary help/status commands.

User Impact

Memory-backed CLI commands terminate naturally after returning their result. Commands that never initialize memory retain their intentional fast startup behavior.

Real Packaged CLI / SQLite / Watcher Proof

Exact committed memory-state/runtime candidate files were rebuilt on an isolated Testbox and run through the actual packaged operator CLI, real configured memory-core, real per-agent SQLite, and its default live filesystem watcher:

$ node openclaw.mjs wiki --help
natural exit: 0

$ node openclaw.mjs wiki get memory/missing.md --corpus memory --json
result: null
natural exit: 0, 9139 ms, forced termination: false

$ node openclaw.mjs wiki get memory/empty.md --corpus memory --json
result: {corpus:"memory",path:"memory/empty.md",content:"",fromLine:1,lineCount:200}
natural exit: 0, 4035 ms, forced termination: false

$ node openclaw.mjs wiki get memory/broken.md --corpus memory --json
error: path must be a regular file
natural exit: 1, 4134 ms

real per-agent SQLite database: 528384 bytes
real default filesystem watcher: enabled

Before the fix, the same genuine successful commands emitted complete JSON but remained alive until a supervisor killed the leaking process. Testbox run: https://github.com/openclaw/openclaw/actions/runs/30787071524

Regression Evidence

  • Red-first owner regressions: three failed before repair.
  • memory-runtime suite 11/11; memory-state suite 18/18; unchanged CLI exit/startup suite 199/199.
  • Partial initialization, current+retired manager replacement, failed close/retry, cache rearm, and config-only cold startup remain covered.
  • Git history proves standalone registry ownership (6c9b38862d2) bypassed the intentional lightweight startup guard (a5cb9ec674b).
  • Independent structured Sol/high review clean, confidence 0.91.
  • Production +16 lines including formatter import expansion; no CLI production, SQLite schema, auth, config, or public SDK changes.
  • AI-assisted implementation and independently verified source review.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 3, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 1:38 AM ET / 05:38 UTC.

ClawSweeper review

What this changes

The PR marks standalone plugin-backed memory managers as active so the CLI finalizer closes their watcher-owning runtime after memory-backed commands finish.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This is still necessary: current main’s CLI finalizer only cleans up when the global memory-runtime check is true, but standalone plugin-backed managers are intentionally outside that registry. The branch records that owner-boundary fact and uses the existing finalizer/cleanup path; no discrete correctness defect was found. The protected maintainer label leaves final merge judgment to a human after checks complete.

Priority: P2
Reviewed head: 1970d4592de56c7a73b35183c3c0779eccaebafa
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused source repair, owner tests, and packaged CLI proof make this a normally mergeable-quality fix, subject to protected-label review and exact-head checks.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.
Evidence reviewed 5 items Current-main lifecycle gap: Current main’s CLI finalizer exits early unless hasMemoryRuntime() is true, while the standalone registry path creates a memory-runtime owner outside the active plugin registry; a standalone manager can therefore remain outside the finalizer’s cleanup eligibility fact.
Owner-boundary repair: The branch sets standalone-manager activity only after selecting a standalone runtime owner, clears it after successful all-manager cleanup, and leaves it true after a cleanup error so a later retry still runs.
Regression coverage: The branch adds coverage for cold config lookup, standalone acquisition, rearming after cleanup, workspace replacement, per-agent cleanup, failed acquisition, and failed cleanup retry. Current-main CLI coverage already verifies that a true runtime fact invokes shared cleanup.
Findings None None.
Security None None.

How this fits together

Standalone CLI commands can lazily load a configured memory plugin without registering it in the gateway’s active plugin registry. The CLI finalizer consults memory runtime state before calling shared cleanup, which must release filesystem watchers without making ordinary help or configuration commands load the memory runtime.

flowchart LR
  A[CLI wiki command] --> B[Memory runtime owner]
  B --> C[Standalone plugin registry]
  C --> D[Memory manager and watcher]
  D --> E[Runtime activity fact]
  E --> F[CLI finalizer]
  F --> G[Close memory managers]
  G --> H[Natural process exit]
Loading

Decision needed

Question Recommendation
Should the protected maintainer review accept the standalone-runtime activity fact as the canonical cleanup eligibility signal after required checks complete? Approve canonical activity fact: Merge after exact-head checks complete because the fact is recorded where standalone watcher ownership begins and preserves lazy CLI startup.

Why: The patch is small and source-supported, but the maintainer label reserves final merge judgment for a human despite sufficient behavior proof.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main and required checks are still running; merge after GitHub evaluates the exact head against the current base and required checks complete.
  • Complete next step (P2) - No mechanical repair is needed; a human must clear the protected maintainer label and wait for exact-head checks before merge.
Agent review details

Security

None.

PR surface

Source +16, Tests +68. Total +84 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 18 2 +16
Tests 1 68 0 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 86 2 +84

Review metrics

Metric Value Why it matters
Lifecycle bookkeeping 1 activity fact added; 3 focused regressions added The patch leaves CLI code unchanged and confines watcher-cleanup eligibility to the standalone memory-runtime owner.
Production versus tests production +16 net; tests +68 The production growth implements one ownership fact and lifecycle reset, while the larger test delta exercises replacement and failure paths.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/plugins/memory-runtime.test.ts, vector/embedding metadata: src/plugins/memory-runtime.test.ts, vector/embedding metadata: src/plugins/memory-state.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the owner-boundary activity fact after protected-label review and exact-head CI complete, while retaining the existing lazy finalizer so non-memory CLI commands do not import the memory runtime.
  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 owner-boundary activity fact after protected-label review and exact-head CI complete, while retaining the existing lazy finalizer so non-memory CLI commands do not import the memory runtime.

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

Yes. Source establishes that a standalone watcher-owning manager can be created while current main’s CLI finalizer sees no active global memory runtime; the PR body also supplies after-fix packaged command transcripts with natural exits.

Is this the best way to solve the issue?

Yes. Recording the resource-ownership fact in the standalone memory-runtime owner enables the existing shared cleanup without importing heavy memory code for ordinary CLI commands.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.
  • 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 (terminal): The updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded CLI command-exit regression with a defined owner and no evidence of data loss, security impact, or broad availability failure.
  • 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 updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides after-fix packaged CLI terminal output showing natural exits for successful, missing, and error wiki-get paths with real SQLite state and an enabled filesystem watcher.

Evidence

What I checked:

  • Current-main lifecycle gap: Current main’s CLI finalizer exits early unless hasMemoryRuntime() is true, while the standalone registry path creates a memory-runtime owner outside the active plugin registry; a standalone manager can therefore remain outside the finalizer’s cleanup eligibility fact. (src/cli/run-main.ts:263, 607cf8fb6f2e)
  • Owner-boundary repair: The branch sets standalone-manager activity only after selecting a standalone runtime owner, clears it after successful all-manager cleanup, and leaves it true after a cleanup error so a later retry still runs. (src/plugins/memory-runtime.ts:124, 1970d4592de5)
  • Regression coverage: The branch adds coverage for cold config lookup, standalone acquisition, rearming after cleanup, workspace replacement, per-agent cleanup, failed acquisition, and failed cleanup retry. Current-main CLI coverage already verifies that a true runtime fact invokes shared cleanup. (src/plugins/memory-runtime.test.ts:96, 1970d4592de5)
  • Real packaged behavior proof: The updated PR body provides after-fix packaged CLI terminal output for successful, missing, and error wiki-get paths, each with natural termination; it also reports a real per-agent SQLite database and an enabled default filesystem watcher. (1970d4592de5)
  • Feature-history ownership: The locally available log attributes the current central memory-runtime module to Peter Steinberger’s recent refactor, making that path the strongest available ownership signal for routing this review. (src/plugins/memory-runtime.ts:1, 238bec2da353)

Likely related people:

  • steipete: Available history for the central memory-runtime module attributes its present form to Peter Steinberger, and this branch changes the same owner boundary. (role: recent area contributor; confidence: medium; commits: 238bec2da353, 1970d4592de5; files: src/plugins/memory-runtime.ts, src/plugins/memory-state.ts, src/cli/run-main.ts)

Rank-up moves

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

  • Let the required exact-head checks finish and refresh the merge result against current main.

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-03T05:22:13.365Z sha 1970d45 :: needs real behavior proof before merge. :: none

@steipete
steipete marked this pull request as ready for review August 3, 2026 05:32
@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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 3, 2026
@steipete
steipete merged commit 1333238 into main Aug 3, 2026
266 of 283 checks passed
@steipete
steipete deleted the codex/qa0803-memory-cli-teardown branch August 3, 2026 05:58
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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.

1 participant