Skip to content

fix(#5863): decouple @props type hint emission from includeMetadata in map2json - #5980

Merged
lvca merged 2 commits into
mainfrom
fix/5863-5952-props-typehint-map2json
Aug 9, 2026
Merged

lvca merged 2 commits into
mainfrom
fix/5863-5952-props-typehint-map2json

Conversation

@lvca

@lvca lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member

Description

map2json was using the includeMetadata parameter to decide whether to emit the @props per-column JSON type-hint string. This bundled @props into every toJSON(true) call, including the WebSocketEventBus/ChangeEvent broadcast path where no consumer can opt in to receiving it (and, incidentally, the Redis and Postgres wire-protocol paths, which call record.toJSON(true) too).

The WebSocketEventBus calls record.toJSON(true) once per change event and broadcasts the resulting JSON string to every connected subscriber. There is no per-subscriber request to key an opt-in off of, so every subscriber got @props on any property whose type is lossy through JSON (SHORT, FLOAT, LONG, temporals, ...) and isn't declared in the schema.

Fix

Mirrors the #5860 fix for serializeResult:

  • map2json now uses the serializer-level includeTypeHints field (off by default) instead of the includeMetadata parameter to decide whether to emit @props.
  • includeMetadata keeps its original meaning: "include @rid/@type/@cat/@in/@out" identity metadata only (unchanged, still handled by the MutableDocument/ImmutableDocument/DetachedDocument wrappers).
  • The @props hint is now emitted only when the caller explicitly enables it via JsonSerializer.setIncludeTypeHints(true).

Regression proof

Reverting just the JsonSerializer.java change reproduces the exact leak reported in #5863 - the new ChangeEventTest fails with:

"record":{"dynamicLong":99,"@props":"dynamicLong:3","@cat":"d","@type":"Doc","@rid":"#1:0"}

Tests

  • JsonSerializerTest#map2jsonPropsHintOffByDefaultForSchemalessLossyProperty - pins the off-by-default behavior at the Document.toJSON(true) API level (mirrors propsHintOffByDefault from fix(#5812): make the @props JSON type hint opt-in, off by default #5860).
  • ChangeEventTest#changeEventNeverEmitsPropsHint (new file) - asserts a broadcast ChangeEvent payload never contains @props, exercising ChangeEvent/WebSocketEventBus directly with no HTTP server needed.
  • Ran JsonSerializerTest, JSONSerializerTest, WebSocketEventBusIT, Issue5024WebSocketEventBusConcurrencyTest, and the full redisw/postgresw module test suites (all green) plus a full reactor compile.

Note on #5952

This supersedes #5952 (same fix, opened by @waterWang, thank you for the report and initial patch). That PR's CI failures were unrelated to its one-line change: claude-review failed on an OIDC-token permission limitation for fork PRs, unit-tests hit a pre-existing stale-assertion bug in RangeFunctionTest that was fixed on main by #5954 minutes after that PR's CI ran, and integration-tests/ha-integration-tests/coverage-report match known chronic CI flakes unrelated to this change. This PR adds the test coverage #5952 was missing and confirms the fix against current main.

Closes #5863

…n map2json

map2json used the includeMetadata parameter to decide whether to emit the
@props type-hint string. This bundled @props into every toJSON(true) call,
including the WebSocket ChangeEvent broadcast path (and the Redis/Postgres
wire-protocol paths, which hit the same map2json call) where no consumer can
opt in to receiving it.

Mirror the #5860 fix for serializeResult: map2json now gates @props on the
serializer-level includeTypeHints field (off by default) instead of
includeMetadata, which keeps its original meaning of "include
@rid/@type/@cat/@in/@out" identity metadata only.

Adds a regression test pinning the off-by-default behavior at the Document
API level (mirroring propsHintOffByDefault from #5860) and a ChangeEvent
test asserting a broadcast payload never contains @props.
@mergify

mergify Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@claude

claude Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review

This is a well-scoped fix. I traced every caller of map2json / Document.toJSON(true) (MutableDocument, ImmutableDocument, DetachedDocument, ChangeEvent/WebSocketEventBus, RedisNetworkExecutor, PostgresType, ResultInternal) to confirm the behavior change is scoped correctly.

Correctness

  • The core fix (includeMetadata → includeTypeHints for gating @props in map2json) is correct and consistent with the prior #5860 fix for serializeResult. includeMetadata's original meaning ("include @rid/@type/@cat") is preserved intact - it's applied separately in MutableDocument#toJSON/ImmutableDocument#toJSON/DetachedDocument#toJSON after map2json returns, so that part of the contract is unaffected.
  • Confirmed RemoteDatabase's Java driver (the one legitimate consumer of the old exhaustive @props hint) opts in via the typeHints HTTP request parameter, which flows into serializeResult, not map2json - so this change doesn't regress the driver's own type-fidelity needs.
  • Redis (RedisNetworkExecutor), Postgres (PostgresType), and the WebSocket ChangeEvent broadcast path all call record.toJSON(true) with no opt-in mechanism for @props - exactly the leak paths described in the PR body - and all now correctly get plain JSON.

Test coverage

  • JsonSerializerTest#map2jsonPropsHintOffByDefaultForSchemalessLossyProperty correctly pins the off-by-default behavior at the Document.toJSON(true) API surface using a schemaless LONG property (a lossy-through-JSON type), mirroring the existing propsHintOffByDefault test for serializeResult.
  • The new ChangeEventTest is a good regression test: it exercises ChangeEvent/WebSocketEventBus directly without spinning up an HTTP/WebSocket server, keeping it fast, and the PR description notes it fails with the exact reported leak when the one-line fix is reverted - solid proof the test actually catches the regression.
  • @BeforeEach/@AfterEach correctly drop the database and close the factory; using UUID in the path avoids collisions with parallel test runs.

Minor / non-blocking observations

  • In map2json, the length check stayed as propertyTypes.length() > 0 while the equivalent code in serializeResult (a few lines above) was already migrated to !propertyTypes.isEmpty(). Not a bug, just a small inconsistency in the same file - could be unified in a follow-up but not worth blocking on.
  • No behavior changes needed for security or performance; if anything, this reduces payload size for the (much more common) default case and removes a data-exposure surface, which is a net performance and security win.

Nothing else stood out. I wasn't able to execute mvn test in this sandboxed environment to independently re-run the suite (build tooling requires interactive approval not available here), so I verified correctness by static tracing of all callers instead; the PR description's own test run summary (JsonSerializerTest, JSONSerializerTest, WebSocketEventBusIT, Issue5024WebSocketEventBusConcurrencyTest, full redisw/postgresw suites, full reactor compile) looks appropriately thorough for the blast radius of this change.

Nice catch tracing this back through #5860/#5952 and writing a regression test that reproduces the exact reported payload.

…p2json

Per code-review on #5980: serializeResult already migrated to
!propertyTypes.isEmpty(), map2json still used the older length() > 0 form.
No behavior change.
@claude

claude Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review

Solid, well-scoped fix that mirrors the established serializeResult pattern from #5860. I traced the change end-to-end (not just the diff) and it holds up.

Correctness

  • map2json now gates @props on includeTypeHints (default false) instead of includeMetadata, matching serializeResult's existing gating. includeMetadata retains its original, narrower meaning (@rid/@type/@cat/@in/@out), which is still handled separately in setMetadata()/the Remote*Document wrappers - no accidental scope creep there.
  • I checked every producer/consumer of @props (Property.PROPERTY_TYPES_PROPERTY) in the tree, and specifically stress-tested the one path that worried me: does RemoteDatabase's document-save path lose type fidelity now that map2json no longer emits @props by default?
    • RemoteMutableDocument.toJSON(true) still calls map2json, but RemoteDatabase.saveRecord() doesn't POST that JSON as a raw document body - it embeds it as literal text in a SQL command ("insert into " + type + " content " + json), sent via command("sql", ...). That content <json> clause is parsed server-side through SQLASTBuilder.visitJson → Json.toMap() → UpdateContentStep.handleContent → doc.fromMap(...), none of which reads @props - it never did, before or after this PR.
    • Separately, RemoteHttpComponent.executeOperation always sends typeHints: true on every command/query request, so the server's response to that same insert/update is still serialized with includeTypeHints=true regardless of this change. That's the actual mechanism RemoteImmutableDocument.parsePropertyTypes relies on to rebuild exact Java types on the client, and it's untouched here.
    • Net: no type-fidelity regression on the remote save/round-trip path.
  • The Redis/Postgres/WebSocket toJSON(true) call sites called out in the description are confirmed to be the only non-query-result producers of includeMetadata=true, so the fix closes the leak at its actual source.

Tests

  • map2jsonPropsHintOffByDefaultForSchemalessLossyProperty correctly pins the behavior at the public Document.toJSON(true) API level (not just map2json directly), which is the right altitude since that's what every real caller uses.
  • ChangeEventTest is a nice, minimal regression test - exercises ChangeEvent/WebSocketEventBus without spinning up an HTTP server, and follows the same setup/teardown shape as the existing sibling Issue5024WebSocketEventBusConcurrencyTest in the same package (consistent style, DB path correctly rooted under target/, so it won't trip the repo's check-test-database-paths.sh guard).
  • The regression proof in the description (reverting just the JsonSerializer.java hunk reproduces the exact leaked payload from @props type hint still leaks unconditionally via Document.toJSON(true) / WebSocket change events #5863) is a good sanity check to include.

Style

  • The second commit (length() > 0 → !propertyTypes.isEmpty()) is a no-op cleanup for consistency with serializeResult - fine as a fast-follow, no behavior change.

Minor notes (non-blocking)

  • After this change, @props is effectively unreachable for embedded documents serialized via map2json's convertToJSONType → document.toJSON(true) (~line 457), since that always builds a fresh default JsonSerializer with includeTypeHints=false. That looks intentional/consistent with the rest of the fix, and I didn't find any caller depending on type hints surviving through nested embedded docs, but worth keeping in mind if that ever becomes a requirement.
  • Nice touch superseding fix(#5863): decouple @props type hint emission from includeMetadata in map2json #5952 with the same one-line fix plus the missing test coverage, and documenting why that PR's CI failures were unrelated.

Overall: low risk, good test coverage, no regressions found in the paths that matter (remote save/round-trip, Redis/Postgres wire protocols, WebSocket broadcast). LGTM.

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.

@props type hint still leaks unconditionally via Document.toJSON(true) / WebSocket change events

1 participant