Skip to content

fix(client-runtime): preserve repeated JSON keys in displayed tool output - #46934

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-00638f9b8d
Dec 1, 2026
Merged

juliusmarminge merged 2 commits into
pingdotgg:mainfrom
saphid:hunter/c-00638f9b8d

Conversation

@saphid

@saphid saphid commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

When a tool's text output contains a JSON object with a repeated key, the work-log tool inspector shows only the last member. prettyJsonText parses and reserializes the text, and its loss check only looks at numbers, so JSON.parse has already overwritten the earlier member. Port 80 and the fact that port appeared twice both disappear.

Deterministic repro on origin/main (afd9ee2014aaa3c7bf5d039e52640d1470e11e6a): Call turnItemOutputText on a completed dynamic_tool item whose output is { content: [{ type: "text", text: '{"port":80,"port":443}' }] }. A local ACP tool can send the same text block as rawOutput, and the ACP adapter forwards generic raw output to dynamic_tool. Web, desktop and mobile tool details all render through turnItemOutputText.

  • Observed: {\n "port": 443\n}
  • Expected: the original {"port":80,"port":443}, shown unchanged

Change

The existing token scan for parsed JSON now also tracks the braces and brackets around each token. It keeps a set of decoded key names for each object and returns the raw text when an object repeats a key. Because it compares decoded names, "p\u006frt" and "port" count as the same key. Single JSON documents and line-delimited JSON both use this check. Objects with unique keys still get pretty-printed, and the existing exact-number checks are unchanged. One shared function covers all clients.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • packages/client-runtime/src/work-log/itemDetail.test.ts gains three "repeats a key" cases: top-level, nested with an escaped equivalent key, and line-delimited. It also gains a "still pretty-prints" case where sibling objects use the same key and a string value equals a key name.
  • On base, the 3 new cases fail. Example: expected '{\n "port": 443\n}' to be '{"port":80,"port":443}'. On head, all 51 tests in the file pass.
  • vp run check:changed exited 0 (format, lint, knip, typecheck, tests).
  • Before/after transcript: https://gist.github.com/saphid/33232c5da26bb2cb281b10a6f7786311

Not shown: no screenshot or scenarios:prove run of the expanded tool row in a real client. The proof covers the shared turnItemOutputText function that all clients call.

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • PR body:5 — Call afd9ee2 the tested base, not current origin/main; the local origin/main ref is 4265fde and its formatter independently reproduced the same loss.
  • PR body:5 — The helper test is deterministic but not a real-client scenario. Add steps for a local ACP tool to return the stated text block, then expand its completed work-log row and assert that both port entries are displayed.
  • PR body:22 — The gist shows 7 passing tests and 44 skipped on head, not the claimed full-file run. Attach the 51-test result or distinguish the reported run from the published transcript.
  • PR body:23 — The reported check:changed pass has no HEAD-stamped log in the evidence; attach the check summary for 51ff76a943cb839c737a91695d59ae3e4402c8a5 or note that it was not independently verified in read-only review.
  • PR body:26 — Before/after screenshots of the expanded inspector are not shown; attach them if available.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Dec 1, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 19325a6

Macroscope's review found this PR approvable — Repeated JSON keys are preserved in displayed tool text instead of being lost during pretty-printing. The change is limited to presentation and retains existing numeric-fidelity safeguards.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 19325a6 and 0102f9a.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

JSON formatting now detects duplicate object keys and preserves the original text when parsing would collapse them. Tests cover escaped duplicate keys, duplicates across JSON lines, and valid arrays that remain eligible for pretty-printing.

Changes: JSON formatting

Layer / File(s) Summary
Duplicate-key detection and formatting
packages/client-runtime/src/work-log/itemDetail.ts, packages/client-runtime/src/work-log/itemDetail.test.ts
The tokenizer identifies object keys and delimiters. The lossiness check detects repeated keys alongside existing numeric-loss checks. prettyJsonText preserves input when it detects lossy JSON. Tests cover escaped keys, JSON lines, and arrays with repeated object keys.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jadelike-wine, yash-singh1

Merge Risk: Minimal · previous review 19325

This change keeps JSON tool output with repeated keys as its original text instead of silently dropping earlier values. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the shared JSON display path now keeps repeated keys in tool output instead of dropping earlier values. The raw summary confirms that prettyJsonText and hasLossyJson n…
Description check Passed The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the reproduction, expected behavior, and observed output. The Change section explains…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the shared JSON display path now keeps repeated keys in tool output instead of dropping earlier values. The raw summary confirms that prettyJsonText and hasLossyJson now detect duplicate object keys and return the raw text. The title is specific and follows the conventional commit form. It is a fix, and the changes match it.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, and Verification. The Problem section gives the reproduction, expected behavior, and observed output. The Change section explains the fix and why one shared function covers all clients. The Scope section explains why no issue is linked. Verification lists the new tests and the results. Review notes flag gaps. The published transcript shows 7 passing and 44 skipped tests, not the claimed 51-test run. The check:changed result has no HEAD-stamped log. No real-client scenario or screenshot is shown. The template asks for a model and harness line, and the body names the model as Claude Opus 5.5 (Model Hub) but does not name a harness. The core template sections are present, so the check passes. The verification gaps should be fixed before merge.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e0064f8 and 19325a6.

Files selected for processing: 2

  • packages/client-runtime/src/work-log/itemDetail.test.ts
  • packages/client-runtime/src/work-log/itemDetail.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 1, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Web client, Chromium on Linux, 1280×1000, light theme, fresh isolated databases and identical replay outputs.

On each commit, create a fresh project and thread through t3.project/t3.thread. Replay “Check the service ports” with four completed tools returning {"port":80,"port":443}, {"server":{"port":80,"p\u006frt":443}}, {"id":1}\n{"id":2,"id":3}, and [{"port":80},{"port":443,"note":"port"}]. Open the thread, expand “Worked for”, “Used 4 tools”, and each tool row. Capture the expanded inspectors.

Scenario: Tool inspectors preserve repeated JSON members

Proven: the scenario fails on base 20a0e5f388 and passes on head 0102f9a8df.

Base 20a0e5f388 Head 0102f9a8df
Result ❌ failed
ASSERTION_FAILED: expect.toBeVisible failed
locator: getByText("{"port":80,"port":443}")
expected: visible
observed: no node (match count 0)
✅ passed
expanded tool outputs Base 20a0e5f388: expanded tool outputs Head 0102f9a8df: expanded tool outputs
failure Base 20a0e5f388: failure

Scenario · Before recording · After recording

Base loses port 80 in both objects and id 2 in JSON lines. Head displays the original repeated members. The unique-key control remains pretty-printed on both.

Not shown:

  • Desktop and mobile clients were not run; this proof exercises the shared formatter through the web client.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 1, 2026
@juliusmarminge
juliusmarminge merged commit 6baa47d into pingdotgg:main Dec 1, 2026
59 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 1, 2026
imetn added a commit to imetn/t4code that referenced this pull request Dec 2, 2026
…ce-control & server fixes)

Ported 15 commits from 772e3d4..1e6e7d7:
- ff548ac (pingdotgg#46552), 4025a2f (pingdotgg#46733), abf106f (pingdotgg#46759), c4f3661 (pingdotgg#46960), 5cac91c (pingdotgg#47138)
- 7cf7446 (pingdotgg#46736 mobile Usage filter env 'all', Lock pingdotgg#5 icons preserved)
- 0a5e0e3 (pingdotgg#46848 Android saved route priority)
- b6ac305 (pingdotgg#47096 mobile Git branch grapheme/flag cuts)
- 946d88b (pingdotgg#47098 mobile SVG pixel dimensions)
- c3faadd (pingdotgg#45111 mobile confirm stop once per run)
- a32c694 (pingdotgg#43968 PR Author menu replaces typed author qualifier)
- 6baa47d (pingdotgg#46934 preserve repeated JSON keys in tool output)
- aef9eb9 (pingdotgg#46497 Forgejo PR org labels)
- c57dd42 (pingdotgg#47143 Forgejo issue detail newest comments)
- a7256d6 (pingdotgg#46622 GitLab multiline issue titles)
(Note: pingdotgg#46702 8184b93 already functionally present via useOpenOrReturnToThread.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants