Fix smart-quoted tool call argument repair#86611
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 28, 2026, 1:22 PM ET / 17:22 UTC. Summary PR surface: Source +406, Tests +190. Total +596 across 2 files. Reproducibility: yes. at source level. Node rejects structural smart-quote JSON and current main's wrapper only has JSON.parse plus ASCII balanced-prefix parsing; I did not run a live cron or Telegram scenario. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the local wrapper fallback after current-head checks are green and maintainers accept the bounded malformed-output heuristic, keeping valid JSON and existing balanced-prefix recovery ahead of smart-quote repair. Do we have a high-confidence way to reproduce the issue? Yes, at source level. Node rejects structural smart-quote JSON and current main's wrapper only has JSON.parse plus ASCII balanced-prefix parsing; I did not run a live cron or Telegram scenario. Is this the best way to solve the issue? Yes, the proposed direction is the narrow repair path. Keeping it local to the embedded-runner malformed argument wrapper is preferable to changing cron status accounting, provided checks pass and maintainers accept the bounded heuristic. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against b2fc8af1b109. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +406, Tests +190. Total +596 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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 PR egg: 🔥 warming; proof passed, review follow-up or readiness checks remain. Hatch with Rules and detailsHatchability:
About:
|
46fb2ee to
20091cd
Compare
1bd79e6 to
0d9d4ee
Compare
0d9d4ee to
cde46bd
Compare
5fc074a to
d7882f5
Compare
d7882f5 to
e417ec8
Compare
62557fc to
4301233
Compare
4301233 to
19d855b
Compare
Summary
src/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.ts; no shared JSON helper, cron status, delivery, or dependency changes.src/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.test.ts.AI assistance disclosure
This PR was implemented with Codex assistance. I reviewed the change and understand the affected embedded-runner tool-call argument repair path.
Real behavior proof
Behavior addressed: malformed smart-quoted edit/write/exec tool-call arguments are repaired before the embedded runner observes empty
{}arguments.Real environment tested: local Node.js v22.22.0 loading the TypeScript source with
tsx, exercising the actualwrapStreamFnRepairMalformedToolCallArgumentsstream wrapper with synthetic streamed tool calls. No live credentials or delivery channels were used.Exact steps or command run after this patch:
node --import tsx --input-type=modulescript importingsrc/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.ts, streaming.functions.<tool>:0plus smart-quoted JSON-like args, draining the wrapped stream, and printing repaired tool-call args. Local proof log:.artifacts/67488-smart-quote-repair-proof.log.Evidence after fix:
Observed result after fix: Node still rejects structural smart quotes directly, but the existing repair wrapper recovers the streamed malformed tool arguments and writes identical repaired args into the partial, streamed, end-message, and final tool-call surfaces. Smart-quoted string values now decode JSON escapes for newline, quote, backslash, and Unicode sequences while preserving invalid prose-style escapes such as
\d.What was not tested: live cron scheduling, live Telegram delivery, and real provider credentials. The proof targets the smallest representative runtime boundary for the reported failure: the embedded-runner malformed tool-call argument repair wrapper.
Root Cause
The current repair path first tries
JSON.parse(raw)and then usesextractBalancedJsonPrefix(raw)plusJSON.parse(extracted.json). Both are ASCII-quote JSON paths. Provider output that uses Unicode smart quotes as structural string delimiters is visually JSON-like but invalid JSON, so the wrapper could fail to recover edit/write args and downstream status reporting could preserve the parse error even after delivery.Dependency contract
Node/ECMAScript
JSON.parserequires JSON object keys and string values to use ASCII double quotes. The proof shows Node v22.22.0 rejecting{“path”:“notes/报告.md”}withSyntaxError.The internal repair contract remains: valid JSON is preserved first, existing balanced-prefix/trailing-junk recovery is preserved next, and this patch only adds a local smart-quote fallback for the existing malformed tool-call repair gate.
Regression Test Plan
src/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.test.tscovers smart-quoted edit args with CJK/Markdown/inner smart quotes, ASCII-delimited content with smart quotes, same-direction smart quote delimiters, command/workdir args, and member-looking prose that must not synthesize extra args.src/agents/embedded-agent-runner/run/attempt.test.tskeeps the broader embedded-runner coverage green.Security Impact
No credential, auth, sandbox, workflow, dependency, lockfile, or network behavior changes. The parser is bounded to the existing malformed tool-call argument repair gate and synthetic recovery of streamed arguments.
Human Verification
I reviewed the narrowed diff after removing the shared-helper change. The local mini-guide for the affected architecture and proof is
.artifacts/issue-67488-smart-quote-repair-guide.html.CODEOWNERS / owner review
Checked
.github/CODEOWNERS; the touched files do not match a special owner-restricted pattern. Expect normal maintainer review forsrc/agents/embedded-agent-runner/run/*.Changelog
No contributor
CHANGELOG.mdedit. Maintainers can add a release note during landing if needed.Review conversations
Existing ClawSweeper review on the first draft called out shared-helper exposure through
src/shared/balanced-json.ts. This revision removes that shared-helper change and keeps the repair local to the embedded-runner wrapper. A later ClawSweeper review found that exact smart-quoted argument objects without preamble or trailing junk were still rejected; this revision now repairs that case and adds a focused regression. A May 28 ClawSweeper review then found that accepted smart-quoted values preserved JSON escapes literally; this revision decodes JSON string escapes and adds a regression for newline, quote, backslash, Unicode, and invalid-escape preservation. A later May 28 ClawSweeper review found the current nested edit-array schema was not repaired; this revision now repairs smart-quotededits: [{ oldText, newText }]arrays and adds a focused regression.Local
codex review --base origin/maincould not complete after the revision because the account hit the usage limit:Risks
Behavior tradeoffs
content,text,message,oldText, andnewTextkeep JSON-looking prose inside the string instead of synthesizing extra top-level args.oldTextmay close before its expectednewTextsuccessor.Scope boundaries
src/shared/balanced-json.tsor CLI-output JSON extraction.openai-responsestransports.Validation
pnpm check:changedwas not rerun after the last narrow parser follow-up; the branch was rebased onto upstream mainc2c29588f4to avoid the unrelated stale-basecheck-prod-typesfailure insrc/secrets/path-utils.ts.