Skip to content

refactor: consolidate safe JSON parsing - #99688

Merged
RomneyDa merged 1 commit into
mainfrom
refactor/safe-json-consolidation
Jul 4, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
refactor/safe-json-consolidation

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

Closes #99665

What Problem This Solves

Pure tolerant JSON parsing was reimplemented in several core callers, mixing parsing mechanics with each caller's record coercion and fallback policy.

Why This Change Was Made

Adds a dependency-free safeParseJson(value: string): unknown helper to the existing private @openclaw/normalization-core root export and migrates four record-only internal callers. The helper returns undefined only for syntax failures; callers still own record coercion, trimming, and defaults.

The earlier package-subpath approach was intentionally removed. This version adds no package export, resolver, tsconfig, Vitest, build-entry, extension-boundary, or Control UI alias plumbing. Logging/redaction parsing and the public src/utils.ts null-contract helper remain unchanged because their contracts differ.

User Impact

No intended user-visible behavior change. The migrated caller slice now shares one parsing primitive while production code decreases.

Evidence

  • Focused tests: OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs packages/normalization-core/src/json-coercion.test.ts src/acp/runtime/session-meta.test.ts src/agents/embedded-agent-message-tool-source-reply.test.ts src/chat/canvas-render.test.ts src/agents/tools/message-tool.internal-source-reply.integration.test.ts — 37 tests passed across four Vitest shards.
  • Build: pnpm build — passed, including normalization-core declarations/runtime output, plugin SDK export checks, and Control UI production build.
  • Build artifact proof: packages/normalization-core/dist/index.mjs and index.d.mts export safeParseJson through the existing root entry.
  • Autoreview: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --prompt-file /tmp/pr99688-autoreview.md --stream-engine-output — clean, no accepted/actionable findings; correctness confidence 0.98.
  • Testbox-through-Crabbox was attempted twice (tbx_01kwqakqby8pg3gwnt3tf476gz, tbx_01kwqb2f7dn16tztfg12m8efzf) but Blacksmith timed out while reading lease status before either command executed; both leases were stopped. AWS fallback was unavailable because broker auth is not configured in this environment.
  • Search proof: the four migrated callers contain no direct JSON.parse.
  • LOC: +34/-41 across 7 files, net -7 overall. Production LOC is +22/-41, net -19.

@RomneyDa

RomneyDa commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Land-ready proof for 5fae32520a6f5a8d2def5449be51165f8f0aea08:

Known proof gaps: none for this refactor scope. GitHub PR CI is still pending.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui scripts Repository scripts agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 4:09 PM ET / 20:09 UTC.

Summary
Adds a dependency-free safeParseJson helper to the private normalization-core root barrel and migrates four internal record-only tolerant JSON parsing wrappers to use it.

PR surface: Source -19, Tests +12. Total -7 across 7 files.

Reproducibility: not applicable. this is a refactor PR rather than a bug report. Source inspection confirms current main lacks the helper and the branch consolidates duplicate tolerant parser wrappers.

Review metrics: 1 noteworthy metric.

  • Private root export: 1 added. The helper becomes reachable through the existing private normalization-core root barrel, so maintainers should confirm that root exposure is intentional before merge.

Stored data model
Persistent data-model change detected: serialized state: packages/normalization-core/src/json-coercion.ts, serialized state: src/acp/runtime/session-meta.ts, serialized state: src/agents/embedded-agent-message-tool-source-reply.ts, serialized state: src/agents/subagent-yield-output.ts, serialized state: src/chat/canvas-render.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99665
Summary: This PR is the candidate implementation for the linked maintainer issue requesting consolidation of pure tolerant JSON parsing.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Let the two in-progress exact-head CI jobs finish before merge.

Risk before merge

  • [P1] Exact-head GitHub CI still had two in-progress jobs during review, so landing should remain behind the normal required-check gates.

Maintainer options:

  1. Decide the mitigation before merge
    Land this narrowed refactor after required exact-head CI passes, keeping the helper limited to syntax-failure suppression and leaving different public, logging, filesystem, JSONL, and validation contracts local.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is needed; the remaining action is maintainer review plus normal exact-head CI gating for the open PR.

Security
Cleared: No concrete security or supply-chain regression was found; the diff adds no dependencies, lockfile changes, workflows, secret handling, downloaded code, or broader permissions.

Review details

Best possible solution:

Land this narrowed refactor after required exact-head CI passes, keeping the helper limited to syntax-failure suppression and leaving different public, logging, filesystem, JSONL, and validation contracts local.

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

Not applicable: this is a refactor PR rather than a bug report. Source inspection confirms current main lacks the helper and the branch consolidates duplicate tolerant parser wrappers.

Is this the best way to solve the issue?

Yes: normalization-core is the existing shared coercion owner, and the updated diff keeps parsing mechanics separate from caller-specific record coercion, defaults, logging, and compatibility contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7a0188cbd20d.

Label changes

Label justifications:

  • P3: This is low-risk internal maintainability cleanup with no intended user-visible behavior change.
  • 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. Not applicable: This is a member-authored internal refactor, so the external-contributor real behavior proof gate does not apply; the PR body reports focused tests, build, and autoreview proof.
Evidence reviewed

PR surface:

Source -19, Tests +12. Total -7 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 6 22 41 -19
Tests 1 12 0 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 34 41 -7

What I checked:

Likely related people:

  • RomneyDa: Opened the linked maintainer issue and recently authored adjacent record-guard consolidation work, so this person has strong context on the intended helper boundary beyond this PR branch. (role: adjacent normalization cleanup owner; confidence: medium; commits: de34dfdbe8c4; files: extensions/codex-supervisor/src/config.ts, extensions/telegram/src/bot/body-helpers.ts, extensions/qa-lab/src/jsonl-replay.ts)
  • Takhoffman: Merged PR 64104 introduced the canvas rendering path containing one of the migrated tolerant JSON parsers. (role: adjacent feature owner; confidence: high; commits: cc5c691f0069; files: src/chat/canvas-render.ts, src/gateway/canvas-documents.ts, ui/src/ui/canvas-url.ts)
  • quotentiroler: Authored the merged PR that added the existing public src/utils.ts safeParseJson helper with its different null-on-failure contract. (role: adjacent helper introducer; confidence: high; commits: f0924d3c4e92; files: src/utils.ts, src/plugin-sdk/index.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 (4 earlier review cycles)
  • reviewed 2026-07-04T05:00:35.325Z sha 117d0c2 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T18:18:41.843Z sha ce42b74 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T18:25:22.742Z sha ce42b74 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T20:04:09.707Z sha 1d81eaf :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 3, 2026
@RomneyDa RomneyDa closed this Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/safe-json-consolidation branch from 5fae325 to 5ea4b41 Compare July 4, 2026 02:46
@RomneyDa RomneyDa reopened this Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/safe-json-consolidation branch from b1e4507 to 9fa6a2c Compare July 4, 2026 03:40
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/safe-json-consolidation branch from 9fa6a2c to 117d0c2 Compare July 4, 2026 04:44
@RomneyDa RomneyDa self-assigned this Jul 4, 2026
@RomneyDa
RomneyDa force-pushed the refactor/safe-json-consolidation branch from 117d0c2 to ce42b74 Compare July 4, 2026 18:14
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 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.

@RomneyDa
RomneyDa force-pushed the refactor/safe-json-consolidation branch from ce42b74 to 1d81eaf Compare July 4, 2026 19:59
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed app: web-ui App: web-ui scripts Repository scripts size: M labels Jul 4, 2026
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Reduced the PR from +149/-69 across 22 files to +34/-41 across 7 files.

The updated implementation exports the helper only from the existing private normalization-core root and deletes all new subpath/resolver/build/UI plumbing. It also drops the logging migration and refactor-only caller tests where the contracts or proof value did not justify the added surface.

Proof on head 1d81eaf:

  • 37 focused tests passed across four Vitest shards.
  • pnpm build passed, including generated normalization-core runtime/types and Control UI build.
  • Fresh autoreview returned no findings with 0.98 correctness confidence.
  • Testbox-through-Crabbox was attempted twice, but Blacksmith timed out before command execution; both leases were stopped. Exact ids and the AWS-auth fallback gap are recorded in the PR body.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 4, 2026
@RomneyDa
RomneyDa merged commit cf14b27 into main Jul 4, 2026
115 of 123 checks passed
@RomneyDa
RomneyDa deleted the refactor/safe-json-consolidation branch July 4, 2026 23:33
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

Refactor: consolidate pure safe JSON parsing

1 participant