Repository navigation
fix(id-core): reject duplicate JSON keys in parse_surface (#6491) - #8424
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 15 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64e10b3fde
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .and_then(|value| value.get("kind")) | ||
| .and_then(Value::as_str); | ||
| if matches!(kind, Some("screen" | "text")) | ||
| || err.to_string().contains("\"kind\"") |
There was a problem hiding this comment.
Restrict duplicate-kind rejection to the top-level object
For legacy JSON such as {"payload":{"kind":"a","kind":"b"}}, the duplicate-key error contains "kind" even though the duplicate is nested and cannot affect surface dispatch. This condition therefore changes the result from Ok(None) to an error for non-surface data, violating the preserved plain-text fallback. Consequently, world_session::send_view sends an invalid-presentation error instead of the view, and the web view handler returns HTTP 500. Track the duplicate's depth/path rather than treating every duplicated kind as a top-level discriminator.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d1fdabc: the err.to_string().contains("\"kind\"") test is gone. parse_surface now calls a new top_level_kind_is_duplicated() scan that walks only the top-level object's keys (nested values are skipped with IgnoredAny, which does not itself reject duplicates), so rejection requires either a top-level kind of screen/text or a repeated top-level kind — the only duplicate that makes dispatch ambiguous. A kind duplicated inside a nested object (your {"payload":{"kind":"a","kind":"b"}} example, and the same shape under a non-surface top-level kind) stays on the legacy plain-text path as Ok(None); both shapes are pinned as regression controls in duplicate_keys_in_surface_documents_are_rejected. Verified: cargo test -p id-core --lib world_presentation 33/33 and the duplicate-key suite 9/9 pass. (Fix landed by queue lane code-c under triage task 10977, which owns routing this issue; the branch's original task 14443 is inactive.)
…ct (#6491) Codex P2 on PR #8424: parse_surface rejected any document whose duplicate-key error named kind, including a kind duplicated only inside a nested object ({"payload":{"kind":"a","kind":"b"}}), which cannot affect the top-level dispatch — legacy plain-text documents turned into errors. The error-string match is replaced with top_level_kind_is_duplicated(), a top-level-only scan that skips nested values with IgnoredAny: only a repeated top-level kind (ambiguous dispatch) or a duplicate inside a document whose top-level kind is screen/text rejects. Regression controls added to duplicate_keys_in_surface_documents_are_rejected: nested-kind duplicates with no surface kind and with a non-surface kind both stay Ok(None). world_presentation 33/33 and duplicate-key 9/9 tests pass.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1fdabc60f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if seen_kind { | ||
| return Ok(true); |
There was a problem hiding this comment.
Consume the full map before returning the duplicate-kind verdict
When a repeated top-level kind is followed by another field, this early return leaves the map unconsumed. serde_json calls end_map() after the visitor returns, so the remaining comma produces an error that .unwrap_or(false) converts into a negative duplicate verdict. Consequently, {"kind":"screen","kind":"other","version":1} returns Ok(None) and is forwarded as legacy text instead of rejecting the ambiguous surface discriminator. Retain a duplicate flag while consuming the remaining entries, and add a regression case where the surviving kind is non-surface and further fields follow.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@/tmp/codex-reply-10977.md
There was a problem hiding this comment.
Fixed — and a correction to my previous reply on this thread (comment 4539019448), which posted a file path (@/tmp/codex-reply-10977.md) instead of the reply text. This comment is the actual disposition:
top_level_kind_is_duplicated() no longer returns early on a repeated top-level kind. The visitor now records the duplicate in a flag and keeps consuming the rest of the map (next_key/next_value::<IgnoredAny>() to the end) before returning the verdict, so serde_json's end_map() succeeds and the caller sees the true verdict instead of a trailing-content error mapped to false.
Regression coverage: the duplicate-kind documents in duplicate_keys_in_surface_documents_are_rejected (including a repeated kind followed by further keys) are rejected by parse_surface.
Landed in 258ef8a; the branch has since been rebased onto current main (conflict with the new TokenSpan struct resolved by keeping both additions) — current PR head 2a47b4e, with the fix unchanged. Targeted tests on the rebased head: cargo test -p id-core world_presentation — 34 passed, 0 failed.
…ct (#6491) Codex P2 on PR #8424: parse_surface rejected any document whose duplicate-key error named kind, including a kind duplicated only inside a nested object ({"payload":{"kind":"a","kind":"b"}}), which cannot affect the top-level dispatch — legacy plain-text documents turned into errors. The error-string match is replaced with top_level_kind_is_duplicated(), a top-level-only scan that skips nested values with IgnoredAny: only a repeated top-level kind (ambiguous dispatch) or a duplicate inside a document whose top-level kind is screen/text rejects. Regression controls added to duplicate_keys_in_surface_documents_are_rejected: nested-kind duplicates with no surface kind and with a non-surface kind both stay Ok(None). world_presentation 33/33 and duplicate-key 9/9 tests pass.
258ef8a to
2a47b4e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a47b4e362
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if matches!(kind, Some("screen" | "text")) | ||
| || err.to_string().contains("\"kind\"") |
There was a problem hiding this comment.
Scan for duplicate kind independently of the first duplicate error
When another key is duplicated before kind, an ambiguous surface discriminator still passes through as legacy text. For example, {"x":1,"x":2,"kind":"screen","kind":"other"} returns Ok(None): the unique-key parser stops at the repeated x, its error does not mention kind, and the lenient parse retains only "other". Consequently, world_session::send_view forwards the document instead of rejecting it. Call the newly added top_level_kind_is_duplicated(data) scanner rather than relying on which duplicate the parser encounters first.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in aa60487 — and thank you, this one was a real catch by re-review: the finding was caused by this branch's own rebase. Resolving the TokenSpan conflict from the pre-conflict stage file silently dropped the parse_surface condition change from d1fdabc, so the verdict again depended on which duplicate the unique-key parser hit first, exactly as you describe.
The condition now calls top_level_kind_is_duplicated(data) again (independent of the first duplicate error), and your example document {"x":1,"x":2,"kind":"screen","kind":"other"} is added to the duplicate_keys_in_surface_documents_are_rejected regression list.
Verified on the new head: cargo test -p id-core world_presentation — 34 passed, 0 failed.
…6491) The rebase onto main resolved the TokenSpan conflict from the pre-conflict stage file, which silently dropped the parse_surface condition change from d1fdabc: the duplicate verdict again relied on the parser error naming kind, so a duplicate key preceding a duplicated kind ({"x":1,"x":2,"kind":"screen","kind":"other"}) slipped through as legacy text (Codex P2 4540059438 on PR #8424). Restore the top_level_kind_is_duplicated(data) call and add that document shape to the regression list.
Closes #6491.
Problem
parse_surface(pkgs/id/crates/id-core/src/world_presentation.rs) parsed the guest document into aserde_json::Valuefirst, so duplicate JSON keys collapsed last-wins before any check ran: a forbidden version, width, lines, or rows hidden behind a benign duplicate was accepted, and every presenter trusts this verdict. Same defect class as #6473 / #6474.Fix
parse_surfacenow parses through the existing shared helpercrate::json_unique::parse_json_without_duplicate_keys(the Design: a duplicate key is a parse error — one duplicate-key refusal contract for pkgs/id's checked JSON gates #6520 rule, already used byworld_caps::parse_wants).kind: text/kind: screendocument — or a duplicatedkindkey itself, which makes the dispatch ambiguous — is rejected with an error. Non-surface JSON and ordinary strings keep the legacy plain-text path (Ok(None)), unchanged.duplicate_keys_in_surface_documents_are_rejecteduses raw string literals (json! values cannot represent duplicate keys) covering: duplicateversion(text and screen), duplicatewidth, duplicatelinescarrying a control character, duplicaterows, duplicatekind, and a duplicate key inside a nested style-span object — plus single-key and non-surface controls.Tests
cargo test -p id-core world_presentation— 33 passed, 0 failed (laptop).cargo test -p id-core --lib— 361 passed, 0 failed, 1 ignored (laptop).Queue: task 14443, lane code-e.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.