Preserve MCP resource origins across compaction (#39192)

## Why

Compaction can remove the tool-call events that associate an MCP app widget with
the tool, account, and URI needed to authorize later resource reads.

## What changed

- Store a bounded MCP resource-origin checkpoint with each compacted rollout.
- Restore the checkpoint when resuming a session so existing widgets remain
  readable after compaction and restart.
- Discard saved origins when rollback rewrites history across the compaction
  boundary, and reject oversized or invalid checkpoints during restoration.

## Testing

- Extend the app-server MCP resource-origin test to compact a paginated thread,
  continue the conversation, and read the original widgets before and after a
  restart.
- Verify rollback clears provenance that no longer matches retained history.

GitOrigin-RevId: 7f91c6202fe8d9be21c78dda42fa205937c44263
This commit is contained in:
jif authored and copyberry committed 2026-08-18 12:37:41 +00:00
1 parent 880f1135ea
commit a397079287
22 files changed
+254 -18

No files matched your search

+14 -2
View File
@@ -1224,8 +1224,20 @@ impl Session {
mcp_projection.config.prefix_mcp_tool_names,
));
for item in initial_history.get_rollout_items() {
if let RolloutItem::EventMsg(event) = item {
mcp_runtime.observe_event(event);
match item {
RolloutItem::Compacted(compacted) => {
if let Some(checkpoint) = &compacted.mcp_resource_origins {
mcp_runtime.restore_resource_origin_checkpoint(checkpoint);
}
}
RolloutItem::EventMsg(event) => mcp_runtime.observe_event(event),
RolloutItem::SessionMeta(_)
| RolloutItem::ResponseItem(_)
| RolloutItem::InterAgentCommunication(_)
| RolloutItem::InterAgentCommunicationMetadata { .. }
| RolloutItem::TurnContext(_)
| RolloutItem::WorldState(_)
| RolloutItem::SecurityRiskScore(_) => {}
}
}
let session_extension_data =