Skip to content

Preserve stored JSON in memory reads and MCP replies - #2064

Open
yorkhellen wants to merge 28 commits into
ClickHouse:mainfrom
yorkhellen:fix/mcp-user-payload
Open

yorkhellen wants to merge 28 commits into
ClickHouse:mainfrom
yorkhellen:fix/mcp-user-payload

Conversation

@yorkhellen

@yorkhellen yorkhellen commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #2063

Changelog category

Bug Fix

Changelog entry

Memory reads retain stored null and empty-object members. HTTP and MCP replies preserve caller payloads through response shaping and idempotency replay. Conditional-write read tokens remain valid across rolling builds.

Why

The native JSON projection omits members present in stored text. Recursive response shaping also removes diagnostic-named keys and meaningful empty values inside caller content. Read stored text and mark opaque payload boundaries so returned content matches written content.

Conditional writes keep the native-projection token both rolling builds accept. Stored content and approval attestations use the full canonical hash. Using a projected token for proposal approval would accept changes to omitted members that the reviewer never saw.

Scope and risk

  • Memory projections retain stored value text and native value_json for conditional-write tokens. Point lookups, bulk lookups and report citations use the same token input. The SQL analyzer corpus is regenerated.
  • Mark memory values, record content, conflict values, schemas, procedure fields, learnings, profile overrides, task brief/outcome, run metadata, knowledge metadata and conversation metadata as opaque.
  • Apply task payload boundaries to projected task.list dictionaries while retaining their wire schema and selected columns.
  • Preserve typed dictionary keys and marked payloads through diagnostic trimming, integer conversion and epoch cleanup, including annotated union containers.
  • Cache full HTTP-normalized results in both transports. MCP cache entries retain string encoding for large server version IDs so the preceding MCP build can replay them. Retries use the receiving transport's encoding.
  • Conditional set, update, update_by_id and move accept the read token or the full hash returned by writes. Definition promotion also accepts the read token. Proposal approval requires the complete canonical content hash.
  • The dashboard resolves a proposal's identity with memory.get_by_id, then reads its complete value and approval hash from memory.history scoped to that identity and memory_id. Identity scoping also works when the preceding build ignores the id filter.
  • The mixed-version gate checks review through either build, another identity's newer tombstone, omitted-member replacement refusal and fresh full-content attestation. Its event-view leg excludes that old build's hashless stub from hashed-copy repair while retaining the event assertions and the new build's repair proof.

Replies can be larger because meaningful caller content remains present. Conditional-write read tokens retain the native projection's limitation: changes confined to omitted members cannot be distinguished. A full write hash retains that limit when it equals the current projection token. Stored content and attestation hashes cover the complete value. Authorization, reviewer independence and tenant scoping remain enforced.

Compatibility, rollout and rollback

  • memory.history accepts an optional memory_id filter before the version limit. No operations are added or removed.
  • Caller payloads retain JSON types, empty values and epoch-like strings. MCP server version fields retain their string conversion.
  • Read content_sha256 tokens hash the native JSON projection when populated, else stored text, matching the preceding build. Conditional writes across builds use the token from a read. The preceding build can reject a full write hash when its projection differs.
  • Proposal clients send the full canonical hash from memory.history as approved_sha256. Either build can supply the complete reviewed value. Acceptance requests must reach an upgraded replica: the preceding build refuses a full hash when its native JSON projection omits members. Sending the projected hash would let an omitted-member replacement pass review.
  • Default MCP shaping omits empty server fields, including normalized null timestamps; HTTP and explain=true retain those null fields.
  • New writers store full normalized cache entries so a preceding HTTP reader returns null timestamps consistently. The cache retains diagnostic fields for retries with explain=true.
  • Operator steps: route proposal acceptance to upgraded replicas during a rolling upgrade. There is no migration, backfill or new setting.
  • Rollback restores the preceding response transformations and approval limitation; no stored memory data needs cleanup.
  • Public documentation will be updated after the next release. Architecture pages describe the token and rollout limits in this change.

Tests

The latest review repair was tested before the final main synchronization:

  • Complete dashboard suite: 3895 passed in 322 files. The unchanged component fails the new identity regression; the repaired component passes. Coverage includes more than 500 newer rows from other identities and invalid id lookup results.
  • Focused backend batch: 350 passed. History, reach and commit-review contract batch: 47 passed. Mixed-version gate unit batch: 15 passed.
  • Complete mixed-version gate: all three configured base legs pass. Both builds review full text and JSON beside another identity's tombstone. The upgraded build refuses an approval after an omitted member changes, then accepts a fresh full hash and records its attestation. The pinned preceding build refuses full JSON approval.
  • Real-server probe: all four text read/approve combinations accept; both JSON combinations with the upgraded approving build accept; both combinations with the preceding approving build refuse and retain the complete pending value.
  • Dashboard build, bundle budget, format, lint, type checks and generator checks pass.

After the final main synchronization, 523 focused backend tests and 22 dashboard approval tests pass. Format, lint, type checks, every generator check, the dashboard build and its bundle budget pass. The three complete mixed-version legs above were run before that final merge; they have not been repeated afterward.

Fresh independent review of 32c1ce9b7 approves the eight-file fixing delta and the inspected main-merge effects, with no verified P0–P3 findings. It independently passes 138 backend tests, 25 frontend tests, Go generation and reach-census checks. This is not a full-PR or merge-ready approval; final-head runtime behavior was not independently rerun.

The full backend unit and browser end-to-end suites were not rerun for this fixing pass. The new head's 17 hosted workflows report action_required, with no CI jobs executed. Hosted CI and human re-review remain pending.

AI assistance in the code

AI-generated (TRAE). The agent wrote the fix and regression tests and ran the checks listed above. Human review is pending.

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

Checklist

  • Local format, lint, type checks and focused tests pass.
  • Applicable generators run without drift.
  • Repair commits are signed off.
  • Synchronize with current main and rerun focused checks.
  • Hosted CI passes.
  • Fresh independent fixing-delta review completes on the current head.

Note

High Risk
Changes conditional-write semantics, proposal approval hashing, shared promotion admission, and HTTP response shaping across memory and transport—areas that affect data integrity and rolling upgrades.

Overview
Memory reads and writes now distinguish a rolling-upgrade read precondition token from full canonical content hashes. Reads return stored JSON (including null/empty-object members); content_sha256 on gets hashes the native JSON projection when present so N and N−1 agree for if_match_sha256, while history, attestations, and write responses use the complete value hash. Conditional set/update/move/promote accept either token.

HTTP/MCP responses preserve caller-owned JSON by marking memory values, metadata, and similar fields as opaque Payloads and reshaping only non-payload fields (integers, diagnostics). Idempotency replay applies per-request ignored-arg feedback to cached full bodies.

Proposal review in the dashboard resolves identity via memory.get_by_id, then loads the full proposed revision and approval hash from memory.history scoped with optional new memory_id (also in SDKs). Accept/reject uses the history hash so omitted-projection tokens cannot approve unseen changes.

Shared promotion/repair adds per-target leases, stricter saved-copy vs source checks, and embedding-worker proofs so stub recovery embeds the saved excerpt without altering the canonical copy or borrowing attestation.

CI mixed-version gate runs as a three-scenario matrix (previous commit, event-views build, lossy-promotion build) with new cross-build checks for content preconditions, proposal approval, and shared embedding repair.

Reviewed by Cursor Bugbot for commit 8162036. Bugbot is set up for automated code reviews on this repo. Configure here.

Stop response shaping at declared payload fields so diagnostic names and
empty values in stored content survive reads and idempotent replays.
Read stored JSON text because native JSON rendering omits null and empty
object members.

Add regression tests for payload boundaries, replay consistency and
stored-value roundtrips through HTTP and MCP.

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

vercel Bot commented Dec 3, 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 2:11am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 2:11am UTC

Request Review

Task list rows keep their dictionary contract while response shaping uses the task model's payload boundaries.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
@zlareb1 zlareb1 self-assigned this Dec 3, 2026

@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.

Stored text now supplies the memory value and its served hash. The MCP response models preserve marked payloads through normal replies and idempotency replays, while server diagnostics still trim. The added tests cover both reply channels, projected task rows, and a tags-only memory update.

@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.

Unit part 3 fails on the old memory projection assertion.

Comment thread server/memory/store/sql.py Resolved
Check the raw value projection and its version-write alias, and keep byte and hash round trips for hydrated rows.

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

@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 projection test checks the stored value, the version-write alias and the separate native JSON projection. The round-trip tests check the stored bytes and hash. The focused memory and MCP suite passes (113 tests).

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

@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 new response-shaping branches put server/operations/ below its CI coverage floor. Coverage job

Comment thread server/operations/payloads.py Resolved
Mark profile schemas, structured profiles, procedure metadata and learning
candidates as payloads so MCP encoding keeps their stored JSON values.
Cache the full handler result and encode each replay for its destination
transport and toolset.

Cover payload reads, cross-transport replay, audit rows and authenticated
assistant calls with regression tests. Assistant probes use the real
operation input models so accepted arguments reach the handler.

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

@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 new replay cache format needs to work with a replica running the previous build. Coverage from the previous head is recorded in the existing thread. The new head needs its own CI result.

Comment thread server/transport/mcp_outcome.py Resolved
Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Store large server integers as decimal strings in full MCP replay answers.
Older readers replay the cache without bigint encoding; storing numbers
loses precision when a JavaScript client parses the response.

Keep HTTP integer restoration and opaque payload values intact. Cover
the preceding reader's replay conversion at the safe integer boundary
and with large positive and negative versions.

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

@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 MCP cache preserves large version IDs for older MCP replicas. HTTP replay still exposes the raw zero date when a newer replica writes the cache and an older replica answers the retry.

Comment thread server/transport/http.py Resolved
Store the full result after epoch cleanup so an older HTTP replica replays the same timestamp. Keep payload boundaries through annotated containers and cover both reply channels and previous-build readers.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
An epoch string in a preceding writer's cache must produce the same default and explained reply as a fresh result.

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

Copy link
Copy Markdown
Contributor Author

@zlareb1 The requested fixes are pushed at cf32bc2, with details in the original threads:

  • c549aeb stores large server version IDs as strings for previous MCP readers.
  • ab20db2 covers plain Annotated and union container selection through both rendered MCP channels. payloads.py branch coverage is 100%; combined server/operations/ coverage is 96.36% against the unchanged 96% floor.
  • ab20db2 stores HTTP-normalized full cache entries. cf32bc2 normalizes preceding cache entries before MCP lean shaping, so retries match fresh replies while preserving caller payloads.

The final focused suite passes 236 tests with one environment skip. Format, lint, type and generator checks pass. Fresh independent review of the full diff found no code defects; hosted Actions still need maintainer approval. Please recheck this head.

@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.

Conditional writes can fail during a rolling upgrade even when the memory revision has not changed. Cover both directions of the read and write across builds.

Comment thread server/memory/store/sql.py Resolved

@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.

Pinned Biome rejects the same assertion in Chat.test.tsx on the PR merge and clean main. The check passes with the formatting repair. PR job · Main job · Repair #2107

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

@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 read token now agrees across builds for the original fixture. Proposal approval can still attest content the reviewer did not see. The shared embedding repair finding also still applies because the repair compares the shared projection with the full source value.

Comment thread server/memory/app/proposals.py Resolved
Projection tokens omit null and empty-object members and can approve a replacement the reviewer has not read. Read the complete proposal revision and hash through memory.history, and reject projection tokens during approval.

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

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 8f86f55. Configure here.

Comment thread frontend/src/views/admin/Proposals.tsx Resolved

@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.

Proposal approval now compares the full stored hash. The shared embedding repair still refuses an N-1 promotion whose native projection omitted fields. The bulk read and namespace report also return different hashes from point reads of the same row.

Comment thread server/memory/app/query.py Resolved
Comment thread server/memory/store/reads.py Resolved
Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
A newer tombstone from another identity can hide a pending proposal in
key-wide history. Filter both history reads by the proposal ID so the
dashboard reviews the complete value and hash from the selected revision.

Cover identity collisions, tenant and read scopes, target changes, missing
history and the dashboard request. Regenerate the optional SDK field and
the SQL analyzer corpus.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
The bulk projection omits native JSON and citation reads hash stored text,
so an unchanged object containing null or empty members gets a different
token from memory.get. Select the native projection and use the shared
token input while keeping complete values in responses.

Cover actual SELECT columns, authority heads, citation disclosure limits
and conditional writes through HTTP and across rolling builds.

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

@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.

Bulk reads and report citations now agree with the point-read token. The shared embedding repair still compares the preceding build’s projected promotion with the current build’s full source value. A promotion of a value with an omitted null member can still leave an embedding stub that repair rejects. Existing finding

@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.

GitHub reports a merge conflict with main in sdk/go/wire/models.gen.go. Please reconcile the Go wire models from the combined registry.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Match the saved copy against the complete source or its recorded native
projection. Carry the original source and candidate heads through the
provider call, then bind publication to the saved copy's hash. Verification
requires a current attestation of the complete value and an identical copy.

Serialize promotion, repair and demotion across models with a target lease.
Lock missing candidate scopes on Postgres, retain uncertain sends and keep
the retry stub when a cross-model fill is withheld.

Cover worker interleavings, cleanup cancellation and retries, Postgres
authority checks and an actual preceding-build promotion in the mixed gate.
Saved lineage cannot reveal historical edits confined to omitted fields.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Keep legacy projection recovery required on its pinned build and preserve full-copy compatibility for other bases. Answer the shared-vector version read in the retirement fixture.

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

@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.

Proposal review can fail when the dashboard and server are on different builds during a rolling upgrade.

Comment thread frontend/src/views/admin/Proposals.tsx Outdated
setReview({ proposal });
try {
const row = await getMemoryById(identity.org, proposal.memory_id);
const { rows } = await memoryHistory({ ...scope, agent: "*" }, proposal.memory_key, 1, proposal.memory_id);

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 — An older server ignores the new memory_id filter. With a newer tombstone for another identity sharing this key, limit 1 returns the tombstone and the dashboard makes the pending proposal unavailable. Approval can also reach an older server that compares the new full-value digest against its normalized value, rejecting valid JSON with explicit nulls. Preserve review across both build combinations and cover them in the rolling-upgrade test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zlareb1 Fixed the history lookup in 32c1ce9b7: the dashboard resolves the proposal's identity by id, then scopes history by agent, user and session before the one-row limit. The regression covers a preceding server ignoring memory_id, more than 500 newer rows from other identities, and another user's newer tombstone.

Full JSON acceptance must still reach an upgraded replica. The unchanged preceding server compares against its lossy native projection; sending that projected hash would allow an omitted-member replacement to pass review. The full hash remains required, and the architecture page and PR body state this rollout boundary.

All three complete mixed-version legs passed before the final main merge, including full text/JSON review through either reader, omitted-member replacement refusal, and fresh full-content attestation. After the merge, 523 backend tests and 22 dashboard approval tests passed; the complete matrix was not repeated on the final head. Hosted Actions still require approval.

Comment thread scripts/gates/mixed_version.py Resolved

@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 tunable constant test flags the worker approval bigint bound on the clean CI base and this merge. The same test passes with the existing bound fix. The mixed-version failure is separate. Failed job · Bound fix #2138.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Resolve the proposal identity before reading history so preceding builds cannot select another identity’s newer revision. Keep full-content approval binding and cover omitted-member replacements across builds.

The event-view base writes hashless stubs outside the hashed-copy repair proof. Retain its event checks and the new build’s hashed repair, and remove temporary container volumes on exit.

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

@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.

Scoping history by the proposal’s identity fixes the tombstone case. The event-view leg keeps its assertions and runs hashed-stub repair on the new build. The approval path across builds still needs a rollout path. The new mixed-version test expects the preceding server to reject the canonical hash for a proposal with null members. Keep that hash check and give clients a supported way to complete or safely defer the approval while both builds serve.

@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 isolation test cannot build the worker approval and enrollment requests on this run or on its clean base. The merged fix supplies those request fields and keeps the refusal assertion. PR job · Base job · Fix #2156

Read receipts record stored content separately from read precondition tokens. Proposal review uses identity-scoped history while retaining address navigation, rejection reasons and retries.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
The generated contracts include run.reliance and the proposal history revision filter. Run metadata retains its opaque payload marker, and read receipts retain their full-content hash binding.

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

@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 combined wire models retain the full-value hash binding. The proposal approval thread remains open. The rollout guide requires calls to reach an upgraded server, but the dashboard still sends them through its ordinary endpoint.

ap.add_argument(
"--base", default="", help="the N-1 revision (default: merge base with origin/main)"
"--base",
default="HEAD~1",

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.

P2 — Plain make test-mixed-version now compares a branch with its own previous commit. On a two-commit branch, a compatibility break in the first commit is present on both sides and the gate can miss it. Keep the documented merge-base default for local runs. CI already passes its tested base explicitly.

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.

Memory reads and MCP replies omit members of stored JSON

2 participants