Skip to content

fix(cli): avoid initializing provider runtime during cleanup - #200139

Merged
vincentkoc merged 1 commit into
mainfrom
fix/cli-cleanup-session-resources-20261116
Nov 16, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/cli-cleanup-session-resources-20261116

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

One-shot CLI commands can initialize an unused provider runtime while shutting down.

User Impact

Command output and configuration are unchanged. Session cleanup still runs, without initializing an unrelated provider runtime solely to reach its cleanup function.

Why This Change Was Made

Expose the existing session-resource registry through an internal package entry and import it directly from CLI cleanup. The broader runtime entry continues to share the same registry. No new registry, cache, or conditional cleanup path is added.

Evidence

  • Baseline 5ed49aa7c35024563fa4cb26ade3efd0b0fa4e15: a fresh child called the real closeCliResources; absent default-runtime state became initialized, the registered callback ran once, and both entries shared the registry. Native diagnostic completed successfully; the Actions cancellation reflects native lease teardown.
  • Candidate 9674081c7e37a2ffda41080de8ee6a3e43e08d6f: native validation passed all 28 focused cases, four type graphs, targeted formatting/lint, and the full build with declarations on Node 24.22.1. Tests cover cold compiled cleanup, resource retirement and one-shot exits, plus external packed-package registry identity and callbacks in both directions. Source and dependency inputs remained unchanged; native teardown completed successfully.
  • Independent source review and the completed exact-head autoreview found no actionable issues. The autoreview covered all changed owners and their cleanup, build, resolver, and packed-package contracts.

The change adds seven shipping/configuration lines for the internal package boundary and 66 test/support lines. No quantified RSS or latency improvement is claimed.

@vincentkoc vincentkoc self-assigned this Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 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.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S labels Nov 16, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 16, 2026 14:43
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR gives CLI cleanup a direct internal entry to the existing session-resource registry, avoiding default provider-runtime initialization.

Example: A one-shot CLI command finishes without using an AI provider.

  • Before: Cleanup imports the broader AI runtime and initializes an otherwise unused default runtime.
  • After: Cleanup runs the registered callbacks without initializing that runtime.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported change with useful boundary tests; the supplied execution evidence is harness-based rather than shipped-entry-point proof.
Proof confidence 🦐 gold shrimp (3/6) This internal import-graph change preserves user-visible behavior and requires no shipped-entry-point demonstration; supplied regression coverage exercises cold compiled cleanup and external package registry identity.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: CLI shutdown performs unnecessary provider-runtime initialization after commands that never used a provider.
Reason: The maintainer-authored direction removes avoidable initialization with a small package-boundary change and preserves the existing cleanup behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it makes a focused cleanup improvement while preserving the existing resource owner and teardown order; no actionable defect was found.

Priority: P3
Reviewed head: 9674081c7e37a2ffda41080de8ee6a3e43e08d6f

Before merge

None.

Findings

None.

Agent review details

How this fits together

One-shot CLI teardown drains provider resource callbacks held by the AI package; provider transports and the compatibility runtime continue using the same registry.

flowchart LR
  A[One-shot CLI command] --> B[CLI resource cleanup]
  B --> C[Internal session resources entry]
  D[Provider transports] --> E[Shared cleanup registry]
  F[AI runtime compatibility entry] --> E
  C --> E
  E --> G[Resource cleanup callbacks]
Loading

Technical review

Best possible solution:

Use the existing registry through the narrow internal package entry while preserving provider cleanup and shared module identity.

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

Current main's cleanup imports internal/runtime, which reexports default-runtime and initializes it at module evaluation; no target code was executed during this review.

Is this the best way to solve the issue?

The change is the smallest complete fix using the existing owner: expose its module directly, switch the cleanup import, and verify compiled and packed-package boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a139d420834e.

Provenance checked

  • CLI provider session-resource cleanup keeps the original intent (f4d984d: Release cached provider WebSockets after completed local agent commands so the process exits naturally.)
  • AI package internal entry points keeps the original intent (b4e27f8: Keep provider transport implementation inside the reusable AI package behind explicit internal entries and typed host boundaries.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit f4d984d adds src/cli/runtime-cleanup.ts:123 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f4d984df3222; files: src/cli/runtime-cleanup.ts)
  • Peter Steinberger: Raw commit 518fe6a adds src/cli/runtime-cleanup.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 518fe6a25536; files: src/cli/runtime-cleanup.ts)

PR surface

Source 0, Tests +66, Config +6, Other +1. Total +73 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 3 66 0 +66
Docs 0 0 0 0
Config 2 6 0 +6
Generated 0 0 0 0
Other 1 1 0 +1
Total 7 75 2 +73

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P3: This removes unnecessary runtime initialization during teardown without changing command output, configuration, or resource cleanup semantics.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This removes unnecessary runtime initialization during teardown without changing command output, configuration, or resource cleanup semantics.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 16, 2026, 10:00 AM ET / 15:00 UTC.

@vincentkoc
vincentkoc merged commit 0578291 into main Nov 16, 2026
261 checks passed
@vincentkoc
vincentkoc deleted the fix/cli-cleanup-session-resources-20261116 branch November 16, 2026 15:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Nov 16, 2026
…tgres-compaction-watched-prompt-20261116

* commit '9e810f7101557b006d5ff223d955f14dc43329f0': (23 commits)
  chore(ui): refresh control ui locales (#200164)
  fix(update): stop reporting unset git config keys as failing checks (#200153)
  test: consolidate redundant coverage (198793, part 2) (#198936)
  revert: skills-used full-transcript scan on every chat history page (#200159)
  refactor(sessions): follow the chat by key for stored delivery references (#200099)
  fix(update): bridge 2026.11.5-beta.4 updaters (#200152)
  fix(gateway): avoid filesystem stalls during catalog refresh (#200136)
  fix(ci): match update refusal probe to selected candidate (#200043)
  fix(agents): keep read-only steering carriers when publishing suppressed user envelopes (#200156)
  test: consolidate suites while retaining recovery owners (#198933)
  test: consolidate redundant coverage (198789, part 2) (#198932)
  refactor(cli): consolidate camera command tests (#200144)
  fix(cli): avoid initializing provider runtime during cleanup (#200139)
  fix(ui): show mobile destinations without the drawer exit delay (#198879)
  chore(ui): refresh control ui locales (#200146)
  fix(knowledge): keep historical claims distinct and reject changed retries (#200140)
  fix(ui): align dropdown arrows on mobile New Session
  improve(sessions): archive inactive transcripts by default (#199899)
  refactor(agents): own background commands and yield waits by the chat (#200097)
  fix(models): guessed non-chat models leave the default picker instead of being refused (#200102)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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