Skip to content

fix(diffs): stop lightweight CLI registration from crashing when runtime.state is unavailable - #128360

Merged
steipete merged 2 commits into
openclaw:mainfrom
chelsealong:fix/diffs-cli-metadata-lightweight-crash-128330
Aug 24, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
chelsealong:fix/diffs-cli-metadata-lightweight-crash-128330

Conversation

@chelsealong

@chelsealong chelsealong commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #128330

AI-assisted PR: this change was written and validated by an autonomous coding agent (Claude).

What Problem This Solves

@openclaw/diffs throws during registration in a lightweight CLI runtime because extensions/diffs/src/plugin.ts unconditionally calls api.runtime.state.openBlobStore(...). When the plugin is discovered as a non-bundled (e.g. npm-installed) plugin with no dedicated cli-metadata.ts entry, the lightweight CLI metadata loader (src/plugins/loader-cli-registry.ts) falls back to loading the full plugin.ts/index.ts entry and calls register(api) with an empty runtime: {}, since CLI metadata capture never needs a live gateway runtime. plugin.ts dereferences api.runtime.state.openBlobStore immediately, before registering anything else, so the plugin fails to register and logs a confusing error even though the command itself still completes:

[plugins] diffs failed during register from .../node_modules/@openclaw/diffs/dist/index.js: TypeError: Cannot read properties of undefined (reading 'openBlobStore')

Why This Change Was Made

The public Plugin SDK already identifies lightweight command discovery with api.registrationMode === "cli-metadata". The diffs plugin exposes no CLI commands, so its existing registration owner should return immediately for that exact mode, before reading api.runtime.state.openBlobStore.

The corrected head implements that guard directly in extensions/diffs/src/plugin.ts and adds its regression to the existing extensions/diffs/src/plugin.test.ts owner suite. Full, discovery, and tool-discovery registration still follow their existing paths.

An earlier version introduced a no-op top-level metadata entry and a test that imported core loader internals from a plugin. Both have been removed: the owner-local guard needs no extra module, manifest entry, loader change, Plugin SDK change, or cross-boundary test.

User Impact

Users who install @openclaw/diffs as a standalone npm plugin (its documented default install mode: openclaw.install.defaultChoice: "npm") no longer see a spurious [plugins] diffs failed during register ... error on ordinary lightweight CLI commands like openclaw nodes --help. No behavior changes for diffs running under the full Gateway runtime.

Evidence

  • Exact reviewed head: a5645b47281b235919b948a370f235c652b769da.
  • Existing contributor proof reproduced the reported failure through a real built CLI before this owner-local rewrite. That run used the earlier superseded metadata-entry implementation; it establishes the original symptom but is not proof of the rewritten head.
  • The rewritten owner regression constructs the public createTestPluginApi with registrationMode: "cli-metadata" and its default empty runtime, then asserts registration does not throw and registers no tool, HTTP route, or hook.
  • Existing full-mode plugin tests continue to cover blob-store initialization and normal tool registration.
  • Three plugin/SDK owner sources independently establish the shipped registration-mode contract; the production change is limited to the diffs plugin registration owner.
  • Fresh isolated source-bundle maintainer review completed without actionable findings. Exact-head secretless hosted CI/build must pass before landing.

Exact-head built CLI proof gap: the contributor fork is untrusted and cannot be executed on a credential-hydrated maintainer host; no already-provisioned, approved free isolated runner is available for this task. The earlier built CLI transcript predates the rewrite and must not be treated as exact-head proof. Exact-head verification therefore relies on the owner-boundary regression, existing full-mode coverage, independent source review, and required hosted CI/build unless an exact-head hosted CLI artifact becomes available.

The diffs plugin has no cli-metadata.ts, so the lightweight CLI
metadata loader fell back to plugin.ts and called register() with an
empty runtime, crashing on api.runtime.state.openBlobStore for any
non-bundled install (e.g. the published @openclaw/diffs npm package).
Add a no-op cli-metadata.ts, matching every other bundled plugin's
convention, so CLI metadata capture stops there instead of loading the
full runtime.

Fixes openclaw#128330
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 5:33 PM ET / 21:33 UTC.

ClawSweeper review

What this changes

Adds a lightweight diffs plugin metadata entry and a regression test so CLI metadata discovery does not initialize the runtime-dependent diffs plugin.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this is a focused, correct repair for the linked CLI-registration bug, and current main still lacks it.

Priority: P2
Reviewed head: 1eff5cd4e826e287aa139615afa8ff1d6062bbba

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with credible command-level evidence and a useful boundary regression test.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body supplies before/after terminal output from the built CLI path showing the registration error disappears without exposing sensitive data.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies before/after terminal output from the built CLI path showing the registration error disappears without exposing sensitive data.
Evidence reviewed 6 items Empty runtime in CLI discovery: The CLI registry builds its plugin API with an empty runtime and explicitly prefers a root cli-metadata entry over the normal plugin entry.
Actual failure boundary: Normal diffs registration immediately dereferences api.runtime.state.openBlobStore before registering the plugin’s tool and HTTP route.
Packaging contract: Publishable plugin builds collect non-test top-level public files, so cli-metadata.ts is compiled alongside index.ts and included under dist/.
Findings None None.
Security None None.

Live Verification

Command: pnpm build && OPENCLAW_STATE_DIR=/tmp/openclaw-diffs-proof OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 node dist/index.js nodes --help

Result: FAIL (partial) — step 2 expect_output Usage: openclaw nodes: expected terminal output was not visible within 30 seconds: "Usage: openclaw nodes"

pnpm build && OPENCLAW_STATE_DIR=/tmp/openclaw-diffs-proof OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 node dist/index.js nodes --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128360-Qxitsh/target$ pnpm build && OPENCLAW_STATE_DIR=/tmp/openclaw-diffs-proof OPENCLAW_DISABLE_BUNDLED_PLUGI
NS=1 node dist/index.js nodes --help
$ node --import tsx scripts/build-all.mts
[build-all] plugins:assets:build
pnpm build && OPENCLAW_STATE_DIR=/tmp/openclaw-diffs-proof OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 node dist/index.js nodes --help
$ node --import tsx scripts/bundled-plugin-assets.mts --phase build
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 109.97 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[build-all] plugins:assets:build done in 1.85s
[build-all] tsdown-ai
[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
  - tsdown:deps (46%)
  - rolldown-plugin-dts:fake-js (22%)
  - rolldown-plugin-dts:generate (21%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/1 finished in 4.8s
[build-all] tsdown-ai done in 5.41s
[build-all] tsdown-packages
[tsdown-build] invocation 1/1 finished in 20.8s
[build-all] tsdown-packages done in 21.3s
[build-all] tsdown-unified






















Assertions:

  • FAIL expect_output: Usage: openclaw nodes

How this fits together

CLI metadata discovery loads installed plugin metadata before a Gateway runtime exists. The normal diffs plugin entry later registers blob-backed tools and viewer routes when that runtime is available.

flowchart LR
  A[CLI help command] --> B[Plugin discovery]
  B --> C[CLI metadata entry]
  C --> D[Command registry]
  B --> E[Full diffs entry]
  E --> F[Gateway runtime]
  F --> G[Diff tools and viewer]
Loading

Before merge

  • Resolve merge risk (P1) - Production +13 is necessary for a distinct metadata entry; packaging must continue compiling that top-level entry into the published plugin artifact.
  • Complete next step (P2) - The existing PR is already the focused repair; it needs normal exact-head validation rather than an automated replacement.
Agent review details

Security

None.

PR surface

Source +13, Tests +33. Total +46 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 0 +13
Tests 1 33 0 +33
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 46 0 +46

Review metrics

Metric Value Why it matters
Production vs test LOC production +13, tests +33 The production entry establishes the required metadata/runtime separation; the test verifies installed-plugin discovery at that boundary.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/diffs/cli-metadata.test.ts, vector/embedding metadata: extensions/diffs/cli-metadata.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128330
Summary: This PR is the candidate repair for the reported lightweight diffs CLI registration failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the dedicated metadata entry and boundary-level regression test; there is no net-neutral alternative that prevents discovery from importing the runtime entry.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the dedicated metadata entry and boundary-level regression test; there is no net-neutral alternative that prevents discovery from importing the runtime entry.

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

Yes—current source shows CLI metadata loading supplies an empty runtime while the full diffs entry immediately uses runtime.state; the PR body also provides before/after command output.

Is this the best way to solve the issue?

Yes—the dedicated metadata entry is the established loader boundary and avoids importing or conditionally weakening the full runtime registration path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The patch removes a reproducible lightweight-CLI registration error without changing the full diffs runtime.
  • 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 before/after terminal output from the built CLI path showing the registration error disappears without exposing sensitive data.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies before/after terminal output from the built CLI path showing the registration error disappears without exposing sensitive data.

Evidence

What I checked:

Likely related people:

  • Unknown: The available checkout cannot access pre-PR diffs/plugin-loader history, and CODEOWNERS has no matching path owner. (role: area owner unresolved from available history; confidence: low; commits: 1eff5cd4e826; files: extensions/diffs/src/plugin.ts, src/plugins/loader-cli-registry.ts)

Rank-up moves

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

  • Refresh the branch only as required for exact-head CI and mergeability.

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-23T20:50:47.988Z sha 1eff5cd :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review — the contributor patch now fixes the plugin registration owner directly, removes the unused metadata shim and invalid cross-boundary test, and includes an exact-head owner regression with the built-CLI proof gap documented.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit d2e62c6 into openclaw:main Aug 24, 2026
104 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 Aug 25, 2026
…ime.state is unavailable (openclaw#128360)

* fix(diffs): stop lightweight CLI registration from crashing

The diffs plugin has no cli-metadata.ts, so the lightweight CLI
metadata loader fell back to plugin.ts and called register() with an
empty runtime, crashing on api.runtime.state.openBlobStore for any
non-bundled install (e.g. the published @openclaw/diffs npm package).
Add a no-op cli-metadata.ts, matching every other bundled plugin's
convention, so CLI metadata capture stops there instead of loading the
full runtime.

Fixes openclaw#128330

* fix(diffs): skip runtime setup while collecting CLI metadata

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: diffs 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: XS 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.

diffs: lightweight CLI registration crashes when runtime.state is unavailable

2 participants