Enable paginated thread history in app-server (#33364)

## What changed

- Allow `thread/start` to select experimental `historyMode: "paginated"` when the thread store supports turn and item pagination.
- Resume paginated threads with bounded model context and require `excludeTurns: true` instead of loading full history.
- Return `turnsBackwardsCursor` and `itemsBackwardsCursor` from `thread/resume` so clients can hydrate durable history through `thread/turns/list` and `thread/items/list` while newer records arrive through live notifications.
- Reject operations that still require full history, including `initialTurnsPage`, `thread/read` with `includeTurns: true`, `thread/rollback`, and detached review.
- Make item cursors independent of the optional `turnId` filter.

## Testing

- Cover paginated thread start, cold and live resume, backwards cursor hydration, metadata reads, unsupported operations, and stores without pagination support.

GitOrigin-RevId: c42f9b268e29d049843330f474fa3ecde12f5b8a
This commit is contained in:
Owen Lin authored and copyberry committed 2026-07-15 15:29:13 +00:00
1 parent 1bbdb32789
commit da61f7d8e1
26 files changed
+758 -138

No files matched your search

@@ -219,6 +219,8 @@ fn thread_resume_response_round_trips_initial_turns_page() {
next_cursor: Some("cursor_next".to_string()),
backwards_cursor: Some("cursor_back".to_string()),
}),
turns_backwards_cursor: Some("turns_head".to_string()),
items_backwards_cursor: Some("items_head".to_string()),
};
let value = serde_json::to_value(&response).expect("serialize thread resume response");
@@ -230,6 +232,14 @@ fn thread_resume_response_round_trips_initial_turns_page() {
"backwardsCursor": "cursor_back",
}))
);
assert_eq!(
value.get("turnsBackwardsCursor"),
Some(&json!("turns_head"))
);
assert_eq!(
value.get("itemsBackwardsCursor"),
Some(&json!("items_head"))
);
let decoded = serde_json::from_value::<ThreadResumeResponse>(value)
.expect("deserialize thread resume response");
assert_eq!(decoded, response);
@@ -435,6 +435,20 @@ pub struct ThreadResumeResponse {
#[experimental("thread/resume.initialTurnsPage")]
#[serde(default)]
pub initial_turns_page: Option<TurnsPage>,
/// Opaque head cursor for hydrating paginated turns backwards.
///
/// Pass this as `cursor` to `thread/turns/list` with
/// `sortDirection: "desc"`. The first page includes the cursor's head turn.
#[experimental("thread/resume.turnsBackwardsCursor")]
#[serde(default)]
pub turns_backwards_cursor: Option<String>,
/// Opaque head cursor for hydrating paginated items backwards.
///
/// Pass this as `cursor` to `thread/items/list` with
/// `sortDirection: "desc"`. The first page includes the cursor's head item.
#[experimental("thread/resume.itemsBackwardsCursor")]
#[serde(default)]
pub items_backwards_cursor: Option<String>,
}
impl ThreadResumeResponse {