Skip to content

feat(common-json): mark and rewind the generator - #3214

Merged
jfallows merged 3 commits into
developfrom
feature/json-generator-mark-rewind
Nov 13, 2026
Merged

jfallows merged 3 commits into
developfrom
feature/json-generator-mark-rewind

Conversation

@jfallows

@jfallows jfallows commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds mark() and rewind() to JsonGeneratorEx, the output-side counterpart of the parser's mark() and rewind().

A generator can mark its position between writes and rewind to it. Rewinding discards the bytes written since the mark and restores the structural context: open object and array depth, the separator state of each open level, an open string or number fragment, the open escaped scopes, and length(), remaining() and consumed(). A unit of output can therefore be generated and measured, then either kept or taken back and generated again.

Contract, mirroring the parser:

  • one mark is held, and marking again replaces it
  • the mark is valid until the next wrap or reset, and rewind() throws IllegalStateException otherwise
  • marking does not allocate once the generator has marked at its deepest context
  • the methods are declared without a default: JsonGeneratorImpl is the one implementation of JsonGeneratorEx and supports both

Tests (JsonGeneratorMarkRewindTest):

  • for nested, escaped-scope and fragmented documents, every combination of mark position and walk length rewinds to output identical to an uninterrupted run
  • a reflection check that every mutable field of the generator is restored to its value at the mark, so a field added later and missed by the mark fails the test
  • length(), remaining() and consumed() are restored
  • re-marking replaces the mark
  • rewinding without a mark, or after wrap or reset, is refused

Verification: ./mvnw clean install -pl runtime/common-json passes (5245 tests, 0 failures).

No issue was opened first, as this is a small, additive API change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

A generator can mark its position between writes and rewind to it, which discards the bytes written since and
restores the structural context, so a unit of output can be generated, measured and then kept or taken back and
generated again. This is the output-side counterpart of the parser mark and rewind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ
…wind

The generator mark and rewind are declared without a default, as JsonGeneratorImpl is the one implementation
of JsonGeneratorEx and supports both.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ
@jfallows
jfallows merged commit 508660f into develop Nov 13, 2026
102 checks passed
jfallows added a commit that referenced this pull request Nov 14, 2026
… per-filter suback failure (#3231)

* feat(common-json): mark and rewind the generator (#3214)

* feat(common-json): mark and rewind the generator

A generator can mark its position between writes and rewind to it, which discards the bytes written since and
restores the structural context, so a unit of output can be generated, measured and then kept or taken back and
generated again. This is the output-side counterpart of the parser mark and rewind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

* refactor(common-json): require every generator to support mark and rewind

The generator mark and rewind are declared without a default, as JsonGeneratorImpl is the one implementation
of JsonGeneratorEx and supports both.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

* test(common-json): rewind the generator that escapes its output

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

---------

Co-authored-by: Claude <[email protected]>

* test(binding-mqtt-kafka): specify per-filter suback failure for a filter no route matches

Failing scripts and ITs only, ahead of the production change for #3208:
mqtt-kafka echoes the stored session state with reasonCode 0x80 on each
filter no subscribe route matches, and the mqtt binding leaves such a
filter out of its session state and skips it on resume.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ

* test(binding-mqtt): carry the subscription flags of the unsubscribe-after-failed-filter scenario

The application scripts of subscribe.topic.filters.non.successful.unsubscribe
are shared by the v4 and v5 ITs, and a v3.1.1 SUBSCRIBE always requests the
retained messages to be sent, so the state they expect must carry the
SEND_RETAINED flag in both versions. Adds the session state builder that sets
the qos, flags and reason code of a filter together.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ

* fix(binding-mqtt-kafka): answer a filter that no route matches with a per-filter suback failure

The session factory marks each filter of the session state it echoes to the
mqtt binding, on a SUBSCRIBE and when the stored state is delivered at CONNECT,
with reason code 0x80 when no subscribe route authorized for the session
matches it. The mqtt binding carries the code into the SUBACK, opens no
subscribe stream for the filter, leaves it out of its session state and
skips it on resume, so the connection stays open and the other filters of the
SUBSCRIBE are delivered as usual. Nothing new is persisted.

Fixes #3208

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoW6JiEUeLJ93BQKGfQ

---------

Co-authored-by: Claude <[email protected]>
jfallows added a commit that referenced this pull request Nov 15, 2026
…own broker id (#3232)

* feat(common-json): mark and rewind the generator (#3214)

* feat(common-json): mark and rewind the generator

A generator can mark its position between writes and rewind to it, which discards the bytes written since and
restores the structural context, so a unit of output can be generated, measured and then kept or taken back and
generated again. This is the output-side counterpart of the parser mark and rewind.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

* refactor(common-json): require every generator to support mark and rewind

The generator mark and rewind are declared without a default, as JsonGeneratorImpl is the one implementation
of JsonGeneratorEx and supports both.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

* test(common-json): rewind the generator that escapes its output

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoUTvQwZM7nY1gjgnZJ

---------

Co-authored-by: Claude <[email protected]>

* test(binding-kafka): script the refresh before an unknown broker id is answered

A raw API request stream addressed to a non-zero broker id that the route's
table does not know triggers an immediate Metadata refresh, and is answered
with the existing reset only after that refresh has completed or failed.
There is no retry, even when the refreshed table now contains the id.

The network scripts for the unknown id now play a second Metadata exchange
before the reset. New paired scripts cover a refresh whose response lists the
id (still reset, no connection to that broker) and a refresh that fails
(the meta connection is aborted). The application pairs for the same two
scenarios carry the refreshed partitions on the meta stream.

The spec network and application ITs and the runtime IT gain one method per
scenario. The runtime scenarios fail against the current binding because it
never sends the second Metadata request.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVZT5Lb5aAUG57ioRa

* fix(binding-kafka): refresh the broker table before answering an unknown broker id

A raw API request stream addressed to a non-zero broker id that the route's
table does not know is no longer reset at once. It is held, the route's
Metadata refresh is triggered (the same metaFlush the fetch and produce
clients use), and the stream is reset with the existing reset only after
that refresh has completed or failed. There is no retry, so the answer to
that attempt is the reset even if the refreshed table now has the id, and
the caller's next request meets a fresh table.

KafkaClientRoute gains the reverse of its meta flush registry: a one-shot
completion callback that the meta client fires after a Metadata response has
rewritten the table and when its stream fails. Streams hitting the same
unknown id share one flush and are reset together; a route with no meta
stream resets at once. The same holds when a reconnect finds the id gone.
An unknown id gets no entry in clientsByAffinity.

Fixes #3213

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVZT5Lb5aAUG57ioRa

---------

Co-authored-by: Claude <[email protected]>
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.

2 participants