Skip to content

🐛 Quote an edited flow-unsafe scalar inside a flow collection#189

Merged
frenck merged 1 commit into
mainfrom
frenck/roundtrip-quote-flow-indicators
Jul 3, 2026
Merged

🐛 Quote an edited flow-unsafe scalar inside a flow collection#189
frenck merged 1 commit into
mainfrom
frenck/roundtrip-quote-flow-indicators

Conversation

@frenck

@frenck frenck commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Breaking change

None. This only changes how an edited-in scalar is emitted inside a flow collection (it is now quoted when it must be); an unmodified document still re-emits byte-for-byte.

Proposed change

A value assigned into a flow collection ([...]/{...}) that contained a flow indicator was emitted as a bare plain scalar, so doc["seq"][0] = "a,b" produced [a,b, 2], which reparses as two entries (and [/{/: break the parse outright).

The round-trip emitter now tracks how many flow collections are open and quotes a plain scalar carrying a flow indicator (, [ ] { }, or a : / trailing :) while inside one. This only affects an edited-in value: a loaded plain scalar never contains a bare flow indicator (the scanner would not produce one), so an unmodified document still re-emits byte-for-byte.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

  • This PR fixes or closes issue: None
  • This PR is related to: None
  • Link to a separate documentation pull request: None

Checklist

  • I have read the AI Policy, and this pull request was not created by an autonomous agent.
  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and uv run pytest passes locally. A pull request cannot be merged unless CI is green.
  • uv run ruff check . and uv run ruff format --check . pass.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings pass.
  • Round-trip fidelity is preserved: an unmodified document still re-emits byte-for-byte.
  • No commented-out or dead code is left in the pull request.

If the change is user-facing:

  • Documentation under docs/ is added or updated, and docs/verify_examples.py still passes.

A value assigned into a flow collection (`[...]`/`{...}`) that contained a flow
indicator was emitted as a bare plain scalar, so `doc["seq"][0] = "a,b"` produced
`[a,b, 2]`, which reparses as two entries (or breaks the parse for `[`/`{`/`: `).

The round-trip emitter now tracks how many flow collections are open and quotes a
plain scalar carrying a flow indicator (`,` `[` `]` `{` `}`, or a `: ` / trailing
`:`) while inside one. This only affects an edited-in value: a loaded plain
scalar never contains a bare flow indicator (the scanner would not produce one),
so an unmodified document still re-emits byte-for-byte.
Copilot AI review requested due to automatic review settings July 3, 2026 10:41
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@frenck, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ebb42114-5523-4b42-b5ed-8c0f72e38db0

📥 Commits

Reviewing files that changed from the base of the PR and between 78e2a24 and b5dfc4b.

📒 Files selected for processing (2)
  • src/roundtrip/emit.rs
  • tests/roundtrip/test_edge_cases.py

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.

@codspeed-hq

codspeed-hq Bot commented Jul 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing frenck/roundtrip-quote-flow-indicators (b5dfc4b) with main (78e2a24)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a round-trip emitter bug where a value edited into a flow collection ([...]/{...}) that contains a flow indicator was emitted as a bare plain scalar. For example, doc["seq"][0] = "a,b" produced [a,b, 2], which reparses as two entries; a [/{/: would break the parse entirely. This sits in src/roundtrip/ (the rich AST + emitter path), complementing the fast dumps path, which already quoted such scalars in flow context via has_flow_indicator.

The emitter now tracks how many flow collections are open (flow_depth) and double-quotes a plain scalar carrying a flow indicator while inside one. I verified this only affects edited-in values: flow_depth is incremented/decremented symmetrically only in emit_flow_sequence/emit_flow_mapping (the sole sites emitting [/{), with no intervening early returns, and unmodified documents still re-emit verbatim, so byte-for-byte fidelity is preserved. The : /trailing-: branches of plain_unsafe_in_flow are defensive (such values are already quoted at assignment time by needs_quoting), which is consistent with the emitter treating quoting as its own correctness boundary.

Changes:

  • Added a flow_depth counter to RoundTripEmitter, maintained around flow-collection emission.
  • Added a new emit_scalar arm that double-quotes a plain scalar via plain_unsafe_in_flow when inside a flow collection.
  • Added a parametrized test verifying edited-in flow-unsafe scalars round-trip as a single string.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/roundtrip/emit.rs Adds flow_depth tracking and the plain_unsafe_in_flow guard so edited-in flow-unsafe plain scalars are quoted; core of the fix.
tests/roundtrip/test_edge_cases.py Adds a parametrized test asserting values with ,[]{}/: /trailing : round-trip correctly inside flow collections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.38%. Comparing base (78e2a24) to head (b5dfc4b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #189   +/-   ##
=======================================
  Coverage   92.37%   92.38%           
=======================================
  Files          40       40           
  Lines       11580    11595   +15     
=======================================
+ Hits        10697    10712   +15     
  Misses        883      883           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frenck frenck merged commit a1fcd86 into main Jul 3, 2026
74 of 75 checks passed
@frenck frenck deleted the frenck/roundtrip-quote-flow-indicators branch July 3, 2026 10:59
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants