Skip to content

fix(wire-codec): stop encode silently dropping a literal __proto__ field - #342

Merged
prisis merged 4 commits into
alphafrom
fix/303-wire-proto-roundtrip
Aug 4, 2026
Merged

prisis merged 4 commits into
alphafrom
fix/303-wire-proto-roundtrip

Conversation

@prisis

@prisis prisis commented Aug 4, 2026

Copy link
Copy Markdown
Member

Plan 303(b). Found by the thermos review of #339.

The asymmetry

decodeWire has always preserved a __proto__ key faithfully, installing it with Object.defineProperty so it lands as an own data property rather than firing the prototype setter.

encodeWire did not. Its plain-object branch used a bare result[key] = …, which for that one key invokes the setter and creates no own property — so the field silently vanished:

own keys in:            [ 'b', '__proto__' ]
after the assign loop:  {"b":2}                     own keys: [ 'b' ]
with defineProperty:    {"b":2,"__proto__":{"a":1}} own keys: [ 'b', '__proto__' ]

Why it's reachable

JSON.parse makes __proto__ an own key, so any document written before the codec shipped can carry one. Studio's row editor is one such path: it seeds from encodeWire(doc), so the field was absent from the editor text and an untouched save deleted it from the row.

Not a pollution change

defineProperty is precisely what avoids invoking the setter. The test asserts the key survives all three hops (parse → encode → JSON → decode) and that a bare {} gains nothing along the way.

Demonstrated to fail against alpha: expected [ 'amount' ] to strictly equal [ '__proto__', 'amount' ].

Suites: client 641, do 519, shard-engine 981, studio 1012.

🤖 Generated with Claude Code

https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347

…field

`decodeWire` has always preserved a `__proto__` key faithfully, installing it
with `Object.defineProperty` so it lands as an own data property rather than
firing the prototype setter. `encodeWire` did not: its plain-object branch used
a bare `result[key] = …`, which for that one key invokes the setter and creates
no own property — so the field simply vanished from the output.

The two halves therefore disagreed, and the loss was silent. A stored document
carrying a literal `__proto__` field (`JSON.parse` makes it an OWN key, so this
is reachable for anything written before the codec shipped) lost it on every
re-encode. Studio's row editor is one such path: it seeds from
`encodeWire(doc)`, so the field was absent from the editor text and an
untouched save deleted it from the row.

Encode now mirrors decode. No pollution is introduced — `defineProperty` is
precisely what avoids invoking the setter, and the round-trip test asserts a
bare `{}` gains nothing.

Found by the thermos review of plan 300; filed as plan 303(b).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347
@netlify

netlify Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for lunorash ready!

Name Link
🔨 Latest commit d822b1c
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a719f7b9802c90008573ac9
😎 Deploy Preview https://deploy-preview-342--lunorash.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • packages/client/__tests__/wire-codec.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • shared/wire-codec.ts is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 14c0c761-1ba7-46e3-a56f-30acd786f4f8

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

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

The round-trip deliberately goes through `JSON.parse(JSON.stringify(...))` to
model the actual transport. `structuredClone` preserves values JSON drops, so
swapping it in would make the assertion vacuous.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WfuWNN3cWJE6beZjng347
@prisis
prisis merged commit f8b05d0 into alpha Aug 4, 2026
41 checks passed
@prisis
prisis deleted the fix/303-wire-proto-roundtrip branch August 4, 2026 08:31
@codspeed

codspeed Bot commented Aug 4, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 250 untouched benchmarks
⏩ 10 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ flat 3 primitives (the notify.send attribute shape) 55.5 µs 62.5 µs -11.24%
⚡ 1 shard × 1000 rows (single round-trip) 3.1 ms 2.7 ms +13.21%
⚡ baseline (Object.keys + toInternal + path spread per field) 72 µs 65.1 µs +10.67%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/303-wire-proto-roundtrip (d822b1c) with alpha (596dd3c)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on alpha (a20d7fd) during the generation of this report, so 596dd3c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — d822b1c3 Deployed Aug 4, 2026 by prisis via Benchmarks #1439
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant