Skip to content

fix(setup): edit the duplicate JSON member that clients read - #4957

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/json-duplicate-member-edit
Oct 18, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/json-duplicate-member-edit

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4952. Setup and uninstall now edit the duplicate JSON member that the parsed document and JSON clients read (the last one), and they refuse an uninstall that would make an earlier shadowed duplicate active.

Problem and expected behavior

parseClientConfiguration reads JSON/JSONC with last-member semantics, the same as JSON.parse and native Claude Code. The shared serializer edited text through jsonc-parser's modify and findNodeAtLocation, and both of those pick the first matching property. As a result, setup on {"mcpServers": {...}, "mcpServers": {...}}, or on a repeated rea leaf, wrote into a member nobody reads, and the run ended in needs_human with failed/readback. Uninstall from a repeated parent table failed the same way. In every case the original file was restored.

Expected: edit the member the client reads, and leave shadowed duplicates and comments as they are. If removing the effective owned rea would make an earlier rea active (owned, foreign or unresolved), keep the configuration unchanged and say why.

Change and scope

  • ClientConfigurationDocument.ts now owns a single last-member locator (effectiveJsonProperty), and every JSON text edit goes through editJsonMember. The first-member modify path is gone. Formatting follows modify's own rule: jsonc-parser format runs over the touched lines.
  • serializeClientConfiguration returns Result<string, ClientConfigurationShadowedMember>. Deleting an effective member that has an earlier same-key sibling returns { kind: "shadowed_member", path }.
  • Uninstall serializes before taking a backup. On shadowed_member it reports failed with a specific explanation and writes nothing, not even a backup.
  • Setup serializes before its backup too. The only way setup deletes is OpenCode's legacy mcp.rea beside V2. That case now maps to a new shadowed_member failure reason with its own message.
  • Scope: an ordinary fix inside existing boundaries; no maintainer scope decision is needed. TOML, YAML and DSH serialization are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ClientConfigurationDocument JSON text-edit boundary.

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix inside existing setup/uninstall authority).

  • CLI and MCP/tool-catalog contract: setup client results gain failed/shadowed_member with path. Uninstall keeps failed and adds a new detail text. Tool catalog unchanged.

  • Provider, bridge, target-format, or platform compatibility: JSON/JSONC client formats only.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: shadowed members are never deleted or activated. A refused uninstall leaves the configuration untouched and creates no backup.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

  • Change process memory, registers, files, or configuration.

Evidence and regression coverage

  • Tests added or updated: new tests/acceptance/setup/duplicateJsonMemberSetup.test.ts, which runs the public CLI:

    • Claude Code setup with a repeated server table and with a repeated rea leaf succeeds. The shadowed member stays byte-for-byte, the backup matches the original, and a second setup plans nothing and leaves the file unchanged.
    • Cursor JSONC setup with a repeated table keeps the comments and the shadowed table.
    • Uninstall from a repeated parent table succeeds.
    • Uninstall with a foreign rea followed by an owned rea is refused. The file is unchanged and no backup is created.

    Existing serializer callers in ClientConfigurationDocument.capacity.test.ts and clientConfigurationEnvironment.test.ts were updated to the Result return.

  • Base reproduction: on origin/main (2c4338db1) the issue's CLI repro gave exit 1 with failed/readback for duplicate-parent setup and duplicate-leaf setup, and a failed uninstall (original restored) for duplicate-parent and foreign-then-owned. With this branch the same script gave exit 0 configured for both setups, exit 0 removed for duplicate-parent uninstall, and exit 1 failed for foreign-then-owned, with the file unchanged. All 5 new tests fail when run against origin/main sources.

  • User-visible output for the refused uninstall: Configuration repeats the member at ["mcpServers","rea"]; removing the registration the client reads would activate an earlier duplicate, so no change was made. Remove the duplicate members manually, then rerun uninstall.

  • Remaining proof gaps: native Claude Code and other native clients were not run for this change; the issue's native last-member observation is the only native evidence. Not run: Windows/Linux, and the OpenCode legacy shadowed_member setup path (source-derived only, no dedicated test).

Validation performed

  • npm run build:cached — passed
  • Issue repro script (setup/uninstall with isolated HOME/CLAUDE_CONFIG_DIR) on main and on this branch — results as above
  • npm run test:focused -- tests/acceptance/setup/duplicateJsonMemberSetup.test.ts on origin/main sources — 5 failed (expected)
  • npm run test:focused -- the related setup and client-configuration tests (44 files in tests/acceptance/setup and tests/boundary/filesystem, plus src/application/ClientConfigurationDocument.{capacity,shape}.test.ts and src/application/Setup.{configuration,recovery,planning,initialSnapshot}.test.ts) — 50 files, 738 passed, 2 skipped
  • npm run check:fast — passed
  • npx oxfmt --check on changed files — clean after formatting

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Configurations without duplicate members are edited as before.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only; native Claude Code not run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the fix narrows mutation. It never removes or activates a shadowed member.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

JSON.parse, JSONC parse, and native Claude Code keep the last duplicate
object member, and parseClientConfiguration therefore validates the last
one. The shared setup/uninstall serializer instead edited text through
jsonc-parser's modify and findNodeAtLocation, which select the first
matching member, so setup and uninstall on configurations with repeated
server tables or rea members wrote into a shadowed member and failed
readback.

Locate every JSON text edit by the effective (last) member in one place,
replacing the first-member modify path. Removing an effective member
that shadows an earlier duplicate would activate that duplicate, whatever
its ownership, so the serializer now returns a tagged shadowed_member
failure and setup and uninstall refuse before writing a backup or the
configuration.

Fixes #4952

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added bug Something isn't working track:issues Issue bug-fix track labels Oct 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T04:51:18.359854Z 59eaa2e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The reviewed changes appear safe to merge; no blocking issue was found.

Summary

Setup and uninstall now edit the last matching JSON member, which is the member clients read.

  • Setup and uninstall edit the JSON members clients actually read.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Build desired configuration] --> B[Locate last matching JSON member]
  B --> C{Would deletion reveal a duplicate?}
  C -->|Yes| D[Return failure without backup or write]
  C -->|No| E[Finish serialization]
  E --> F[Preserve original backup]
  F --> G[Publish and check configuration]
Loading

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@kaoru0822-kitauji
kaoru0822-kitauji merged commit b83b9ca into main Oct 18, 2026
35 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/json-duplicate-member-edit branch October 18, 2026 05:15
Geetesh72 added a commit to Geetesh72/rea that referenced this pull request Oct 18, 2026
fix(setup): edit the duplicate JSON member that clients read (morluto#4957)
NikeGunn added a commit to NikeGunn/rea that referenced this pull request Oct 18, 2026
Deleting repeats one at a time still copied the whole document once per
member, so tens of thousands of repeats in a large file cost k x n work.
All removal spans now come from one syntax tree and the text is rebuilt
once. A separator stays only between members that remain, plus a JSONC
trailing separator while any member remains, and comments outside the
removed members keep their bytes. The single-member deletion from morluto#4957
is unchanged. Removing 20,000 repeats drops from 35.8 s to 0.46 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
daffafikri19 pushed a commit to daffafikri19/rea that referenced this pull request Oct 23, 2026
daffafikri19 pushed a commit to daffafikri19/rea that referenced this pull request Oct 27, 2026
daffafikri19 pushed a commit to daffafikri19/rea that referenced this pull request Nov 7, 2026
daffafikri19 pushed a commit to daffafikri19/rea that referenced this pull request Nov 16, 2026
@morluto morluto added the area: setup Setup, packaging, upgrade, install, Doctor, and client registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working track:issues Issue bug-fix track

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Setup edits the first duplicate JSON member while clients read the last one

2 participants