Skip to content

feat(unstable-v2): patch upsert _meta by top-level key - #2372

Draft
benbrandt wants to merge 1 commit into
mainfrom
feat/v2-meta-patches
Draft

benbrandt wants to merge 1 commit into
mainfrom
feat/v2-meta-patches

Conversation

@benbrandt

@benbrandt benbrandt commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

v2 upserts now apply a concrete top-level _meta as a key-level patch instead of replacing the whole stored object. This is the same three-state rule the update already applies to its own fields, one level down:

  • Omitted _meta leaves the stored metadata unchanged; null clears it.
  • An object patches by top-level key: omitted keys stay, a key set to null is removed, and any other value replaces that key whole. Nested objects are not merged, and _meta: {} changes nothing.

This adds the v2 Metadata Patches RFD, which covers motivation, replay rules, v1 compatibility, conformance cases, and an FAQ.

Why

Unlike the other patch fields, _meta has several independent writers. Replacing the whole object made each writer responsible for every other writer's keys:

Scope

The rule applies to the top-level _meta of:

  • tool_call_update, including a permission request's tool_call subject
  • terminal_update
  • user_message, agent_message, agent_thought
  • session_info_update, compaction_update
  • the draft-only subagent_update and session_message

Every other _meta field is unchanged, including plan_update and the session/update envelope's params._meta (the place for data about a single notification). v1 is unchanged.

Review notes

  • Replay now has to remove stale keys explicitly: set them to null, or send _meta: null and then the new object. The two-update form isn't atomic.
  • A key can no longer store a literal null. rawInput/rawOutput already make the same trade-off.
  • v1 unstable updates diverge. The v1 unstable session_message, subagent_update, and compaction_update still replace _meta whole. The subagents and compaction RFDs now say so.
  • apply_meta_update is new public API in the v2 module. It lets clients that store message, session-info, or compaction state reuse the rule.

A concrete top-level `_meta` on a v2 upsert replaced the whole stored
object, so every writer had to know every other writer's keys: Agents
lost keys sent on earlier reports, and a proxy adding one key erased
the Agent's metadata.

Apply the update's three-state rule one level down instead. Omitted
`_meta` leaves metadata unchanged and `null` clears it; an object
patches by top-level key, where omitted keys stay, a key set to `null`
is removed, and other values replace that key whole without merging.
This covers tool call, terminal, message, session info, compaction,
subagent, and session message upserts. Other `_meta` fields, including
`plan_update`, are unchanged, and so is v1.

Add the v2 Metadata Patches RFD, define the rule and its replay
requirements in the v2 extensibility docs, and update related guides,
RFDs, and schema descriptions. Add `apply_meta_update` and use it in
`ToolCallUpdate::apply_update` and `TerminalUpdate::apply_update`.

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.

1 participant