Include context window IDs in response metadata (#39847)

## What changed

- Add `context_window_id` to turn metadata for sampling and compaction requests, using the UUID for the model-visible context window.
- Keep the ID stable for requests in the same context window and advance it after compaction, independently of the existing thread-generation `window_id`.
- Reserve `context_window_id` so client metadata cannot override it.

## Testing

- Cover HTTP and WebSocket metadata, remote compaction, token-budget context alignment, resume behavior, and post-compaction window changes.

GitOrigin-RevId: 55cceea377ad509c8dd96ad668f2b5703ea46a63
This commit is contained in:
Brandon Zhang authored and copyberry committed 2026-08-21 03:31:56 +00:00
1 parent bd19459358
commit 27c05a52e0
14 files changed
+151 -32

No files matched your search

+6 -1
View File
@@ -3769,10 +3769,15 @@ impl Session {
}
pub(crate) async fn current_window_id(&self) -> String {
self.current_window().await.0
}
pub(crate) async fn current_window(&self) -> (String, Uuid) {
let state = self.state.lock().await;
let thread_id = self.thread_id;
let window_number = state.auto_compact_window_number();
format!("{thread_id}:{window_number}")
let context_window_id = state.auto_compact_window_ids().window_id;
(format!("{thread_id}:{window_number}"), context_window_id)
}
pub(crate) async fn advance_auto_compact_window(&self) -> (u64, AutoCompactWindowIds) {