Preserve model-facing ID allocations in saved history (#60771)

## Why

Restoring model-facing ID sequences requires allocation ordinals alongside the rendered IDs. Responses API payloads still require string IDs.

## What changed

- Add allocation metadata to `ResponseItemId` while keeping equality, hashing, and ordering based on the rendered ID.
- Preserve optional `id_allocation` metadata in rollout items, inter-agent messages, compaction replacement history, and Guardian checkpoints. Continue accepting legacy string IDs.
- Support structured context-window allocations alongside UUIDv7 strings, validate the `window` salt on restoration, and keep request metadata IDs as strings.

## Testing

Add tests for allocation round trips, legacy ID compatibility, string-only raw response item IDs, and context-window allocation validation.

GitOrigin-RevId: ce1fd964bde9a4e7c527432be99aea87ada30169
This commit is contained in:
Ruslan Nigmatullin
2026-11-11 09:58:13 +00:00
committed by copyberry
parent 32234ddac4
commit 340a18ed7c
15 changed files with 450 additions and 85 deletions
+4 -2
View File
@@ -61,6 +61,7 @@ use crate::plan_tool::UpdatePlanArgs;
use crate::request_permissions::RequestPermissionsEvent;
use crate::request_permissions::RequestPermissionsResponse;
use crate::request_user_input::RequestUserInputResponse;
use crate::response_item_id::OptionalWireItemId;
use crate::turn_input::CyberAccessProgram;
use crate::turn_input::SuspendTurnOutcome;
use crate::turn_input::TurnInputMode;
@@ -994,7 +995,8 @@ impl FromStr for ThreadHistoryMode {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema, TS)]
pub struct InterAgentCommunication {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
#[serde(with = "OptionalWireItemId")]
#[ts(optional, as = "Option<ResponseItemId>")]
pub id: Option<ResponseItemId>,
pub author: AgentPath,
pub recipient: AgentPath,
@@ -3450,7 +3452,7 @@ pub enum MultiAgentVersion {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct SessionContextWindow {
/// UUIDv7 identity of this context window.
/// Persisted model-facing window identity.
pub window_id: crate::ContextWindowId,
}