Skip to content

fix(acp-core): never return undefined from stringifyNonErrorCause - #96270

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
ly-wang19:fix/acp-core-stringify-nonerror-cause
Jun 24, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
ly-wang19:fix/acp-core-stringify-nonerror-cause

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

Summary

stringifyNonErrorCause (packages/acp-core/src/error-format.ts) is declared to return string, but its try body returned JSON.stringify(value) directly. JSON.stringify returns undefined (not a string) for functions, symbols, and undefined, so the helper leaked undefined to callers that format nested ACP runtime failure causes and rely on a string (concatenation, .length, etc.).

The sibling helper at src/infra/errors.ts already guards this exact case with ?? Object.prototype.toString.call(value); this aligns acp-core with it.

Changes

  • error-format.ts — return JSON.stringify(value) ?? Object.prototype.toString.call(value);.
  • error-format.test.ts — new colocated test that a function/symbol/undefined cause yields a string, and ordinary causes are unchanged.

Real behavior proof

Behavior addressed: a non-Error cause that JSON.stringify cannot serialize (function/symbol/undefined) made stringifyNonErrorCause return undefined despite its string type. After the fix it returns a tag string; ordinary causes are unchanged.

Real environment tested: Node 22.22.1, macOS, no network/model. Vitest exercises the real exported stringifyNonErrorCause with constructed inputs. BEFORE is origin/main's error-format.ts (swapped in via git show).

Exact steps or command run after this patch:

node scripts/run-vitest.mjs packages/acp-core/src/error-format.test.ts

Evidence after fix:

stringifyNonErrorCause(() => {})      BEFORE: undefined   AFTER: "[object Function]"
stringifyNonErrorCause(Symbol("x"))   BEFORE: undefined   AFTER: "[object Symbol]"
stringifyNonErrorCause(undefined)     BEFORE: undefined   AFTER: "[object Undefined]"
stringifyNonErrorCause({ a: 1 })      BOTH: '{"a":1}'     (unchanged)

Observed result after fix: the three unserializable causes now return a string instead of undefined; object/string/number/null causes are byte-identical. The new test fails on origin/main and passes after.

What was not tested: end-to-end ACP runtime failure formatting (the test drives the real exported helper that those paths call). No other behavior is touched.

Additional checks

  • node scripts/run-vitest.mjs packages/acp-core/src/error-format.test.ts passes; fail-before verified by swapping in origin/main's file. oxlint --tsconfig clean.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 2:21 AM ET / 06:21 UTC.

Summary
The PR updates ACP-core non-Error cause stringification to fall back to an object tag when JSON.stringify returns undefined, and adds a colocated Vitest regression test.

PR surface: Source +2, Tests +19. Total +21 across 2 files.

Reproducibility: yes. for the helper-level bug: current main returns JSON.stringify(value) directly, and a Node contract check shows that functions, symbols, and undefined serialize to undefined. I did not rerun an end-to-end ACP runtime flow in this read-only review.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: packages/acp-core/src/error-format.test.ts, serialized state: packages/acp-core/src/error-format.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
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.

Rank-up moves:

  • none.

Next step before merge

  • [P2] No repair lane is needed; this PR already contains the concrete code and test change and now needs ordinary maintainer review.

Security
Cleared: The diff only changes a pure TypeScript error-format helper and a colocated test; no dependency, workflow, credential, permission, install, or supply-chain surface changed.

Review details

Best possible solution:

Land the narrow helper fallback with the colocated regression test after ordinary maintainer and CI gates.

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

Yes for the helper-level bug: current main returns JSON.stringify(value) directly, and a Node contract check shows that functions, symbols, and undefined serialize to undefined. I did not rerun an end-to-end ACP runtime flow in this read-only review.

Is this the best way to solve the issue?

Yes. The helper owns the string return contract, and using the same nullish fallback as the sibling infra helper is narrower than adding defensive handling at each caller.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This fixes a real ACP error-formatting bug with limited blast radius and no data-loss, security, crash-loop, or urgent channel-delivery signal.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes a concrete Node environment, exact command, and copied before/after live output from the real exported helper showing the fixed return values.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a concrete Node environment, exact command, and copied before/after live output from the real exported helper showing the fixed return values.
Evidence reviewed

PR surface:

Source +2, Tests +19. Total +21 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 22 1 +21

What I checked:

  • Repository policy read: Root AGENTS.md was read fully and applied; no scoped packages/AGENTS.md exists for the touched paths. (AGENTS.md:1, a96418c65f8f)
  • Current main still has the bug: stringifyNonErrorCause is typed as returning string, but current main returns JSON.stringify(value) directly for non-scalar non-null values. (packages/acp-core/src/error-format.ts:67, a96418c65f8f)
  • Runtime callers use the helper for user-visible ACP error formatting: ACP request details and cause-chain rendering pass non-Error values through stringifyNonErrorCause before trimming, joining, redaction, and stored/user-visible error text. (packages/acp-core/src/runtime/errors.ts:71, a96418c65f8f)
  • Sibling helper proves the intended fallback shape: The sibling infra helper already uses JSON.stringify(value) ?? Object.prototype.toString.call(value), matching the PR's approach. (src/infra/errors.ts:120, a96418c65f8f)
  • JavaScript runtime contract checked: Node reported JSON.stringify(undefined), JSON.stringify(function), and JSON.stringify(Symbol(...)) as undefined, while ordinary objects/scalars produce strings.
  • PR patch is narrow: The diff changes only the ACP-core helper return expression and adds assertions for function, symbol, undefined, and ordinary values. (packages/acp-core/src/error-format.ts:78, cc18f71cdc2f)

Likely related people:

  • steipete: Authored and merged the ACP-core package expansion that added packages/acp-core/src/error-format.ts with the direct JSON.stringify(value) return. (role: introduced package helper; confidence: high; commits: 3669e26eabd3, 7ade6fd718e8; files: packages/acp-core/src/error-format.ts, packages/acp-core/src/runtime/errors.ts)
  • jalehman: Recent ACP-core refactor history and blame on the current helper/caller files point to work that carried the current implementation forward. (role: recent area contributor; confidence: high; commits: 96cee6cb6442; files: packages/acp-core/src/error-format.ts, packages/acp-core/src/runtime/errors.ts, src/infra/errors.ts)
  • hexsprite: Authored the earlier ACP runtime error-detail propagation work that used the safer infra stringifyNonErrorCause helper for non-Error causes. (role: adjacent error-behavior contributor; confidence: medium; commits: dbafc4f7a0c6; files: src/acp/runtime/errors.ts, src/infra/errors.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.

@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. P2 Normal backlog priority with limited blast radius. labels Jun 24, 2026
@vincentkoc
vincentkoc force-pushed the fix/acp-core-stringify-nonerror-cause branch from 5d4a108 to cc18f71 Compare June 24, 2026 05:51
`stringifyNonErrorCause` is typed `string`, but its `try` returned
`JSON.stringify(value)`, which is `undefined` for functions, symbols, and
undefined causes — leaking undefined to callers that format nested ACP runtime
failures and expect a string. Fall back to a tag string when stringify yields
undefined, matching the already-correct sibling at `src/infra/errors.ts`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vincentkoc
vincentkoc force-pushed the fix/acp-core-stringify-nonerror-cause branch from cc18f71 to 4f20386 Compare June 24, 2026 07:52
@vincentkoc
vincentkoc merged commit 599294b into openclaw:main Jun 24, 2026
76 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 25, 2026
…enclaw#96270)

`stringifyNonErrorCause` is typed `string`, but its `try` returned
`JSON.stringify(value)`, which is `undefined` for functions, symbols, and
undefined causes — leaking undefined to callers that format nested ACP runtime
failures and expect a string. Fall back to a tag string when stringify yields
undefined, matching the already-correct sibling at `src/infra/errors.ts`.

Co-authored-by: ly-wang19 <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants