Skip to content

Memory reads and approval hashes preserve complete JSON objects - #2224

Open
yorkhellen wants to merge 2 commits into
ClickHouse:mainfrom
yorkhellen:fix/full-content-review-baseline
Open

yorkhellen wants to merge 2 commits into
ClickHouse:mainfrom
yorkhellen:fix/full-content-review-baseline

Conversation

@yorkhellen

@yorkhellen yorkhellen commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Related: #2064
Related: #2063

Part of issue #2063: this repairs the persisted-object read and hash behavior. The MCP response shaping work remains in #2064; merging this prerequisite does not close the issue.

Remaining review requirement

The cross-build token requirement remains unresolved. Real HTTP requests against unchanged main d65505001 and this exact head confirm that an unchanged object can produce a token the other receiver rejects. The successful prototype probe uses a repaired baseline and does not satisfy this requirement. A change confined to the new receiver cannot change the untouched receiver's projection-hash comparison. Accepting the projection hash would not bind an attestation to omitted members.

Changelog category

  • Backward Incompatible Change

Changelog entry

Memory reads preserve null and empty object members from persisted JSON object text. Verification and proposal approval compare the hash of that complete value.

Why

Native JSON rendering omits null and empty object members. A caller can read {"keep":1} for stored {"keep":1,"omitted":null,"nested":{}}, while another replica verifies the complete object. This makes unchanged content fail verification or proposal approval across replicas.

Object text is authoritative when present. Native-only objects beside scalar import values remain readable. The version projection selects the qualified stored text column so the served-value alias cannot replace the bytes a version write carries.

Scope and risk

Three production files change: the memory SQL projection, the shared persisted-value decoder and refusal policy capture/admission. Regression tests cover point, ID and bulk reads, Verify/revoke, omitted-member edits, proposal approval, native-only imported content, stored byte preservation and snapshot refusal across the read upgrade. The generated SQL corpus changes with the projection.

Refusal hashes can name either persisted representation. Capture records both when their canonical hashes differ, and admission inspects both, preserving matches against existing projection-based policies and through rollback. This comparison distinguishes integers, booleans and floats even when Python considers their decoded objects equal.

Reading and parsing complete object text adds work proportional to its length; this change makes no performance claim. No migration or content rewrite is required.

Compatibility, rollout and rollback

  • Wire: operation and field names remain the same. For objects whose native rendering omits members, the returned value and content hash change to cover the complete persisted object. Callers must refresh previously read precondition tokens.
  • Merge dependency: merge this PR first, then synchronize Preserve stored JSON in memory reads and MCP replies #2064 with main and complete its dependent token changes and bidirectional gate before merging Preserve stored JSON in memory reads and MCP replies #2064. No separate release or deployment is required between the two merges.
  • Operator steps: no migration, backfill or new setting. An untouched previous verifier cannot validate a complete-content token. The successful two-build probe uses this repaired baseline and a candidate Preserve stored JSON in memory reads and MCP replies #2064 build; it does not establish compatibility with an untouched previous build.
  • Rollback: reverting restores projection-based reads. Complete-object tokens can then fail verification and approval; refresh reads after rollback. There are no new schema objects to remove.

This is a prerequisite for #2064, not completion of its remaining review threads. The dependent PR still needs the complete-content token rule and durable bidirectional gate cases against the repaired baseline. Public documentation will be updated after the repair is released.

Tests

  • Full affected unit files: 249 passed, 1 skipped because the ClickHouse-local binary is unavailable. The new decoder regressions fail four cases on untouched production code; snapshot refusal and numeric-type regressions fail both mixed directions before their repairs.
  • After syncing current main, eight complete affected unit files pass: 290 passed, 3 skipped. LOOM_ENV_FILE= make format lint typecheck passes, and the SQL corpus is regenerated on that baseline.
  • All six affected integration files and SQL analyzer tests: 52 passed, including twelve persisted-policy representation/type combinations and unrelated-content/user controls.
  • After syncing current main, all eight affected integration files and SQL analyzer tests pass: 62 passed, with no skips, on a private ClickHouse 26.10.4.207 and server from this head. The additional files cover proposal listing and update admission.
  • Two real servers from unchanged main d65505001 and exact head 7646bac888 execute 24 cross-build Verify/revoke requests for one unchanged object, covering point, by-ID and bulk reads and either writer. Twenty return HTTP 409 without changing the row version; four old-bulk reads provide the full hash that the new receiver accepts. Four new-receiver full-hash controls succeed.
  • Both history readers return the full value and hash. Old history followed by new approval decides one proposal. New history followed by old approval, and old history followed by old approval, decide none and leave the version unchanged. Keeping a request on one replica does not repair the old history/approval mismatch.
  • These requests capture expected compatibility failures; the probe's zero exit is not a compatibility pass.
  • With this repaired baseline and the candidate dependent build: all ten cross-version scenarios pass. Both directions attest and revoke complete objects, reject stale tokens after omitted-member edits, approve proposals after reading their complete current value, and refuse deleted snapshots.
  • Earlier independent review executes 380 passing checks with three skips. Subsequent untouched-build diagnosis and real HTTP requests confirm the unresolved P1 token requirement above. The earlier review does not establish compatibility or merge readiness.
  • Hosted workflows complete with seven successes and two failures. The CI workflow has 46 successful jobs and one failed integration job: 736 tests pass, one worklist-order fixture fails and 152 tests skip. The same assertion fails with the same order on the tested main run. Dependency review fails on missing snapshots; a rerun is refused for lack of repository admin rights. Postgres 16 and 18 storage jobs pass. These results do not resolve the token requirement.
  • The full repository suite has not run locally.

Reproduce the affected units with:

LOOM_ENV_FILE= .venv/bin/python -m pytest -q \
  tests/unit/test_full_object_value.py \
  tests/unit/test_version_row_value_bytes.py \
  tests/unit/test_memory_refusals.py \
  tests/unit/test_proposal_commit_review.py \
  tests/unit/test_proposals.py \
  tests/unit/test_memory_verify.py \
  tests/unit/test_proposals_listing.py \
  tests/unit/test_memory_metadata_contention.py

Against a private server and ClickHouse, reproduce the integration scope with:

.venv/bin/python -m pytest -q \
  tests/integration/test_full_object_value.py \
  tests/integration/test_memory_verify.py \
  tests/integration/test_proposals.py \
  tests/integration/test_proposal_independent_review.py \
  tests/integration/test_memory_refusal_policy.py \
  tests/integration/test_memory_refusal_capture_live_ch.py \
  tests/integration/test_proposals_listing.py \
  tests/integration/test_memory_metadata_contention.py \
  tests/analyzer

AI assistance in the code

  • AI-generated (TRAE): an agent wrote the production change and regression tests; validation runs and independent review are recorded separately. Human review is pending.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Final local checks and focused tests pass.
  • The SQL statement corpus is regenerated from its builders.
  • Commits are signed off.
  • Hosted CI and review complete before merging.

Read persisted object text before native JSON rendering so omitted members remain part of verification and approval. Preserve refusal matches against both persisted representations during upgrade and rollback.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
…view-baseline

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>

# Conflicts:
#	tests/analyzer/shapes.txt
@vercel

vercel Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 5, 2026 7:02am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 7:02am UTC

Request Review

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An unchanged object must keep a usable verification and proposal approval token while N-1 and N serve together.

# Object text preserves null and empty members. Imports may keep their object only
# in value_json beside a scalar value.
SERVED_VALUE = (
"if(isValidJSON(loom.memory.value) AND startsWith(trimLeft(loom.memory.value), '{'), "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1 — This projection changes the content hash for existing objects with null or empty members. A read on either build can return a token that the other build rejects for the same unchanged row. The compatibility notes reproduce the mismatch with the untouched previous build. Keep the token usable across the rollout and add a two-build test against that untouched baseline.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The dependency review fails because its missing-snapshot fallback includes Rust files that changed on main. Replaying the same failure without this PR reproduces it on the tested base and current main. The existing repair passes the replay against this PR’s tested merge. Failed job · Repair #2053

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The worklist order test reproduces the same reversed results on the clean CI base with no changes from this PR. Both rows can receive the same whole-second timestamp, so the tie breaks on the key. The fixture in #2235 gives the first row an explicit earlier timestamp. The same test passed three times on current main. Failed job · Merged fix

This branch has not been deployed

No deployments
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