mirror of
https://github.com/openai/codex.git
synced 2026-11-29 15:36:12 +00:00
Load local session pickers from the state DB first (#36378)
## What changed - Start local resume and fork picker listings from indexed state DB metadata, while preserving the existing store-backed behavior for remote workspaces. - Keep the selected listing mode across pagination and fall back to the normal local store listing when the initial state DB request returns no rows or fails. - Add coverage for pagination, fallback rendering, and selecting an indexed thread without validating its rollout file. GitOrigin-RevId: 9005fbe73134e261bc6dd3f588c4fff494bdeea0
This commit is contained in:
1 parent
2e32d95894
commit
d62353a312
3 files changed
+393
-84
No files matched your search
@@ -0,0 +1,100 @@
|
||||
use super::PageCursor;
|
||||
|
||||
/// Selects whether thread listing trusts indexed metadata or uses the store's normal behavior.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(super) enum PageLoadMode {
|
||||
/// Return only the store's indexed metadata without repairing it from rollout files.
|
||||
StateDbOnly,
|
||||
/// Use the store's normal listing behavior, which may include repair for local stores.
|
||||
StoreDefault,
|
||||
}
|
||||
|
||||
/// Tracks the current request and the cursor policy inherited by its next page.
|
||||
pub(super) struct PaginationState {
|
||||
pub(super) next_cursor: Option<PageCursor>,
|
||||
next_page_mode: PageLoadMode,
|
||||
pub(super) num_scanned_files: usize,
|
||||
pub(super) reached_scan_cap: bool,
|
||||
loading: LoadingState,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum LoadingState {
|
||||
Idle,
|
||||
Pending(PendingLoad),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(super) struct PendingLoad {
|
||||
request_token: usize,
|
||||
pub(super) search_token: Option<usize>,
|
||||
pub(super) mode: PageLoadMode,
|
||||
}
|
||||
|
||||
impl PaginationState {
|
||||
pub(super) fn new() -> Self {
|
||||
Self {
|
||||
next_cursor: None,
|
||||
next_page_mode: PageLoadMode::StoreDefault,
|
||||
num_scanned_files: 0,
|
||||
reached_scan_cap: false,
|
||||
loading: LoadingState::Idle,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reset(&mut self) {
|
||||
*self = Self::new();
|
||||
}
|
||||
|
||||
pub(super) fn start_load(
|
||||
&mut self,
|
||||
request_token: usize,
|
||||
search_token: Option<usize>,
|
||||
mode: PageLoadMode,
|
||||
) {
|
||||
self.loading = LoadingState::Pending(PendingLoad {
|
||||
request_token,
|
||||
search_token,
|
||||
mode,
|
||||
});
|
||||
}
|
||||
|
||||
/// Completes only the matching in-flight request, leaving newer requests untouched.
|
||||
pub(super) fn finish_load(&mut self, request_token: usize) -> Option<PendingLoad> {
|
||||
let LoadingState::Pending(pending) = self.loading else {
|
||||
return None;
|
||||
};
|
||||
if pending.request_token != request_token {
|
||||
return None;
|
||||
}
|
||||
self.loading = LoadingState::Idle;
|
||||
self.next_page_mode = pending.mode;
|
||||
Some(pending)
|
||||
}
|
||||
|
||||
/// Records a page cursor and accumulates scan progress across the current listing.
|
||||
pub(super) fn complete_page(
|
||||
&mut self,
|
||||
next_cursor: Option<PageCursor>,
|
||||
num_scanned_files: usize,
|
||||
reached_scan_cap: bool,
|
||||
) {
|
||||
self.next_cursor = next_cursor;
|
||||
self.num_scanned_files = self.num_scanned_files.saturating_add(num_scanned_files);
|
||||
self.reached_scan_cap |= reached_scan_cap;
|
||||
}
|
||||
|
||||
/// Returns the next cursor together with the listing mode that produced it.
|
||||
pub(super) fn next_page(&self) -> Option<(PageCursor, PageLoadMode)> {
|
||||
if self.is_loading() {
|
||||
return None;
|
||||
}
|
||||
self.next_cursor
|
||||
.clone()
|
||||
.map(|cursor| (cursor, self.next_page_mode))
|
||||
}
|
||||
|
||||
pub(super) fn is_loading(&self) -> bool {
|
||||
matches!(self.loading, LoadingState::Pending(_))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user