Skip to content

fix(oc-path): use last duplicate JSON key to match runtime parsing - #189855

Merged
obviyus merged 7 commits into
openclaw:mainfrom
jerome-queck:fix/oc-path-duplicate-key-last-wins
Nov 1, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
jerome-queck:fix/oc-path-duplicate-key-last-wins

Conversation

@jerome-queck

@jerome-queck jerome-queck commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #189835

What Problem This Solves

For named duplicate keys in JSON, JSONC, and JSONL, path resolve and find select the first occurrence even though runtime parsing uses the last. path set can report success after changing only that shadowed first occurrence, leaving the effective configuration unchanged.

User Impact

Named-key reads, searches, predicates, and replacements now use the effective last occurrence. Real edits preserve earlier shadowed copies and unrelated source bytes. Insertion beneath a duplicated parent remains safely refused rather than editing the wrong copy.

Why This Change Was Made

Use last-key selection in the existing AST resolver/finder. Share a last-effective jsonc-parser node walk between JSONC and JSONL editors so edits target the correct source token, while retaining range formatting and source-preservation owners. No new grammar, dependency, public API, schema, authority, or configuration option.

Both commits by @jerome-queck are preserved. The live head fetched for takeover already included a4a0460bdb29, addressing the review's P3 recovery text. Its guidance was retained and verified through actual human CLI output and a successful retry after preserving the effective parent value—not replaced with a wording policy.

The follow-up consolidates the standalone regression file into existing JSONC resolve/edit, JSONL edit, and finder fixtures. All existing assertions remain; fixture data now discriminates first-versus-effective duplicate selection. Tests remain net zero lines. Current main was merged without rewriting contributor history, retaining the YAML alias fix from #189784 alongside last-wins JSON addressing. The merged finder retains its AST-access budget and stays within the existing lint ceiling.

Evidence

Independent built CLI and actual-write proof: secretless Linux Docker, Node 24.22.1, real files, independently built base/candidate CLI artifacts. In all three formats, main reads/finds1 twice and reports successful edits while runtime parsing still sees2. Candidate reads/finds2 twice and real set ... 5 makes runtime parsing see5, retaining the earlier1. JSONC comments/formatting, JSONL BOM/CRLF/literal tokens, nested duplicate parents, predicates, and winning scalar shapes are checked.

No-duplicate controls produce identical bytes on both refs. Candidate duplicate-parent insertion refusal leaves the file unchanged and prints actionable --human recovery text. Consolidating that parent while retaining its effective value, then retrying, succeeds.

After merging main 85ae35910a6e6f903fbe885eda88e7e343c3e09d, fresh builds and an additional main/candidate pair reproduce the same JSON/JSONC/JSONL contrast. A combined workspace proof interleaves YAML alias reads, actual duplicate-JSON writes, and YAML alias/cycle reads again: both refs retain two alias matches, scalar aliases, finite cycle traversal, and identical unchanged YAML bytes; only the candidate updates the runtime-effective JSON key. Candidate:153 passed across5 focused files, including YAML-kind coverage. Targeted lint and formatting pass. This is shipped CLI proof, not helper-only or dry-run-only edit evidence.

Merge Danger

Two-way door: reverting restores first-occurrence behavior; no migration. Explicit set writes workspace files, so preserve normal backups/review practices. Blast radius is named JSON/JSONC/JSONL object addressing and source-token replacement. Positional object selectors still count source entries, including shadowed copies; their semantics are not changed here. Safe insertion refusal and ordinary-file behavior remain intact.

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Makes named JSON, JSONC, and JSONL reads, searches, and edits select the last duplicate key.

Example: Run openclaw path set oc://config.json/port 5 on {"port":1,"port":2}.

  • Before: The file becomes {"port":5,"port":2}, so runtime parsing still reads 2.
  • After: The file becomes {"port":1,"port":5}, so runtime parsing reads 5.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, useful repair with exact-head CLI proof, discriminating regressions, preserved historical contracts, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact-head evidence exercises the shipped CLI in secretless Linux Docker against real JSON, JSONC, and JSONL files, verifies effective values after actual writes, and covers nested duplicates, predicates, source preservation, refusal recovery, ordinary-file controls, and adjacent YAML behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The CLI can report successful edits while runtime parsing continues to use the unchanged duplicate value.
Reason: Matching effective runtime values restores useful inspection and editing behavior within the existing optional plugin contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current wrong-value editing bug, has convincing shipped-CLI proof, and has no actionable findings; exact-head CI remains pending.

Priority: P2
Reviewed head: 1a21e4e9f5eed096a0c773e1cd0a6fe280fbb6ec

Before merge

None.

Findings

None.

Agent review details

How this fits together

The optional bundled oc-path plugin translates CLI addresses into format-specific reads and edits, returning matches or updated workspace-file bytes.

flowchart LR
  A[Path CLI] --> B[Address and format dispatch]
  B --> C[JSONC and JSONL resolver]
  B --> D[Finder]
  C --> E[Effective source node selection]
  E --> F[Format specific editor]
  F --> G[Workspace file]
  D --> H[Resolved matches]
Loading

Technical review

Best possible solution:

Land the consistent last-occurrence repair through the existing plugin owners once required CI passes.

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

Current-main source and the pinned dependency establish first-occurrence reads and writes; supplied built-CLI traces demonstrate the failure and correction, while this read-only review executed no target code.

Is this the best way to solve the issue?

The patch fixes selection at the existing resolver, finder, and editor boundaries, shares the necessary token walk, and retains format-specific byte handling without unnecessary machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ffbaf04726a5.

Provenance checked

  • JSON value resolution and finder selection changes intended behavior with a stated reason (88c49f9: The shared resolver consolidation retained first-match lookup; inspected history establishes no deliberate duplicate-key policy.)
  • JSONC replacement formatting and insertion keeps the original intent (95da05d: The editor separates replacement from insertion to preserve parser-owned formatting; the patch retains that formatting contract while selecting the effective replacement token.)
  • JSONL source-token edits keeps the original intent (fix(oc-path): preserve untouched JSONL data during edits #172410: Token-local edits preserve untouched numeric literals, comments, whitespace, BOMs, separators, and malformed records.)
  • Quoted keys and typed traversal keeps the original intent (fix(oc-path): keep quoted positional keys literal #172382: Shared traversal preserves literal special keys and distinguishes object keys from array indexes.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e3b33a2 adds extensions/oc-path/src/oc-path/find.ts:30 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e3b33a26cdb1; files: extensions/oc-path/src/oc-path/find.ts)
  • Vincent Koc: Raw commit 88c49f9 adds extensions/oc-path/src/oc-path/jsonc/resolve-value.ts:36 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 88c49f9e68fc; files: extensions/oc-path/src/oc-path/jsonc/resolve-value.ts)
  • fhgffy: Raw commit ae55909 adds extensions/oc-path/src/oc-path/jsonc/resolve-value.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ae55909c9026; files: extensions/oc-path/src/oc-path/jsonc/resolve-value.ts)

PR surface

Source +48, Tests 0, Docs +6. Total +54 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 69 21 +48
Tests 4 12 12 0
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 87 33 +54

Review metrics

Metric Value Why it matters
Production versus test LOC Production +69/-21; tests +12/-12 The production growth implements shared effective-node selection and replacement while preserving existing formatting and insertion owners; regression fixtures gain duplicate-key discrimination without test growth.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This fixes deterministic wrong-value reads and ineffective writes in an optional advanced CLI workflow when files contain duplicate keys.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-31T23:30:27.338Z sha 1c012aa :: needs changes before merge. :: [P3] Give users a recovery step for duplicate-parent insertion refusal
  • reviewed 2026-11-01T00:04:51.270Z sha a4a0460 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-01T00:16:47.041Z sha 5d91973 :: needs maintainer review before merge. :: none

Reviewed October 31, 2026, 8:38 PM ET / November 1, 2026, 00:38 UTC (Revision 4).

@jerome-queck

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 1, 2026
@obviyus

obviyus commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Independent built CLI proof — effective duplicate JSON keys

Candidate 5d91973b2351940e5de33997eec1562ef58db798; main baseline 65aa4cc5499d6607faa9ff19711555986eb3a8be. Adopted live contributor head a4a0460bdb29aba23cdcfd06e0387cb87a1d1a7c, which already contains the factual P3 recovery-text fix after the originally assigned 1c012aaf49; both contributor commits are preserved unchanged.

Independently installed and built both source snapshots with the canonical runtime build in secretless Linux node:24.22.1 Docker. Four fresh task-owned profiles/workspaces run the shipped CLI against real .json, .jsonc, and .jsonl files. Plugin inspection confirms each arm selects its own compiled dist/extensions/oc-path/index.js. No mocked filesystem or direct helper substitutes for CLI execution.

Each file starts with port:1 followed by effective port:2. path set .../port 5 performs a real write, not a dry run. The harness independently reads the resulting disk bytes after CLI exit and applies JSON.parse (removing only the known JSONC comment line or JSONL BOM for strict-reference parsing).

All three formats                     main #1/#2      candidate #1/#2
resolve named port                    1 / 1          2 / 2
find named port through wildcard      1 / 1          2 / 2
set reports success                   yes / yes      yes / yes
actual runtime value after set 5      2 / 2          5 / 5
actual ordered source tokens          [5,2]          [1,5]

Candidate edits the effective last occurrence while retaining the earlier shadowed copy. Exact source-byte checks retain JSONC comments/formatting and JSONL BOM, CRLF, and an untouched 1e+02 token on the next record. Nested duplicate parents also update the effective child: main leaves runtime value2, candidate writes7. Predicate selection follows effective booleans/values, and a scalar winning over an earlier object makes descent correctly unresolved on candidate.

Ordinary no-duplicate reads and real writes are unchanged in all four runs; their resulting bytes have the same SHA-256: 7094622b823f41905ea714e5a365564ca38afc191549f736760708881634ae93.

P3 recovery guidance is factual

The live contributor follow-up already supplied this error detail; I retained it rather than introducing a wording policy. Actual --human output on both candidate runs:

set failed: not-writable — insertion under a duplicated key is ambiguous; merge the duplicate keys into one (keeping the last, effective value), then retry the insertion

Both refusals preserve the file. Following that advice—consolidating the duplicate parent while retaining its effective {port:2}, then retrying the real insertion—succeeds and produces {group:{port:2,new:9}}. Raw human output and the recovered actual file are retained.

Committed regressions without growth

Consolidated the standalone duplicate-key test into existing JSONC resolve/edit, JSONL edit, and finder fixtures. All existing assertions remain; duplicate inputs strengthen their effective-value coverage, including empty keys, predicate fields, nested objects, and arrays. No new test lines or allocation.

Same final fixtures on frozen main: 7 intended failures / 106 passes. Candidate: 113 pass across 4 files. Targeted lint reports zero warnings/errors; formatting passes. Production is unchanged from the live contributor head: +68/-15; tests +12/-12 (net0); docs +6.

Limits: named-key semantics only; positional object selectors still count source entries, including shadowed copies. No new grammar, parser dependency, schema, authority, or configuration contract. The existing safe insertion refusal is preserved. Production source hashes match the final candidate and built artifact inputs.

@obviyus

obviyus commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Nov 1, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@obviyus

obviyus commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Current-main integration proof

Exact candidate: 1a21e4e9f5eed096a0c773e1cd0a6fe280fbb6ec. Merged frozen main 85ae35910a6e6f903fbe885eda88e7e343c3e09d without rewriting contributor commits. This retains #189784's YAML alias/cycle handling and the duplicate-key last-wins fix together.

Fresh secretless Linux Docker / Node 24.22.1 canonical runtime builds, then real shipped openclaw path CLI commands against actual files:

Additional pair after merge Main Candidate
JSON, JSONC, JSONL named read/find shadowed 1 effective 2
Actual set port 5, independently parsed disk tokens [5,2], runtime remains 2 tokens [1,5], runtime becomes 5
Ordinary no-duplicate control identical bytes identical bytes

The earlier two independently built main/candidate repetitions remain documented in the original evidence. The new pair reruns nested duplicate parents, predicates, winning scalar shapes, insertion refusal, actual human recovery and successful retry, JSONC comment/format preservation, and JSONL BOM/CRLF/untouched literal preservation.

Combined adjacent-file control: one workspace contains YAML anchors/aliases/a self-cycle and duplicate-key JSON. Both fresh refs find two YAML alias ports, resolve the scalar alias to stable, then perform the JSON read/find/actual write, then find the same YAML alias results and finitely traverse the self-cycle (two label matches). YAML bytes remain identical (c697ab4d2bc1cd5fb73d06df4eab9ff4b7d6857a2954261f2d6137b024bf2f3b). JSON remains wrong on main and targets the effective key on the candidate. These are interleaved CLI invocations, not a claimed single-process batch.

Final exact-source build/proof task succeeded. Focused suites: 153 passed /5 files, including YAML-kind coverage. Targeted oxlint:0 errors/warnings; formatting:12 files passed. Test delta remains net zero. An intermediate attempted lint compaction increased AST getter reads and was rejected by the existing expansion-budget regression; the final source restores the single cached access, passes that regression, and compacts the equivalent null return instead.

Host and built-container source SHA256 agree: finder 47697acaccc037d47ae2606f2e6398966ca0bc71dc2380570597bbdc8842b695; YAML resolver fcc20cc54e442163b5783b2b4b3b0cba4f364d736ad668b128cad8a17cb548a2. No system clock changes, external credentials, or contributor execution on the host.

@obviyus

obviyus commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@obviyus
obviyus merged commit 7f593b6 into openclaw:main Nov 1, 2026
101 checks passed
@obviyus

obviyus commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Landed in 7f593b6. Thanks @jerome-queck. CLI path tools now use the effective last key when a key is repeated.

vincentkoc added a commit that referenced this pull request Nov 1, 2026
…ed-backup-search-exports-20261101

* commit 'cde4bfe4f10ce470ded7264c68d9a72ae03594cc':
  fix(ci): keep backup and chat search internals private (#189894)
  fix(codex): recover unused native threads without dropping history (#189900)
  fix(oc-path): use last duplicate JSON key to match runtime parsing (#189855)
  perf(test): parse the Mantis resolver workflow once (#189801)
  fix(agents): revert default hard context admission (#189891)
  refactor(test): use canonical tracked temp paths (#189800)
  chore(ui): refresh control ui locales (#189898)
  improve: show gateway commit and build time on About
  refactor(test): share SDK export fixture JSON writes (#189799)
  fix: restore Files navigation from unavailable previews (#189879)
  refactor(test): share raw ratchet fixture writes (#189798)
  fix(ai): honor Model Studio compatible-mode output limits (#189870)
  fix: hold queued messages through inline edits (#189869)
  perf(test): reuse the baseline fixture Node resolver (#189790)
  test(qa): correlate handoff replies by run identity (#189885)
  fix(ui): normalize canonical Unicode in local search comparisons (#189874)
  fix(ui): explain unsupported browsers without module scripts (#189883)

# Conflicts:
#	ui/src/pages/chat/components/chat-search-highlight.browser.test.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…penclaw#189855)

fix(cli): use the effective last key when a JSON file repeats a key

Fixes openclaw#189835.

When a JSON, JSONC or JSONL object repeated a key, CLI path resolve, find and set used the first occurrence. Runtime parsing takes the last one, so set reported success while the value OpenClaw actually used stayed the same. Path tools now select and rewrite the effective last key and keep the shadowed copies. Files without duplicates produce byte-identical output. JSONC comments and formatting, and JSONL BOM, CRLF and literal tokens, are preserved. The human-readable recovery text points to consolidating the duplicates. This works together with YAML alias resolution from openclaw#189784.

Evidence: built CLI in secretless Node 24.22.1 Docker on real JSON, JSONC and JSONL files, rebuilt after merging current main. Main selected the first key and reported writes that didn't change the effective value; with this change the effective last key was selected and actually rewritten. A combined YAML and JSON workspace kept aliases, scalar aliases, finite cycle traversal and unchanged YAML bytes across actual JSON writes. Details: openclaw#189855 (comment) and openclaw#189855 (comment).

Thanks @jerome-queck.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport of 7f593b6 (#189855). Preserve shadowed source copies while resolving and editing the runtime-effective last key. Targeted baseline: 7 failed, 104 passed; fixed: 111 passed. Scoped self-review retained existing parser and edit ownership.

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: oc-path P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: openclaw path set silently edits a shadowed duplicate key in JSON/JSONL, so the effective value never changes

2 participants