Skip to content

Preserve JSON input object order#2

Closed
dnagoda wants to merge 1 commit into
dc.batch-1-jsonl-modefrom
dc.batch-2-preserve-json-order
Closed

Preserve JSON input object order#2
dnagoda wants to merge 1 commit into
dc.batch-1-jsonl-modefrom
dc.batch-2-preserve-json-order

Conversation

@dnagoda

@dnagoda dnagoda commented Jul 2, 2026

Copy link
Copy Markdown
Owner

📚 Stack (bottom → top)

  1. Add batch mode for processing multiple inputs via JSONL #1 Add batch mode for processing multiple inputs via JSONL
  2. Preserve JSON input object order #2 Preserve JSON input object order
  3. Refine batch failure handling #3 Refine batch failure handling
  4. Reuse the compiled provider across runs #4 Reuse the compiled provider across runs
  5. Compute humanized bytes lazily #5 Compute humanized bytes lazily
  6. Add minimal batch output with --batch-full-output opt-in #6 Add minimal batch output with --batch-full-output opt-in

Stacked draft PRs on the fork; review bottom-up. Merge target is Shopify/function-runner once upstream write access is available.


Why

function-runner parses each JSON input into serde_json::Value and
reserializes it to bytes before handing it to the Wasm module. With
serde_json's default map, object keys are reordered lexicographically. JS
functions that rely on Object.keys() ordering (e.g. fallback/localized-message
logic in Checkout Blocks discount functions) can then behave differently under
replay than in production, breaking parity.

What

  • Enable serde_json's preserve_order feature so input object key order is
    retained end-to-end through the runner.
  • Add a regression test covering nested, metafield-like message objects to lock
    in the ordering guarantee.

This brings function-rerunner inputs closer to real production bytes.

Testing

  • cargo test json_input_preserves_object_key_order_in_raw_bytes
  • cargo build --release
  • cargo test
  • Re-ran the 17 discount localized-message mismatch rows with the fixed release
    runner → full semantic matches.

Function-runner parses JSON inputs into serde_json::Value and reserializes them before passing bytes to the WASM. With serde_json's default map implementation, this sorts object keys lexicographically, which can change JS behavior that depends on Object.keys() ordering for fallback logic.\n\nEnable serde_json's preserve_order feature so JSON input object key order is retained, and add a regression test covering nested metafield-like message objects. This keeps function-rerunner parity closer to production inputs for Checkout Blocks discount functions.\n\nVerified with:\n- cargo test json_input_preserves_object_key_order_in_raw_bytes\n- cargo build --release\n- cargo test\n- Rerunning the 17 discount localized-message mismatch rows with the fixed release runner produced full semantic matches.

Assisted-By: devx/c659e918-9568-4750-b122-e3890447348a
@dnagoda

dnagoda commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

Moved upstream to Shopify#590 now that write access is available. Closing this fork PR.

@dnagoda dnagoda closed this Jul 6, 2026
@dnagoda dnagoda deleted the dc.batch-2-preserve-json-order branch July 6, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant