Skip to content

fix(plugins): wrap self-hosted discovery JSON parse in try/catch#99892

Closed
cxbAsDev wants to merge 4 commits into
openclaw:mainfrom
cxbAsDev:fix/provider-self-hosted-setup-json-parse
Closed

fix(plugins): wrap self-hosted discovery JSON parse in try/catch#99892
cxbAsDev wants to merge 4 commits into
openclaw:mainfrom
cxbAsDev:fix/provider-self-hosted-setup-json-parse

Conversation

@cxbAsDev

@cxbAsDev cxbAsDev commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a self-hosted provider discovery endpoint returning malformed JSON would produce a raw SyntaxError without identifying which endpoint failed. This made it hard for operators and developers to diagnose which local or self-hosted provider returned bad data during setup or model discovery.

Why This Change Was Made

Wrapped JSON.parse inside readSelfHostedDiscoveryJson with a try/catch that rethrows an Error carrying the endpoint label (e.g. ollama discovery response is not valid JSON) and the original parse failure as cause. The change is scoped to the shared discovery helper so both /models and llama.cpp /props discovery benefit from the same diagnostic.

User Impact

When a self-hosted provider returns non-JSON or malformed JSON during discovery, the resulting warning/error now names the provider endpoint instead of surfacing only a bare SyntaxError, speeding up diagnosis.

Evidence

Real environment tested: Linux, Node 22, branch fix/provider-self-hosted-setup-json-parse

Proof command:

node_modules/.bin/tsx scripts/proof/provider-self-hosted-json-parse.mts

Proof output:

=== Proof: self-hosted provider malformed discovery JSON ===

Endpoint: http://127.0.0.1:44995/v1/models
Response body: not valid json {

[plugins/self-hosted-provider-setup] Failed to discover malformed-test models: Error: malformed-test discovery response is not valid JSON
Discovered models: []

PASS: malformed discovery JSON is caught and discovery returns an empty list.

Regression test:

node scripts/run-vitest.mjs src/plugins/provider-self-hosted-setup.test.ts
 Test Files  1 passed (1)
      Tests  13 passed (13)

The regression test "wraps malformed discovery JSON with a descriptive error" asserts that the logged warning contains malformed-test discovery response is not valid JSON.

🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]

@clawsweeper

clawsweeper Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 5, 2026, 12:06 PM ET / 16:06 UTC.

Summary
The branch wraps JSON.parse in the self-hosted discovery helper with a provider-labeled error and adds a regression test plus a loopback proof script.

PR surface: Source +4, Tests +35, Other +43. Total +82 across 3 files.

Reproducibility: yes. from source: current main decodes the bounded discovery body and passes malformed bytes directly to JSON.parse before the outer warning. The PR body and exact-head proof check provide after-fix live-output evidence for the improved diagnostic.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: scripts/proof/provider-self-hosted-json-parse.mts, serialized state: src/plugins/provider-self-hosted-setup.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

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

Next step before merge

  • [P2] No repair lane is needed because there are no review findings and the remaining action is ordinary maintainer review.

Security
Cleared: No concrete security or supply-chain concern was found; the diff adds no dependency, workflow, permission, secret, package, or code-execution surface and improves diagnostics for untrusted JSON.

Review details

Best possible solution:

Land the narrow shared-helper diagnostic after normal maintainer review, preserving bounded reads and fail-soft discovery behavior.

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

Yes from source: current main decodes the bounded discovery body and passes malformed bytes directly to JSON.parse before the outer warning. The PR body and exact-head proof check provide after-fix live-output evidence for the improved diagnostic.

Is this the best way to solve the issue?

Yes. Wrapping JSON.parse inside readSelfHostedDiscoveryJson is the narrowest maintainable fix because it covers both /models and llama.cpp /props while preserving the existing bounded read and fail-soft callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 286d0b9fb340.

Label changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: The PR is a narrow self-hosted provider discovery diagnostic fix with limited blast radius and no config, API, dependency, or migration change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal live output from a loopback HTTP server returning malformed JSON, and the exact-head Real behavior proof check succeeded.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal live output from a loopback HTTP server returning malformed JSON, and the exact-head Real behavior proof check succeeded.
Evidence reviewed

PR surface:

Source +4, Tests +35, Other +43. Total +82 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 36 1 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 43 0 +43
Total 3 84 2 +82

What I checked:

Likely related people:

  • Alix-007: Live metadata for merged PR fix(providers): bound self-hosted provider discovery JSON reads #95244 shows Alix-007 authored the commit that introduced readSelfHostedDiscoveryJson and its raw parse line. (role: introduced helper behavior; confidence: high; commits: 374fa36d05f0, dad5ce64d4f1; files: src/plugins/provider-self-hosted-setup.ts, src/plugins/provider-self-hosted-setup.test.ts)
  • sallyom: The merged bounded-discovery PR history shows sallyom tuned the discovery cap and provided compatibility review context for the helper this PR changes. (role: reviewer and cap-tuning contributor; confidence: medium; commits: d84f514a1f17; files: src/plugins/provider-self-hosted-setup.ts, src/plugins/provider-self-hosted-setup.test.ts)
  • Vincent Koc: Local blame for the helper and raw JSON.parse line maps to Vincent Koc in the current checkout history, though the compacted commit subject is not specific to this feature. (role: current-main line owner in local blame; confidence: medium; commits: fd2e4da00651; files: src/plugins/provider-self-hosted-setup.ts)
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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-04T09:02:39.100Z sha e26bf41 :: needs real behavior proof before merge. :: [P3] Assert the wrapped malformed-JSON error
  • reviewed 2026-07-04T09:07:10.355Z sha e26bf41 :: needs real behavior proof before merge. :: [P3] Assert the wrapped malformed-JSON error
  • reviewed 2026-07-04T09:39:44.458Z sha 0439ce3 :: needs real behavior proof before merge. :: [P3] Assert the labeled malformed-JSON diagnostic
  • reviewed 2026-07-05T10:08:19.427Z sha d0a66e1 :: needs real behavior proof before merge. :: [P2] Return void from the listen Promise executor
  • reviewed 2026-07-05T10:38:03.940Z sha e31ab7f :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T10:43:32.556Z sha e31ab7f :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T13:01:09.200Z sha d57103c :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T13:56:41.786Z sha b6850ff :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 4, 2026
@cxbAsDev cxbAsDev closed this Jul 4, 2026
@cxbAsDev cxbAsDev reopened this Jul 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S and removed size: XS labels Jul 5, 2026
@cxbAsDev

cxbAsDev commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@cxbAsDev

cxbAsDev commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 5, 2026
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 5, 2026
@cxbAsDev
cxbAsDev force-pushed the fix/provider-self-hosted-setup-json-parse branch from e31ab7f to e5e4145 Compare July 5, 2026 12:22
@cxbAsDev

cxbAsDev commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@cxbAsDev
cxbAsDev force-pushed the fix/provider-self-hosted-setup-json-parse branch 3 times, most recently from c0542b6 to b6850ff Compare July 5, 2026 13:31
@clawsweeper clawsweeper Bot removed 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 Jul 5, 2026
@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. labels Jul 5, 2026
cxbAsDev and others added 4 commits July 5, 2026 22:13
Malformed JSON from a self-hosted provider discovery endpoint would
throw an uncaught SyntaxError, crashing the provider setup flow.
Wrap in try/catch and rethrow with a descriptive error message.

Co-Authored-By: Claude <[email protected]>
@cxbAsDev
cxbAsDev force-pushed the fix/provider-self-hosted-setup-json-parse branch from b6850ff to 425683e Compare July 5, 2026 14:13
@cxbAsDev

cxbAsDev commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 5, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 5, 2026
@steipete steipete self-assigned this Jul 5, 2026
steipete added a commit that referenced this pull request Jul 5, 2026
Source: #99892

Co-authored-by: 陈宪彪0668000387 <[email protected]>
steipete added a commit that referenced this pull request Jul 5, 2026
* fix(agents): harden LSP process failures

Source: #100450

Co-authored-by: morluto <[email protected]>

* fix(sandbox): report effective workspace layout

Sources: #100435, #100439

Co-authored-by: Aniruddha Adak <[email protected]>

Co-authored-by: ZengWen-DT <[email protected]>

* fix(security): fail install checks on stream errors

Source: #100413

Co-authored-by: 陈宪彪0668000387 <[email protected]>

* fix(android): normalize all-day calendar events

Source: #100032

Co-authored-by: NianJiuZst <[email protected]>

* fix(ios): serialize push-to-talk lifecycle

Source: #99942

Co-authored-by: NianJiuZst <[email protected]>

* fix(talk): reject inherited provider names

Source: #99849

Co-authored-by: zenglingbiao <[email protected]>

* fix(android): stop voice capture in background

Source: #99840

Co-authored-by: xialonglee <[email protected]>

* fix(cron): preserve fallback result classification

Source: #99913

Co-authored-by: jincheng-xydt <[email protected]>

* fix(google): bound Vertex response decompression

Source: #99812

Co-authored-by: 黄剑雄0668001315 <[email protected]>

* fix(plugins): report malformed discovery JSON

Source: #99892

Co-authored-by: 陈宪彪0668000387 <[email protected]>

* test(sandbox): configure non-default workspace fixture

* test: fix small-fix batch validation

---------

Co-authored-by: morluto <[email protected]>
Co-authored-by: ZengWen-DT <[email protected]>
Co-authored-by: 陈宪彪0668000387 <[email protected]>
Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: zenglingbiao <[email protected]>
Co-authored-by: xialonglee <[email protected]>
Co-authored-by: jincheng-xydt <[email protected]>
Co-authored-by: 黄剑雄0668001315 <[email protected]>
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Thanks @cxbAsDev — your malformed discovery-response fix was incorporated into #100483, landed as aaf5ab9. The landed version preserves both the self-hosted provider label and the original parse cause, with logger-level regression coverage. Contributor credit is preserved. Closing this superseded PR.

@steipete steipete closed this Jul 5, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
* fix(agents): harden LSP process failures

Source: openclaw#100450

Co-authored-by: morluto <[email protected]>

* fix(sandbox): report effective workspace layout

Sources: openclaw#100435, openclaw#100439

Co-authored-by: Aniruddha Adak <[email protected]>

Co-authored-by: ZengWen-DT <[email protected]>

* fix(security): fail install checks on stream errors

Source: openclaw#100413

Co-authored-by: 陈宪彪0668000387 <[email protected]>

* fix(android): normalize all-day calendar events

Source: openclaw#100032

Co-authored-by: NianJiuZst <[email protected]>

* fix(ios): serialize push-to-talk lifecycle

Source: openclaw#99942

Co-authored-by: NianJiuZst <[email protected]>

* fix(talk): reject inherited provider names

Source: openclaw#99849

Co-authored-by: zenglingbiao <[email protected]>

* fix(android): stop voice capture in background

Source: openclaw#99840

Co-authored-by: xialonglee <[email protected]>

* fix(cron): preserve fallback result classification

Source: openclaw#99913

Co-authored-by: jincheng-xydt <[email protected]>

* fix(google): bound Vertex response decompression

Source: openclaw#99812

Co-authored-by: 黄剑雄0668001315 <[email protected]>

* fix(plugins): report malformed discovery JSON

Source: openclaw#99892

Co-authored-by: 陈宪彪0668000387 <[email protected]>

* test(sandbox): configure non-default workspace fixture

* test: fix small-fix batch validation

---------

Co-authored-by: morluto <[email protected]>
Co-authored-by: ZengWen-DT <[email protected]>
Co-authored-by: 陈宪彪0668000387 <[email protected]>
Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: zenglingbiao <[email protected]>
Co-authored-by: xialonglee <[email protected]>
Co-authored-by: jincheng-xydt <[email protected]>
Co-authored-by: 黄剑雄0668001315 <[email protected]>
@cxbAsDev
cxbAsDev deleted the fix/provider-self-hosted-setup-json-parse branch July 15, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts 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