mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
Keep Cloud threads current in the Agents overview (#62858)
## Why The Agents overview can go stale when Cloud threads change from another client, especially when the TUI has no conversation stream attached. ## What changed - Use Cloud stream notifications to update thread status and refresh the thread list. Poll every 10 seconds while the overview is visible and no stream is attached. - Refresh the history already shown while preserving the `Show more` cursor. Use fresh list metadata for thread names, recency, and unread state, and restore rows when a refresh catches a missed unarchive. ## Testing Cover Cloud inventory notifications, polling while detached, pagination across refreshes, and recovery from a missed unarchive. GitOrigin-RevId: 63c98438b6ddd2e47dd2d1f419c2a676508c6d91
This commit is contained in:
committed by
copyberry
parent
941e1dcade
commit
beac2ef8fc
@@ -21,6 +21,8 @@ use std::sync::Arc;
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::MutexGuard;
|
use std::sync::MutexGuard;
|
||||||
use std::sync::PoisonError;
|
use std::sync::PoisonError;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
@@ -121,6 +123,7 @@ pub(super) enum IdleReconnect {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CloudRequestHandle {
|
pub struct CloudRequestHandle {
|
||||||
pub(super) reconnect: tokio::sync::watch::Sender<IdleReconnect>,
|
pub(super) reconnect: tokio::sync::watch::Sender<IdleReconnect>,
|
||||||
|
pub(super) attached: Arc<AtomicBool>,
|
||||||
commands: mpsc::Sender<CloudCommand>,
|
commands: mpsc::Sender<CloudCommand>,
|
||||||
native: Option<Arc<codex_cloud_client::Client>>,
|
native: Option<Arc<codex_cloud_client::Client>>,
|
||||||
title_client: Option<Arc<CloudTitleClient>>,
|
title_client: Option<Arc<CloudTitleClient>>,
|
||||||
@@ -209,6 +212,7 @@ impl CloudClient {
|
|||||||
handle: CloudRequestHandle {
|
handle: CloudRequestHandle {
|
||||||
commands,
|
commands,
|
||||||
reconnect: Default::default(),
|
reconnect: Default::default(),
|
||||||
|
attached: Default::default(),
|
||||||
native: native.map(Arc::new),
|
native: native.map(Arc::new),
|
||||||
title_client: title_client.map(Arc::new),
|
title_client: title_client.map(Arc::new),
|
||||||
},
|
},
|
||||||
@@ -281,6 +285,11 @@ impl CloudClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CloudRequestHandle {
|
impl CloudRequestHandle {
|
||||||
|
/// Whether the worker has an installed reply stream that can deliver inventory updates.
|
||||||
|
pub fn has_attachment(&self) -> bool {
|
||||||
|
self.attached.load(Ordering::Relaxed) && !self.commands.is_closed()
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate metadata with Cloud's own account, outside its conversation command queue.
|
/// Generate metadata with Cloud's own account, outside its conversation command queue.
|
||||||
pub async fn generate_thread_title(
|
pub async fn generate_thread_title(
|
||||||
&self,
|
&self,
|
||||||
@@ -462,6 +471,7 @@ impl CloudRequestHandle {
|
|||||||
Self {
|
Self {
|
||||||
commands,
|
commands,
|
||||||
reconnect: self.reconnect.clone(),
|
reconnect: self.reconnect.clone(),
|
||||||
|
attached: self.attached.clone(),
|
||||||
native: None,
|
native: None,
|
||||||
title_client: None,
|
title_client: None,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -837,8 +837,12 @@ async fn prepared_resume_keeps_the_previous_stream_until_handoff() -> Result<()>
|
|||||||
if outcome == "burst" {
|
if outcome == "burst" {
|
||||||
// One partial-history warning plus the entire live burst, including its unread tail.
|
// One partial-history warning plus the entire live burst, including its unread tail.
|
||||||
for _ in 0..PREPARED_EVENT_LIMIT + 2 {
|
for _ in 0..PREPARED_EVENT_LIMIT + 2 {
|
||||||
|
let mut event = client.next_event().await;
|
||||||
|
while matches!(event, Some(AppServerEvent::CloudInventoryChanged(Some(_)))) {
|
||||||
|
event = client.next_event().await;
|
||||||
|
}
|
||||||
assert!(
|
assert!(
|
||||||
matches!(client.next_event().await, Some(AppServerEvent::ServerNotification(notification))
|
matches!(event, Some(AppServerEvent::ServerNotification(notification))
|
||||||
if matches!(*notification, protocol::ServerNotification::Warning(_)))
|
if matches!(*notification, protocol::ServerNotification::Warning(_)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -982,12 +986,20 @@ async fn accepted_idle_reconnect_reports_changed_login() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn attachment_status_follows_its_server_notifications() -> Result<()> {
|
async fn attachment_tracks_its_status_and_reports_account_inventory_changes() -> Result<()> {
|
||||||
let (output, mut events) = mpsc::unbounded_channel();
|
let (output, mut events) = mpsc::unbounded_channel();
|
||||||
let mut replies = Replies::default();
|
let (client, _commands, _events) = CloudClient::channel(/*capacity*/ 1);
|
||||||
let notifications: [&[u8]; 3] = [
|
let handle = client.request_handle();
|
||||||
|
let mut replies = Replies {
|
||||||
|
attached: handle.attached.clone(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let notifications: [&[u8]; 6] = [
|
||||||
b"\x1a\x0d\x12\x0b\x0a\x06\x22\x04\x0a\x02\x08\x01\x12\x01t", // t is waiting
|
b"\x1a\x0d\x12\x0b\x0a\x06\x22\x04\x0a\x02\x08\x01\x12\x01t", // t is waiting
|
||||||
|
b"\xaa\x01\x0c\x12\x0a\x0a\x01x\x12\x05\x22\x01u\x40\x04", // x starts a turn
|
||||||
b"\x1a\x09\x12\x07\x0a\x02\x12\x00\x12\x01x", // x is idle
|
b"\x1a\x09\x12\x07\x0a\x02\x12\x00\x12\x01x", // x is idle
|
||||||
|
b"\x22\x05\x12\x03\x0a\x01x", // x is archived
|
||||||
|
b"\x32\x05\x12\x03\x0a\x01x", // x is unarchived
|
||||||
b"\x1a\x09\x12\x07\x0a\x02\x12\x00\x12\x01t", // t is idle
|
b"\x1a\x09\x12\x07\x0a\x02\x12\x00\x12\x01t", // t is idle
|
||||||
];
|
];
|
||||||
let stream = stream::iter(
|
let stream = stream::iter(
|
||||||
@@ -1007,13 +1019,27 @@ async fn attachment_status_follows_its_server_notifications() -> Result<()> {
|
|||||||
let waiting = cloud::ThreadStatus::Active {
|
let waiting = cloud::ThreadStatus::Active {
|
||||||
active_flags: vec![cloud::ThreadActiveFlag::WaitingOnApproval],
|
active_flags: vec![cloud::ThreadActiveFlag::WaitingOnApproval],
|
||||||
};
|
};
|
||||||
assert_eq!(replies.thread_status("t"), Some(&waiting));
|
let waiting = serde_json::json!(waiting);
|
||||||
replies.forward_next(&output).await;
|
let status_change = |status: &Value| serde_json::json!({"method": "thread/status/changed", "params": {"threadId": "t", "status": status}});
|
||||||
assert_eq!(replies.thread_status("t"), Some(&waiting));
|
for expected in [
|
||||||
|
status_change(&waiting),
|
||||||
|
Value::Null,
|
||||||
|
Value::Null,
|
||||||
|
serde_json::json!({"method": "thread/archived", "params": {"threadId": "x"}}),
|
||||||
|
serde_json::json!({"method": "thread/unarchived", "params": {"threadId": "x"}}),
|
||||||
|
status_change(&serde_json::json!(cloud::ThreadStatus::Idle)),
|
||||||
|
] {
|
||||||
|
let AppServerEvent::CloudInventoryChanged(lifecycle) = events.try_recv()? else {
|
||||||
|
panic!("expected inventory change");
|
||||||
|
};
|
||||||
|
assert_eq!(serde_json::to_value(lifecycle)?, expected);
|
||||||
|
let status = expected.pointer("/params/status").unwrap_or(&waiting);
|
||||||
|
assert_eq!(&serde_json::to_value(replies.thread_status("t"))?, status);
|
||||||
|
assert!(handle.has_attachment());
|
||||||
|
replies.forward_next(&output).await;
|
||||||
|
}
|
||||||
|
|
||||||
replies.forward_next(&output).await;
|
assert!(!handle.has_attachment());
|
||||||
assert_eq!(replies.thread_status("t"), Some(&cloud::ThreadStatus::Idle));
|
|
||||||
replies.forward_next(&output).await;
|
|
||||||
assert_eq!(replies.thread_status("t"), Some(&cloud::ThreadStatus::Idle));
|
assert_eq!(replies.thread_status("t"), Some(&cloud::ThreadStatus::Idle));
|
||||||
let AppServerEvent::ThreadStreamDisconnected(error) = events.try_recv()? else {
|
let AppServerEvent::ThreadStreamDisconnected(error) = events.try_recv()? else {
|
||||||
panic!("expected a Cloud stream loss");
|
panic!("expected a Cloud stream loss");
|
||||||
@@ -1030,5 +1056,8 @@ async fn attachment_status_follows_its_server_notifications() -> Result<()> {
|
|||||||
.replace("t", async { Ok(stream::pending().boxed()) }, &output)
|
.replace("t", async { Ok(stream::pending().boxed()) }, &output)
|
||||||
.await?;
|
.await?;
|
||||||
assert_eq!(replies.thread_status("t"), None);
|
assert_eq!(replies.thread_status("t"), None);
|
||||||
|
assert!(handle.has_attachment());
|
||||||
|
replies.detach("t");
|
||||||
|
assert!(!handle.has_attachment());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ use futures::StreamExt;
|
|||||||
use futures::stream::BoxStream;
|
use futures::stream::BoxStream;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
@@ -70,6 +72,7 @@ struct Attachment {
|
|||||||
struct Replies {
|
struct Replies {
|
||||||
idle: Option<idle::Recovery>,
|
idle: Option<idle::Recovery>,
|
||||||
active: Option<Attachment>,
|
active: Option<Attachment>,
|
||||||
|
attached: Arc<AtomicBool>,
|
||||||
generation: u64,
|
generation: u64,
|
||||||
stream_losses: CloudStreamLosses,
|
stream_losses: CloudStreamLosses,
|
||||||
// Keep the last observed status through EOF until this conversation is unloaded.
|
// Keep the last observed status through EOF until this conversation is unloaded.
|
||||||
@@ -77,6 +80,12 @@ struct Replies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Replies {
|
impl Replies {
|
||||||
|
fn set_active(&mut self, active: Option<Attachment>) {
|
||||||
|
self.active = active;
|
||||||
|
self.attached
|
||||||
|
.store(self.active.is_some(), Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
async fn next_event(&mut self, output: &mpsc::UnboundedSender<AppServerEvent>) {
|
async fn next_event(&mut self, output: &mpsc::UnboundedSender<AppServerEvent>) {
|
||||||
if let Some(recovery) = &mut self.idle
|
if let Some(recovery) = &mut self.idle
|
||||||
&& let Some((root, _, open)) = &mut recovery.held
|
&& let Some((root, _, open)) = &mut recovery.held
|
||||||
@@ -158,7 +167,7 @@ impl Replies {
|
|||||||
ended => {
|
ended => {
|
||||||
let id = active.thread_id.clone();
|
let id = active.thread_id.clone();
|
||||||
let error = ended.and_then(Result::err);
|
let error = ended.and_then(Result::err);
|
||||||
self.active = None;
|
self.set_active(/*active*/ None);
|
||||||
if let Some(recovery) = &mut self.idle {
|
if let Some(recovery) = &mut self.idle {
|
||||||
recovery
|
recovery
|
||||||
.state
|
.state
|
||||||
@@ -259,10 +268,10 @@ impl Replies {
|
|||||||
output: &mpsc::UnboundedSender<AppServerEvent>,
|
output: &mpsc::UnboundedSender<AppServerEvent>,
|
||||||
) {
|
) {
|
||||||
self.generation = self.generation.wrapping_add(1);
|
self.generation = self.generation.wrapping_add(1);
|
||||||
self.active = Some(Attachment {
|
self.set_active(Some(Attachment {
|
||||||
thread_id: id.to_owned(),
|
thread_id: id.to_owned(),
|
||||||
stream,
|
stream,
|
||||||
});
|
}));
|
||||||
if let Some(event) = first_event {
|
if let Some(event) = first_event {
|
||||||
forward(
|
forward(
|
||||||
id,
|
id,
|
||||||
@@ -303,7 +312,7 @@ impl Replies {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|active| active.thread_id == id)
|
.is_some_and(|active| active.thread_id == id)
|
||||||
{
|
{
|
||||||
self.active = None;
|
self.set_active(/*active*/ None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,12 +359,10 @@ fn start_worker(
|
|||||||
loaded: None,
|
loaded: None,
|
||||||
warned_partial_history: None,
|
warned_partial_history: None,
|
||||||
};
|
};
|
||||||
|
let handle = app_client.request_handle();
|
||||||
let mut replies = Replies {
|
let mut replies = Replies {
|
||||||
idle: Some(idle::Recovery::new(
|
attached: handle.attached,
|
||||||
app_client.request_handle().reconnect,
|
idle: Some(idle::Recovery::new(handle.reconnect, client, login)),
|
||||||
client,
|
|
||||||
login,
|
|
||||||
)),
|
|
||||||
stream_losses: app_client.stream_losses.clone(),
|
stream_losses: app_client.stream_losses.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -917,6 +924,15 @@ fn forward(
|
|||||||
recovery.observe_busy();
|
recovery.observe_busy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Ok(status) = serde_json::from_value(serde_json::json!(&status)) {
|
||||||
|
let change = protocol::ThreadStatusChangedNotification {
|
||||||
|
thread_id: id.to_owned(),
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
let _ = output.send(AppServerEvent::CloudInventoryChanged(Some(Box::new(
|
||||||
|
protocol::ServerNotification::ThreadStatusChanged(change),
|
||||||
|
))));
|
||||||
|
}
|
||||||
*latest_status = Some((id.to_owned(), status));
|
*latest_status = Some((id.to_owned(), status));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -944,7 +960,24 @@ fn forward(
|
|||||||
thread_id: Some(id.to_owned()),
|
thread_id: Some(id.to_owned()),
|
||||||
message: "This cloud turn requested an unsupported interaction. Open it in another client to continue.".into(),
|
message: "This cloud turn requested an unsupported interaction. Open it in another client to continue.".into(),
|
||||||
}),
|
}),
|
||||||
cloud::Event::Notification(_) => return,
|
event @ cloud::Event::Notification(_) => {
|
||||||
|
let lifecycle = match event.inventory_change() {
|
||||||
|
Some(cloud::InventoryChange::Archived(thread_id)) => Some(
|
||||||
|
protocol::ServerNotification::ThreadArchived(
|
||||||
|
protocol::ThreadArchivedNotification { thread_id },
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Some(cloud::InventoryChange::Unarchived(thread_id)) => Some(
|
||||||
|
protocol::ServerNotification::ThreadUnarchived(
|
||||||
|
protocol::ThreadUnarchivedNotification { thread_id },
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Some(cloud::InventoryChange::Refresh) => None,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let _ = output.send(AppServerEvent::CloudInventoryChanged(lifecycle.map(Box::new)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
send_notification(output, notification);
|
send_notification(output, notification);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ pub enum AppServerEvent {
|
|||||||
},
|
},
|
||||||
ServerNotification(Box<ServerNotification>),
|
ServerNotification(Box<ServerNotification>),
|
||||||
ServerRequest(Box<ServerRequest>),
|
ServerRequest(Box<ServerRequest>),
|
||||||
|
/// The signed-in Cloud account may have changed its discoverable thread inventory.
|
||||||
|
CloudInventoryChanged(Option<Box<ServerNotification>>),
|
||||||
/// A native Cloud reply stream ended. The underlying thread can still be running.
|
/// A native Cloud reply stream ended. The underlying thread can still be running.
|
||||||
ThreadStreamDisconnected(Box<codex_app_server_protocol::ErrorNotification>),
|
ThreadStreamDisconnected(Box<codex_app_server_protocol::ErrorNotification>),
|
||||||
/// The Cloud worker is listening again on the same conversation.
|
/// The Cloud worker is listening again on the same conversation.
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ pub use items::ItemSummary;
|
|||||||
pub use prewarm::EnvironmentSelection;
|
pub use prewarm::EnvironmentSelection;
|
||||||
pub use prewarm::ProjectEnvironment;
|
pub use prewarm::ProjectEnvironment;
|
||||||
pub use transcript::FileUpdate;
|
pub use transcript::FileUpdate;
|
||||||
|
pub use transcript::InventoryChange;
|
||||||
pub use transcript::ItemDelta;
|
pub use transcript::ItemDelta;
|
||||||
pub use transcript::PatchKind;
|
pub use transcript::PatchKind;
|
||||||
pub use transcript::PatchUpdate;
|
pub use transcript::PatchUpdate;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Typed live transcript updates for the attached thread.
|
//! Live transcript updates for the attached thread and account notifications on its stream.
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::Event;
|
use crate::Event;
|
||||||
use crate::ThreadStatus;
|
use crate::ThreadStatus;
|
||||||
@@ -14,6 +14,13 @@ pub struct TranscriptEvent {
|
|||||||
pub update: TranscriptUpdate,
|
pub update: TranscriptUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Changes to the account's thread list reported over an attachment.
|
||||||
|
pub enum InventoryChange {
|
||||||
|
Archived(String),
|
||||||
|
Unarchived(String),
|
||||||
|
Refresh,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub enum TranscriptUpdate {
|
pub enum TranscriptUpdate {
|
||||||
ItemStarted(crate::ItemLifecycle),
|
ItemStarted(crate::ItemLifecycle),
|
||||||
@@ -99,7 +106,11 @@ redacted_debug!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Field numbers in the ASB Notification.value oneof.
|
// Field numbers in the ASB Notification.value oneof.
|
||||||
|
const THREAD_STARTED: u32 = 2;
|
||||||
const THREAD_STATUS_CHANGED: u32 = 3;
|
const THREAD_STATUS_CHANGED: u32 = 3;
|
||||||
|
const THREAD_ARCHIVED: u32 = 4;
|
||||||
|
const THREAD_UNARCHIVED: u32 = 6;
|
||||||
|
const THREAD_NAME_UPDATED: u32 = 10;
|
||||||
const TURN_STARTED: u32 = 21;
|
const TURN_STARTED: u32 = 21;
|
||||||
const TURN_COMPLETED: u32 = 23;
|
const TURN_COMPLETED: u32 = 23;
|
||||||
pub(super) const ITEM_STARTED: u32 = 27;
|
pub(super) const ITEM_STARTED: u32 = 27;
|
||||||
@@ -124,6 +135,36 @@ pub(super) fn required<T>(value: Option<T>) -> Result<T, DecodeFailure> {
|
|||||||
value.ok_or(DecodeFailure::MissingField)
|
value.ok_or(DecodeFailure::MissingField)
|
||||||
}
|
}
|
||||||
impl Event {
|
impl Event {
|
||||||
|
/// Recognizes account updates carried alongside the attached thread's transcript.
|
||||||
|
pub fn inventory_change(&self) -> Option<InventoryChange> {
|
||||||
|
let Self::Notification(bytes) = self else {
|
||||||
|
return None;
|
||||||
|
};
|
||||||
|
let (tag, values) = wire::notification(bytes).ok().flatten()?;
|
||||||
|
match tag {
|
||||||
|
THREAD_ARCHIVED | THREAD_UNARCHIVED => {
|
||||||
|
let envelope =
|
||||||
|
wire::merge_messages::<wire::Envelope<crate::wire::ThreadIdRequest>>(values)
|
||||||
|
.ok()?;
|
||||||
|
let id = envelope.params?.thread_id;
|
||||||
|
if id.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(if tag == THREAD_ARCHIVED {
|
||||||
|
InventoryChange::Archived(id)
|
||||||
|
} else {
|
||||||
|
InventoryChange::Unarchived(id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
THREAD_STARTED
|
||||||
|
| THREAD_STATUS_CHANGED
|
||||||
|
| THREAD_NAME_UPDATED
|
||||||
|
| TURN_STARTED
|
||||||
|
| TURN_COMPLETED => Some(InventoryChange::Refresh),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a supported status update for this thread from an Attach notification.
|
/// Returns a supported status update for this thread from an Attach notification.
|
||||||
pub fn thread_status_for(&self, thread_id: &str) -> Option<ThreadStatus> {
|
pub fn thread_status_for(&self, thread_id: &str) -> Option<ThreadStatus> {
|
||||||
let Self::Notification(bytes) = self else {
|
let Self::Notification(bytes) = self else {
|
||||||
|
|||||||
@@ -1584,7 +1584,8 @@ async fn finish_turn(
|
|||||||
AppServerEvent::ThreadStreamDisconnected(error) => {
|
AppServerEvent::ThreadStreamDisconnected(error) => {
|
||||||
anyhow::bail!("app-server stream disconnected: {}", error.error.message)
|
anyhow::bail!("app-server stream disconnected: {}", error.error.message)
|
||||||
}
|
}
|
||||||
AppServerEvent::ThreadStreamReconnected(_) => {}
|
AppServerEvent::CloudInventoryChanged(_)
|
||||||
|
| AppServerEvent::ThreadStreamReconnected(_) => {}
|
||||||
AppServerEvent::Lagged { skipped } => {
|
AppServerEvent::Lagged { skipped } => {
|
||||||
let message = lagged_event_warning_message(skipped);
|
let message = lagged_event_warning_message(skipped);
|
||||||
warn!("{message}");
|
warn!("{message}");
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ mod loading;
|
|||||||
#[path = "agents_overview_selection.rs"]
|
#[path = "agents_overview_selection.rs"]
|
||||||
mod selection;
|
mod selection;
|
||||||
|
|
||||||
|
use super::agents_overview_discovery::AgentsOverviewDiscovery;
|
||||||
use super::agents_overview_discovery::is_overview_root;
|
use super::agents_overview_discovery::is_overview_root;
|
||||||
use super::agents_overview_discovery::is_visible_in_agents_overview;
|
use super::agents_overview_discovery::is_visible_in_agents_overview;
|
||||||
use super::agents_overview_view::AgentsOverviewGroup;
|
use super::agents_overview_view::AgentsOverviewGroup;
|
||||||
@@ -59,10 +60,12 @@ pub(super) struct AgentsOverviewState {
|
|||||||
pub(super) usage_disabled: bool,
|
pub(super) usage_disabled: bool,
|
||||||
pub(super) activity: HashMap<ThreadId, super::agents_overview_details::AgentsOverviewActivity>,
|
pub(super) activity: HashMap<ThreadId, super::agents_overview_details::AgentsOverviewActivity>,
|
||||||
pub(super) initialized: HashSet<BackendId>,
|
pub(super) initialized: HashSet<BackendId>,
|
||||||
pub(super) discovery:
|
pub(super) discovery: HashMap<BackendId, AgentsOverviewDiscovery>,
|
||||||
HashMap<BackendId, super::agents_overview_discovery::AgentsOverviewDiscovery>,
|
|
||||||
pub(super) show_more_backends: HashSet<BackendId>,
|
pub(super) show_more_backends: HashSet<BackendId>,
|
||||||
pub(super) refresh_show_more: bool,
|
pub(super) refresh_show_more: bool,
|
||||||
|
pub(super) refresh_recent_backends: HashSet<BackendId>,
|
||||||
|
pub(super) cloud_inventory_dirty: HashSet<BackendId>,
|
||||||
|
pub(super) active_refresh_recent: bool,
|
||||||
pub(super) refresh_failed_backends: HashSet<BackendId>,
|
pub(super) refresh_failed_backends: HashSet<BackendId>,
|
||||||
/// Vacancies left by lifecycle removals, tracked by the backend that owned the row.
|
/// Vacancies left by lifecycle removals, tracked by the backend that owned the row.
|
||||||
pub(super) refill_by_backend: HashMap<BackendId, usize>,
|
pub(super) refill_by_backend: HashMap<BackendId, usize>,
|
||||||
@@ -97,6 +100,14 @@ pub(super) struct AgentsOverviewState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AgentsOverviewState {
|
impl AgentsOverviewState {
|
||||||
|
pub(super) fn cloud_refresh_pending(&self, owner: BackendId) -> bool {
|
||||||
|
(self.active_refresh_recent && self.active_refresh.is_some_and(|(_, id)| id == owner))
|
||||||
|
|| self
|
||||||
|
.discovery
|
||||||
|
.get(&owner)
|
||||||
|
.is_some_and(AgentsOverviewDiscovery::has_cloud_refresh_pending)
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn refill_count(&self, owner: BackendId) -> usize {
|
pub(super) fn refill_count(&self, owner: BackendId) -> usize {
|
||||||
self.refill_by_backend
|
self.refill_by_backend
|
||||||
.get(&owner)
|
.get(&owner)
|
||||||
@@ -113,7 +124,7 @@ impl AgentsOverviewState {
|
|||||||
&& self
|
&& self
|
||||||
.discovery
|
.discovery
|
||||||
.get(&owner)
|
.get(&owner)
|
||||||
.is_some_and(super::agents_overview_discovery::AgentsOverviewDiscovery::has_more)
|
.is_some_and(AgentsOverviewDiscovery::has_more)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,6 +163,17 @@ impl App {
|
|||||||
"Reconnecting — agent list is stale"
|
"Reconnecting — agent list is stale"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if app_server.thread_params_mode() == crate::app_server_session::ThreadParamsMode::Cloud {
|
||||||
|
let owner = app_server.backend_id();
|
||||||
|
if self.agents_overview.cloud_refresh_pending(owner) {
|
||||||
|
self.cancel_agents_overview_refresh(owner);
|
||||||
|
}
|
||||||
|
if let Some(discovery) = self.agents_overview.discovery.get_mut(&owner) {
|
||||||
|
discovery.restart_cloud_refresh();
|
||||||
|
}
|
||||||
|
self.agents_overview.cloud_inventory_dirty.remove(&owner);
|
||||||
|
self.agents_overview.refresh_recent_backends.insert(owner);
|
||||||
|
}
|
||||||
self.refresh_agents_overview_threads(app_server);
|
self.refresh_agents_overview_threads(app_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +196,7 @@ impl App {
|
|||||||
let refill_succeeded = result
|
let refill_succeeded = result
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_ok_and(|refresh| refresh.recent_seed_complete);
|
.is_ok_and(|refresh| refresh.recent_seed_complete);
|
||||||
|
self.agents_overview.active_refresh_recent = false;
|
||||||
if !refill_succeeded {
|
if !refill_succeeded {
|
||||||
self.agents_overview
|
self.agents_overview
|
||||||
.refresh_failed_backends
|
.refresh_failed_backends
|
||||||
@@ -220,7 +243,18 @@ impl App {
|
|||||||
if refresh.recent_seed_complete {
|
if refresh.recent_seed_complete {
|
||||||
self.agents_overview.initialized.insert(refresh_backend_id);
|
self.agents_overview.initialized.insert(refresh_backend_id);
|
||||||
}
|
}
|
||||||
if let Some(discovery) = refresh.discovery {
|
if let Some(mut discovery) = refresh.discovery {
|
||||||
|
// Fresh Cloud list rows can recover from a missed unarchive.
|
||||||
|
let overview = &mut self.agents_overview;
|
||||||
|
for id in discovery.fresh_cloud_page_ids.drain(..) {
|
||||||
|
if refill_succeeded
|
||||||
|
&& self.backend_registry.owner(id) == Some(refresh_backend_id)
|
||||||
|
&& !overview.pending_archives.contains_key(&id)
|
||||||
|
&& !overview.refresh_notifications.contains_key(&id)
|
||||||
|
{
|
||||||
|
overview.removed_threads.remove(&id);
|
||||||
|
}
|
||||||
|
}
|
||||||
if !discovery.has_more() {
|
if !discovery.has_more() {
|
||||||
self.agents_overview
|
self.agents_overview
|
||||||
.refill_by_backend
|
.refill_by_backend
|
||||||
@@ -373,6 +407,7 @@ impl App {
|
|||||||
let overview = &mut self.agents_overview;
|
let overview = &mut self.agents_overview;
|
||||||
overview.initialized.remove(&backend_id);
|
overview.initialized.remove(&backend_id);
|
||||||
overview.discovery.remove(&backend_id);
|
overview.discovery.remove(&backend_id);
|
||||||
|
overview.cloud_inventory_dirty.remove(&backend_id);
|
||||||
overview
|
overview
|
||||||
.removed_threads
|
.removed_threads
|
||||||
.retain(|thread_id| self.backend_registry.owner(*thread_id) != Some(backend_id));
|
.retain(|thread_id| self.backend_registry.owner(*thread_id) != Some(backend_id));
|
||||||
@@ -404,6 +439,9 @@ impl App {
|
|||||||
if std::mem::take(&mut overview.refresh_show_more) {
|
if std::mem::take(&mut overview.refresh_show_more) {
|
||||||
overview.show_more_backends.insert(backend_id);
|
overview.show_more_backends.insert(backend_id);
|
||||||
}
|
}
|
||||||
|
if std::mem::take(&mut overview.active_refresh_recent) {
|
||||||
|
overview.refresh_recent_backends.insert(backend_id);
|
||||||
|
}
|
||||||
let removed_threads = &overview.removed_threads;
|
let removed_threads = &overview.removed_threads;
|
||||||
overview.refresh_thread_ids.extend(
|
overview.refresh_thread_ids.extend(
|
||||||
overview
|
overview
|
||||||
@@ -421,6 +459,8 @@ impl App {
|
|||||||
.pending_refresh_backends
|
.pending_refresh_backends
|
||||||
.retain(|id| *id != backend_id);
|
.retain(|id| *id != backend_id);
|
||||||
if self.backend_registry.request_handle(backend_id).is_none() {
|
if self.backend_registry.request_handle(backend_id).is_none() {
|
||||||
|
overview.refresh_recent_backends.remove(&backend_id);
|
||||||
|
overview.cloud_inventory_dirty.remove(&backend_id);
|
||||||
overview.refresh_failed_backends.remove(&backend_id);
|
overview.refresh_failed_backends.remove(&backend_id);
|
||||||
}
|
}
|
||||||
self.drain_agents_overview_refresh_queue();
|
self.drain_agents_overview_refresh_queue();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//! Demand-driven history discovery. Each source retains its cursor and unshown rows.
|
//! Demand-driven history discovery. Each source retains its cursor and unshown rows.
|
||||||
|
//! Cloud refresh walks the displayed history independently of Show more.
|
||||||
//! Each new query scans the active backend from the start with its own paging cursor.
|
//! Each new query scans the active backend from the start with its own paging cursor.
|
||||||
|
|
||||||
use super::App;
|
use super::App;
|
||||||
@@ -15,6 +16,7 @@ use codex_app_server_protocol::ThreadListParams;
|
|||||||
use codex_app_server_protocol::ThreadListResponse;
|
use codex_app_server_protocol::ThreadListResponse;
|
||||||
use codex_app_server_protocol::ThreadSortKey;
|
use codex_app_server_protocol::ThreadSortKey;
|
||||||
use codex_app_server_protocol::ThreadSourceKind;
|
use codex_app_server_protocol::ThreadSourceKind;
|
||||||
|
use codex_protocol::ThreadId;
|
||||||
use codex_protocol::protocol::SubAgentSource;
|
use codex_protocol::protocol::SubAgentSource;
|
||||||
use codex_state::PINNED_THREAD_SECTION_ID;
|
use codex_state::PINNED_THREAD_SECTION_ID;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
@@ -140,6 +142,10 @@ impl Default for SourcePage {
|
|||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub(crate) struct AgentsOverviewDiscovery {
|
pub(crate) struct AgentsOverviewDiscovery {
|
||||||
sources: [SourcePage; 2],
|
sources: [SourcePage; 2],
|
||||||
|
// Oldest row delivered by Cloud history discovery.
|
||||||
|
cloud_frontier: Option<(i64, String)>,
|
||||||
|
cloud_refresh: Option<SourcePage>,
|
||||||
|
pub(super) fresh_cloud_page_ids: Vec<ThreadId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AgentsOverviewDiscovery {
|
impl AgentsOverviewDiscovery {
|
||||||
@@ -149,7 +155,7 @@ impl AgentsOverviewDiscovery {
|
|||||||
.any(|source| !source.exhausted || !source.rows.is_empty())
|
.any(|source| !source.exhausted || !source.rows.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn next_batch(
|
async fn next_batch(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &AppServerRequestHandle,
|
handle: &AppServerRequestHandle,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
@@ -189,6 +195,77 @@ impl AgentsOverviewDiscovery {
|
|||||||
}
|
}
|
||||||
(rows, left && right)
|
(rows, left && right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn has_cloud_refresh_pending(&self) -> bool {
|
||||||
|
self.cloud_refresh.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn restart_cloud_refresh(&mut self) {
|
||||||
|
self.cloud_refresh = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) async fn next_overview_page(
|
||||||
|
&mut self,
|
||||||
|
handle: &AppServerRequestHandle,
|
||||||
|
limit: usize,
|
||||||
|
refresh_recent: bool,
|
||||||
|
) -> (Vec<(Thread, bool)>, bool) {
|
||||||
|
if !matches!(handle, AppServerRequestHandle::Cloud(_)) {
|
||||||
|
return self.next_batch(handle, limit).await;
|
||||||
|
}
|
||||||
|
// Cloud has one source. Fetch only what we can show, even for a partial refill.
|
||||||
|
self.sources[1].exhausted = true;
|
||||||
|
let mut page = if refresh_recent {
|
||||||
|
self.cloud_refresh.take().unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
self.sources[0].clone()
|
||||||
|
};
|
||||||
|
page.page_size = limit as u32;
|
||||||
|
page.sort_key = ThreadSortKey::UpdatedAt;
|
||||||
|
if !page.fill(handle, Vec::new()).await {
|
||||||
|
if refresh_recent {
|
||||||
|
self.cloud_refresh = Some(SourcePage::default());
|
||||||
|
}
|
||||||
|
return (Vec::new(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut rows: Vec<_> = page.rows.drain(..).collect();
|
||||||
|
if refresh_recent && let Some((oldest, id)) = &self.cloud_frontier {
|
||||||
|
// Stop at the last row reached by Show more. Its timestamp also
|
||||||
|
// bounds the pass if that row has moved up or been archived.
|
||||||
|
if !self.sources[0].exhausted {
|
||||||
|
let boundary = rows.iter().enumerate().find_map(|(index, (thread, _))| {
|
||||||
|
if thread.updated_at < *oldest {
|
||||||
|
Some(index)
|
||||||
|
} else if thread.updated_at == *oldest && thread.id == *id {
|
||||||
|
Some(index + 1)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if let Some(end) = boundary {
|
||||||
|
rows.truncate(end);
|
||||||
|
page.exhausted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !page.exhausted {
|
||||||
|
self.cloud_refresh = Some(page);
|
||||||
|
}
|
||||||
|
} else if refresh_recent && rows.is_empty() && !page.exhausted {
|
||||||
|
self.cloud_refresh = Some(page);
|
||||||
|
} else {
|
||||||
|
// The first nonempty refresh of an empty list also seeds Show more.
|
||||||
|
if let Some((thread, _)) = rows.last() {
|
||||||
|
self.cloud_frontier = Some((thread.updated_at, thread.id.clone()));
|
||||||
|
}
|
||||||
|
self.sources[0] = page;
|
||||||
|
}
|
||||||
|
self.fresh_cloud_page_ids = rows
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(thread, _)| ThreadId::from_string(&thread.id).ok())
|
||||||
|
.collect();
|
||||||
|
(rows, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourcePage {
|
impl SourcePage {
|
||||||
|
|||||||
@@ -25,47 +25,77 @@ use tokio::sync::mpsc;
|
|||||||
use tokio_tungstenite::tungstenite::Message;
|
use tokio_tungstenite::tungstenite::Message;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn overview_cloud_discovery_uses_only_interactive_pages() {
|
async fn overview_refresh_grows_visible_history_and_preserves_the_show_more_cursor() {
|
||||||
let (client, mut commands, _events) = CloudClient::channel(/*capacity*/ 1);
|
let (client, mut commands, _events) = CloudClient::channel(/*capacity*/ 1);
|
||||||
let handle = AppServerClient::Cloud(client).request_handle();
|
let handle = AppServerClient::Cloud(client).request_handle();
|
||||||
let threads = ["First Cloud task", "Second Cloud task"].map(|name| {
|
let parent = None;
|
||||||
overview_thread(
|
let threads: Vec<_> = (0..66)
|
||||||
ThreadId::new(),
|
.map(|rank| {
|
||||||
/*parent_thread_id*/ None,
|
let mut thread = overview_thread(ThreadId::new(), parent, "Task", ThreadStatus::Idle);
|
||||||
name,
|
thread.updated_at -= rank;
|
||||||
ThreadStatus::NotLoaded,
|
(thread, false)
|
||||||
)
|
})
|
||||||
});
|
.collect();
|
||||||
|
let (more, refill, refresh) = (Some(10), Some(2), None);
|
||||||
let serve_pages = async {
|
let pages = [
|
||||||
for (thread, (cursor, next_cursor)) in threads
|
(more, None, Some((12..22, Some("h1")))),
|
||||||
.iter()
|
(more, Some("h1"), Some((22..32, Some("h2")))),
|
||||||
.zip([(None, Some("next")), (Some("next"), None)])
|
(more, Some("h2"), Some((32..42, Some("h3")))),
|
||||||
{
|
(more, Some("h3"), Some((42..52, Some("h4")))),
|
||||||
let command = commands.recv().await.unwrap();
|
(more, Some("h4"), Some((52..62, Some("h5")))),
|
||||||
let CloudOperation::Request(request) = command.operation else {
|
(refresh, None, Some((0..10, Some("r1")))),
|
||||||
panic!("expected a Cloud request");
|
(refresh, Some("r1"), None),
|
||||||
};
|
(refresh, None, Some((0..10, Some("r1")))),
|
||||||
let ClientRequest::ThreadList { params, .. } = *request else {
|
(refresh, Some("r1"), Some((10..20, Some("r2")))),
|
||||||
panic!("expected thread/list");
|
(refill, Some("h5"), Some((62..64, Some("h6")))),
|
||||||
};
|
(refresh, Some("r2"), Some((20..30, Some("r3")))),
|
||||||
assert_eq!(params.source_kinds, Some(Vec::new()));
|
(refresh, Some("r3"), Some((30..40, Some("r4")))),
|
||||||
assert_eq!(params.cursor.as_deref(), cursor);
|
(refresh, Some("r4"), Some((40..50, Some("r5")))),
|
||||||
command
|
(refresh, Some("r5"), Some((50..60, Some("r6")))),
|
||||||
|
(refresh, Some("r6"), Some((60..66, Some("r7")))),
|
||||||
|
(more, Some("h6"), Some((64..66, None))),
|
||||||
|
];
|
||||||
|
let mut discovery = AgentsOverviewDiscovery::default();
|
||||||
|
let mut shown = HashSet::new();
|
||||||
|
for (history_limit, cursor, page) in pages {
|
||||||
|
let range = page.as_ref().map_or(0..0, |(range, _)| range.clone());
|
||||||
|
let clipped_end = if cursor == Some("r6") { 64 } else { range.end };
|
||||||
|
let expected = &threads[range.start..clipped_end];
|
||||||
|
let complete = page.is_some();
|
||||||
|
let response = page
|
||||||
|
.map(|(range, next)| {
|
||||||
|
let data: Vec<_> = threads[range].iter().map(|(thread, _)| thread).collect();
|
||||||
|
json!({"data": data, "nextCursor": next})
|
||||||
|
})
|
||||||
|
.ok_or_else(|| JSONRPCErrorError {
|
||||||
|
code: -32603,
|
||||||
|
message: "Temporary list failure".into(),
|
||||||
|
data: None,
|
||||||
|
});
|
||||||
|
let serve_page = async {
|
||||||
|
next_cloud_page(&mut commands, cursor)
|
||||||
|
.await
|
||||||
.response
|
.response
|
||||||
.send(Ok(Ok(json!({"data": [thread], "nextCursor": next_cursor}))))
|
.send(Ok(response))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
};
|
||||||
|
let discover = discovery.next_overview_page(
|
||||||
|
&handle,
|
||||||
|
history_limit.unwrap_or(10),
|
||||||
|
history_limit.is_none(),
|
||||||
|
);
|
||||||
|
let ((rows, ok), ()) = tokio::join!(discover, serve_page);
|
||||||
|
assert_eq!((rows.as_slice(), ok), (expected, complete));
|
||||||
|
shown.extend(rows.into_iter().map(|(thread, _)| thread.id));
|
||||||
|
if cursor == Some("r1") && complete {
|
||||||
|
assert_eq!(shown.len(), 62);
|
||||||
}
|
}
|
||||||
};
|
if !complete {
|
||||||
let discover = async {
|
assert!(discovery.has_cloud_refresh_pending());
|
||||||
let mut discovery = AgentsOverviewDiscovery::default();
|
|
||||||
for (thread, has_more) in threads.iter().zip([true, false]) {
|
|
||||||
let page = discovery.next_batch(&handle, /*limit*/ 10).await;
|
|
||||||
assert_eq!(page, (vec![(thread.clone(), false)], true));
|
|
||||||
assert_eq!(discovery.has_more(), has_more);
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
tokio::join!(serve_pages, discover);
|
assert!(!discovery.has_cloud_refresh_pending());
|
||||||
|
assert!(!discovery.has_more());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -130,11 +160,21 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
|||||||
assert!(!app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
|
assert!(!app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The previous archive was observed, but its unarchive notification was missed.
|
||||||
|
app.agents_overview.threads.remove(&thread_id);
|
||||||
|
app.agents_overview.removed_threads.insert(thread_id);
|
||||||
app.open_agents_overview(&cloud);
|
app.open_agents_overview(&cloud);
|
||||||
let reopened = tokio::time::timeout(timeout, next_list(&mut commands)).await?;
|
let reopened = tokio::time::timeout(timeout, next_list(&mut commands)).await?;
|
||||||
|
let mut listed = current.clone();
|
||||||
|
listed.name = Some("Renamed in Cloud".to_string());
|
||||||
|
listed.updated_at += 1;
|
||||||
|
listed.recency_at = Some(listed.updated_at);
|
||||||
|
let unread = json!({"revision": "1", "firstUnread": {"type": "threadStart"}});
|
||||||
reopened
|
reopened
|
||||||
.response
|
.response
|
||||||
.send(Ok(Ok(json!({"data": [], "nextCursor": null}))))
|
.send(Ok(Ok(json!({
|
||||||
|
"data": [listed], "nextCursor": null, "readStates": {(thread_id.to_string()): unread}
|
||||||
|
}))))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read = tokio::time::timeout(timeout, commands.recv())
|
let read = tokio::time::timeout(timeout, commands.recv())
|
||||||
.await?
|
.await?
|
||||||
@@ -166,6 +206,31 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
|||||||
finish_overview_refresh(&mut app, &cloud, &mut events).await;
|
finish_overview_refresh(&mut app, &cloud, &mut events).await;
|
||||||
assert!(app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
|
assert!(app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
|
||||||
assert!(!app.agents_overview.refresh_failed_backends.contains(&owner));
|
assert!(!app.agents_overview.refresh_failed_backends.contains(&owner));
|
||||||
|
assert_eq!(
|
||||||
|
app.agents_overview.threads[&thread_id],
|
||||||
|
Some(listed.clone())
|
||||||
|
);
|
||||||
|
assert!(app.agents_overview.unread.contains(&thread_id));
|
||||||
|
|
||||||
|
app.refresh_agents_overview_threads(&cloud);
|
||||||
|
reject_cloud_pinned_list(&mut commands).await;
|
||||||
|
current.status = ThreadStatus::NotLoaded;
|
||||||
|
for response in [
|
||||||
|
json!({"thread": current, "readState": null}),
|
||||||
|
json!({"data": [], "nextCursor": null, "backwardsCursor": null}),
|
||||||
|
] {
|
||||||
|
commands
|
||||||
|
.recv()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.response
|
||||||
|
.send(Ok(Ok(response)))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
finish_overview_refresh(&mut app, &cloud, &mut events).await;
|
||||||
|
listed.status = current.status;
|
||||||
|
assert_eq!(app.agents_overview.threads[&thread_id], Some(listed));
|
||||||
|
assert!(app.agents_overview.unread.contains(&thread_id));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +251,9 @@ async fn resume_picker_cancels_a_held_cloud_show_more_page() -> Result<()> {
|
|||||||
);
|
);
|
||||||
let mut discovery = AgentsOverviewDiscovery::default();
|
let mut discovery = AgentsOverviewDiscovery::default();
|
||||||
let handle = cloud.request_handle();
|
let handle = cloud.request_handle();
|
||||||
let (page, ()) = tokio::join!(discovery.next_batch(&handle, /*limit*/ 10), async {
|
let page =
|
||||||
|
discovery.next_overview_page(&handle, /*limit*/ 10, /*refresh_recent*/ false);
|
||||||
|
let (page, ()) = tokio::join!(page, async {
|
||||||
let command = next_cloud_page(&mut commands, /*cursor*/ None).await;
|
let command = next_cloud_page(&mut commands, /*cursor*/ None).await;
|
||||||
command
|
command
|
||||||
.response
|
.response
|
||||||
@@ -375,7 +442,9 @@ async fn overview_local_enter_drops_the_displayed_cloud_list_before_detach() ->
|
|||||||
let mut discovery = AgentsOverviewDiscovery::default();
|
let mut discovery = AgentsOverviewDiscovery::default();
|
||||||
let handle = cloud.request_handle();
|
let handle = cloud.request_handle();
|
||||||
let (first_page, ()) = tokio::time::timeout(timeout, async {
|
let (first_page, ()) = tokio::time::timeout(timeout, async {
|
||||||
tokio::join!(discovery.next_batch(&handle, /*limit*/ 10), async {
|
let page =
|
||||||
|
discovery.next_overview_page(&handle, /*limit*/ 10, /*refresh_recent*/ false);
|
||||||
|
tokio::join!(page, async {
|
||||||
let command = next_cloud_page(&mut commands, /*cursor*/ None).await;
|
let command = next_cloud_page(&mut commands, /*cursor*/ None).await;
|
||||||
command
|
command
|
||||||
.response
|
.response
|
||||||
@@ -773,6 +842,13 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
|
|||||||
}
|
}
|
||||||
assert_eq!(app.agents_overview.threads.len(), 10);
|
assert_eq!(app.agents_overview.threads.len(), 10);
|
||||||
assert!(app.agents_overview.threads.contains_key(&ids[10]));
|
assert!(app.agents_overview.threads.contains_key(&ids[10]));
|
||||||
|
let retained_id = ids[14];
|
||||||
|
let mut retained = expected[&retained_id].clone().unwrap();
|
||||||
|
retained.name = Some("Earlier task name".to_string());
|
||||||
|
assert!(app.backend_registry.observe(owner, retained_id));
|
||||||
|
app.agents_overview
|
||||||
|
.threads
|
||||||
|
.insert(retained_id, Some(retained));
|
||||||
let other = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
let other = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||||
let other_owner = other.backend_id();
|
let other_owner = other.backend_id();
|
||||||
if mixed_sources {
|
if mixed_sources {
|
||||||
@@ -820,6 +896,10 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
|
|||||||
);
|
);
|
||||||
app.backend_registry.disconnect(other_owner);
|
app.backend_registry.disconnect(other_owner);
|
||||||
other.shutdown().await?;
|
other.shutdown().await?;
|
||||||
|
assert_eq!(
|
||||||
|
app.agents_overview.threads[&retained_id],
|
||||||
|
expected[&retained_id]
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.agents_overview
|
app.agents_overview
|
||||||
.threads
|
.threads
|
||||||
|
|||||||
@@ -332,9 +332,12 @@ async fn late_overview_page_only_refills_its_own_backend() {
|
|||||||
);
|
);
|
||||||
app.remove_agents_overview_thread(id);
|
app.remove_agents_overview_thread(id);
|
||||||
|
|
||||||
for owner in [other, displayed] {
|
// The displayed backend's next history page contains the restored task.
|
||||||
|
for (owner, replacement) in [(other, ThreadId::new()), (displayed, id)] {
|
||||||
let request_id = Uuid::new_v4();
|
let request_id = Uuid::new_v4();
|
||||||
let replacement = ThreadId::new();
|
let mut discovery =
|
||||||
|
crate::app::agents_overview_discovery::AgentsOverviewDiscovery::default();
|
||||||
|
discovery.fresh_cloud_page_ids.push(replacement);
|
||||||
let row = overview_thread(
|
let row = overview_thread(
|
||||||
replacement,
|
replacement,
|
||||||
/*parent_thread_id*/ None,
|
/*parent_thread_id*/ None,
|
||||||
@@ -350,7 +353,7 @@ async fn late_overview_page_only_refills_its_own_backend() {
|
|||||||
threads: HashMap::from([(replacement, Some((row, false, None)))]),
|
threads: HashMap::from([(replacement, Some((row, false, None)))]),
|
||||||
last_messages: HashMap::new(),
|
last_messages: HashMap::new(),
|
||||||
recent_seed_complete: true,
|
recent_seed_complete: true,
|
||||||
discovery: None,
|
discovery: Some(discovery),
|
||||||
pinned_thread_ids: None,
|
pinned_thread_ids: None,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -384,7 +387,20 @@ async fn queued_overview_page_survives_a_focus_change() {
|
|||||||
app.show_more_agents_overview(&session);
|
app.show_more_agents_overview(&session);
|
||||||
|
|
||||||
app.app_server_backend_id = Some(other);
|
app.app_server_backend_id = Some(other);
|
||||||
|
app.chat_widget
|
||||||
|
.dismiss_provider_view(AGENTS_OVERVIEW_VIEW_ID);
|
||||||
app.agents_overview.active_refresh = None;
|
app.agents_overview.active_refresh = None;
|
||||||
|
app.handle_polled_backend_event(
|
||||||
|
&session,
|
||||||
|
other,
|
||||||
|
&mut HashMap::new(),
|
||||||
|
crate::app_server_session::AppServerSessionEvent {
|
||||||
|
backend_id: owner,
|
||||||
|
event: AppServerEvent::CloudInventoryChanged(None),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(app.agents_overview.refresh_recent_backends.contains(&owner));
|
||||||
app.drain_agents_overview_refresh_queue();
|
app.drain_agents_overview_refresh_queue();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.agents_overview.pending_refresh_backends.front(),
|
app.agents_overview.pending_refresh_backends.front(),
|
||||||
@@ -394,12 +410,64 @@ async fn queued_overview_page_survives_a_focus_change() {
|
|||||||
|
|
||||||
app.app_server_backend_id = Some(owner);
|
app.app_server_backend_id = Some(owner);
|
||||||
app.open_agents_overview(&session);
|
app.open_agents_overview(&session);
|
||||||
assert_eq!(
|
let (page, page_owner) = app.agents_overview.active_refresh.unwrap();
|
||||||
app.agents_overview.active_refresh.map(|(_, id)| id),
|
assert_eq!(page_owner, owner);
|
||||||
Some(owner)
|
|
||||||
);
|
|
||||||
assert!(app.agents_overview.pending_refresh_backends.is_empty());
|
|
||||||
assert!(app.agents_overview.refresh_show_more);
|
assert!(app.agents_overview.refresh_show_more);
|
||||||
|
assert!(!app.agents_overview.active_refresh_recent);
|
||||||
|
assert!(app.agents_overview.refresh_recent_backends.contains(&owner));
|
||||||
|
app.agents_overview.refresh_task.take().unwrap().abort();
|
||||||
|
app.agents_overview.show_more_backends.insert(owner);
|
||||||
|
app.agents_overview.refill_by_backend.insert(owner, 1);
|
||||||
|
app.apply_agents_overview_thread_refresh(&session, page, Err("temporary page failure".into()));
|
||||||
|
let (recent, recent_owner) = app.agents_overview.active_refresh.unwrap();
|
||||||
|
assert_eq!(recent_owner, owner);
|
||||||
|
assert!(app.agents_overview.active_refresh_recent);
|
||||||
|
assert!(app.agents_overview.show_more_backends.contains(&owner));
|
||||||
|
let id = ThreadId::new();
|
||||||
|
for (method, archived) in [("thread/archived", true), ("thread/unarchived", false)] {
|
||||||
|
let lifecycle = serde_json::from_value(
|
||||||
|
serde_json::json!({"method": method, "params": {"threadId": id.to_string()}}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
app.handle_app_server_event(
|
||||||
|
&session,
|
||||||
|
AppServerEvent::CloudInventoryChanged(Some(Box::new(lifecycle))),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(app.agents_overview.removed_threads.contains(&id), archived);
|
||||||
|
}
|
||||||
|
app.poll_cloud_inventory(&session, /*attached*/ true);
|
||||||
|
assert_eq!(app.agents_overview.active_refresh, Some((recent, owner)));
|
||||||
|
assert!(app.agents_overview.cloud_inventory_dirty.contains(&owner));
|
||||||
|
app.cancel_agents_overview_refresh(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cloud_inventory_polls_when_visible_and_detached() {
|
||||||
|
let mut app = make_test_app().await;
|
||||||
|
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||||
|
app.app_event_tx = AppEventSender::new(tx);
|
||||||
|
let owner = BackendId::new();
|
||||||
|
let (session, _commands, _events) = overview_session_stub(owner, ThreadParamsMode::Cloud);
|
||||||
|
app.backend_registry.connect(&session);
|
||||||
|
app.app_server_backend_id = Some(owner);
|
||||||
|
app.agents_overview.initialized.insert(owner);
|
||||||
|
app.poll_cloud_inventory(&session, /*attached*/ false);
|
||||||
|
assert!(app.agents_overview.active_refresh.is_none());
|
||||||
|
|
||||||
|
let view = app.agents_overview_view(Vec::new(), /*selected_thread_id*/ None);
|
||||||
|
app.chat_widget.show_bottom_pane_view(Box::new(view));
|
||||||
|
app.poll_cloud_inventory(&session, /*attached*/ true);
|
||||||
|
assert!(app.agents_overview.active_refresh.is_none());
|
||||||
|
app.poll_cloud_inventory(&session, /*attached*/ false);
|
||||||
|
assert!(app.agents_overview.active_refresh_recent);
|
||||||
|
app.agents_overview.view_state.lock().unwrap().has_more = true;
|
||||||
|
app.chat_widget.handle_key_event(KeyCode::Down.into());
|
||||||
|
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||||
|
assert!(
|
||||||
|
std::iter::from_fn(|| rx.try_recv().ok())
|
||||||
|
.any(|event| matches!(event, AppEvent::ShowMoreAgentsOverview))
|
||||||
|
);
|
||||||
app.cancel_agents_overview_refresh(owner);
|
app.cancel_agents_overview_refresh(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -815,6 +883,9 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
|||||||
);
|
);
|
||||||
// A successful read supersedes registration; queued notifications supersede the read.
|
// A successful read supersedes registration; queued notifications supersede the read.
|
||||||
retained_thread.preview = "Fresh preview from the read".to_string();
|
retained_thread.preview = "Fresh preview from the read".to_string();
|
||||||
|
let mut discovery = crate::app::agents_overview_discovery::AgentsOverviewDiscovery::default();
|
||||||
|
discovery.fresh_cloud_page_ids = vec![archived, deleted];
|
||||||
|
app.agents_overview.active_refresh_recent = true;
|
||||||
app.apply_agents_overview_thread_refresh(
|
app.apply_agents_overview_thread_refresh(
|
||||||
&app_server,
|
&app_server,
|
||||||
request_id,
|
request_id,
|
||||||
@@ -827,7 +898,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
|||||||
(deleted, Some((deleted_thread, false, None))),
|
(deleted, Some((deleted_thread, false, None))),
|
||||||
]),
|
]),
|
||||||
recent_seed_complete: true,
|
recent_seed_complete: true,
|
||||||
discovery: None,
|
discovery: Some(discovery),
|
||||||
pinned_thread_ids: None,
|
pinned_thread_ids: None,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -838,6 +909,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
|||||||
(created, Some(created_thread)),
|
(created, Some(created_thread)),
|
||||||
]);
|
]);
|
||||||
assert_eq!(app.agents_overview.threads, expected);
|
assert_eq!(app.agents_overview.threads, expected);
|
||||||
|
assert_eq!(app.agents_overview.refill_count(app_server.backend_id()), 0);
|
||||||
|
|
||||||
let request_id = Uuid::new_v4();
|
let request_id = Uuid::new_v4();
|
||||||
app.agents_overview.active_refresh = Some((request_id, app_server.backend_id()));
|
app.agents_overview.active_refresh = Some((request_id, app_server.backend_id()));
|
||||||
|
|||||||
@@ -336,7 +336,13 @@ impl App {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let cloud = matches!(&request_handle, AppServerRequestHandle::Cloud(_));
|
||||||
let refill = overview.refill_count(backend_id);
|
let refill = overview.refill_count(backend_id);
|
||||||
|
let page_requested = source_has_more
|
||||||
|
&& !overview.refresh_failed_backends.contains(&backend_id)
|
||||||
|
&& (refill > 0 || overview.show_more_backends.contains(&backend_id));
|
||||||
|
let refresh_recent =
|
||||||
|
!page_requested && overview.refresh_recent_backends.remove(&backend_id) && initialized;
|
||||||
let queued = overview.pending_refresh_backends.contains(&backend_id);
|
let queued = overview.pending_refresh_backends.contains(&backend_id);
|
||||||
if queued {
|
if queued {
|
||||||
overview
|
overview
|
||||||
@@ -345,6 +351,7 @@ impl App {
|
|||||||
overview.pin_refresh_requested = true;
|
overview.pin_refresh_requested = true;
|
||||||
}
|
}
|
||||||
let should_refresh = !initialized
|
let should_refresh = !initialized
|
||||||
|
|| refresh_recent
|
||||||
|| overview.refresh_thread_ids.iter().any(|id| {
|
|| overview.refresh_thread_ids.iter().any(|id| {
|
||||||
self.backend_registry
|
self.backend_registry
|
||||||
.owner(*id)
|
.owner(*id)
|
||||||
@@ -357,6 +364,9 @@ impl App {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if page_requested && overview.refresh_recent_backends.contains(&backend_id) {
|
||||||
|
overview.pending_refresh_backends.push_back(backend_id);
|
||||||
|
}
|
||||||
let mut unread_rows = Vec::new();
|
let mut unread_rows = Vec::new();
|
||||||
if std::mem::take(&mut self.agents_overview.pin_refresh_requested) {
|
if std::mem::take(&mut self.agents_overview.pin_refresh_requested) {
|
||||||
unread_rows.extend(
|
unread_rows.extend(
|
||||||
@@ -375,12 +385,16 @@ impl App {
|
|||||||
}
|
}
|
||||||
let request_id = Uuid::new_v4();
|
let request_id = Uuid::new_v4();
|
||||||
self.agents_overview.active_refresh = Some((request_id, backend_id));
|
self.agents_overview.active_refresh = Some((request_id, backend_id));
|
||||||
let show_more = refill == 0
|
let show_more = !refresh_recent
|
||||||
|
&& refill == 0
|
||||||
&& source_has_more
|
&& source_has_more
|
||||||
&& self.agents_overview.show_more_backends.remove(&backend_id);
|
&& self.agents_overview.show_more_backends.remove(&backend_id);
|
||||||
self.agents_overview.refresh_show_more = show_more;
|
self.agents_overview.refresh_show_more = show_more;
|
||||||
let discover = !initialized || show_more || (refill > 0 && source_has_more);
|
let fresh_cloud_list = cloud && (refresh_recent || !initialized);
|
||||||
let limit = if initialized && refill > 0 {
|
self.agents_overview.active_refresh_recent = fresh_cloud_list;
|
||||||
|
let discover =
|
||||||
|
refresh_recent || !initialized || show_more || (refill > 0 && source_has_more);
|
||||||
|
let limit = if !refresh_recent && initialized && refill > 0 {
|
||||||
refill.min(10)
|
refill.min(10)
|
||||||
} else {
|
} else {
|
||||||
10
|
10
|
||||||
@@ -404,12 +418,30 @@ impl App {
|
|||||||
.refresh_thread_ids
|
.refresh_thread_ids
|
||||||
.extend(foreign_thread_ids);
|
.extend(foreign_thread_ids);
|
||||||
self.agents_overview.active_refresh_thread_ids = thread_ids.clone();
|
self.agents_overview.active_refresh_thread_ids = thread_ids.clone();
|
||||||
|
let mut retained = HashMap::new();
|
||||||
|
if cloud {
|
||||||
|
for (&id, row) in &self.agents_overview.threads {
|
||||||
|
let Some(thread) = row else { continue };
|
||||||
|
if (!initialized || thread_ids.contains(&id))
|
||||||
|
&& self.backend_registry.owner(id) == Some(backend_id)
|
||||||
|
{
|
||||||
|
retained.insert(
|
||||||
|
id,
|
||||||
|
(
|
||||||
|
thread.clone(),
|
||||||
|
self.agents_overview.unread.contains(&id),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
let app_event_tx = self.app_event_tx.clone();
|
let app_event_tx = self.app_event_tx.clone();
|
||||||
self.agents_overview
|
self.agents_overview
|
||||||
.view_state
|
.view_state
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||||
.loading = discover;
|
.loading = discover && !refresh_recent;
|
||||||
let refresh_task = tokio::spawn(async move {
|
let refresh_task = tokio::spawn(async move {
|
||||||
let result = async {
|
let result = async {
|
||||||
let mut threads = HashMap::new();
|
let mut threads = HashMap::new();
|
||||||
@@ -452,8 +484,8 @@ impl App {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
let (loaded, (recent, complete)) =
|
let page = discovery.next_overview_page(&request_handle, limit, refresh_recent);
|
||||||
tokio::join!(loaded, discovery.next_batch(&request_handle, limit));
|
let (loaded, (recent, complete)) = tokio::join!(loaded, page);
|
||||||
let loaded = loaded.map_err(|error| error.to_string())?;
|
let loaded = loaded.map_err(|error| error.to_string())?;
|
||||||
recent_seed_complete = complete;
|
recent_seed_complete = complete;
|
||||||
thread_ids.extend(
|
thread_ids.extend(
|
||||||
@@ -492,6 +524,12 @@ impl App {
|
|||||||
.await;
|
.await;
|
||||||
let mut reads = tokio::task::JoinSet::new();
|
let mut reads = tokio::task::JoinSet::new();
|
||||||
for thread_id in thread_ids {
|
for thread_id in thread_ids {
|
||||||
|
let listed = threads
|
||||||
|
.get(&thread_id)
|
||||||
|
.filter(|_| cloud)
|
||||||
|
.cloned()
|
||||||
|
.flatten()
|
||||||
|
.or_else(|| retained.remove(&thread_id));
|
||||||
threads.entry(thread_id).or_default();
|
threads.entry(thread_id).or_default();
|
||||||
let request_handle = request_handle.clone();
|
let request_handle = request_handle.clone();
|
||||||
reads.spawn(async move {
|
reads.spawn(async move {
|
||||||
@@ -505,7 +543,7 @@ impl App {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(mut response) => {
|
||||||
let mut latest_prompt = None;
|
let mut latest_prompt = None;
|
||||||
let mut last_message = None;
|
let mut last_message = None;
|
||||||
// Legacy turn listing replays the entire rollout, even for one turn.
|
// Legacy turn listing replays the entire rollout, even for one turn.
|
||||||
@@ -548,9 +586,15 @@ impl App {
|
|||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let unread = response
|
let mut unread = response
|
||||||
.read_state
|
.read_state
|
||||||
.is_some_and(|state| state.first_unread.is_some());
|
.is_some_and(|state| state.first_unread.is_some());
|
||||||
|
if let Some((thread, listed_unread, _)) = listed {
|
||||||
|
response.thread.name = thread.name;
|
||||||
|
response.thread.updated_at = thread.updated_at;
|
||||||
|
response.thread.recency_at = thread.recency_at;
|
||||||
|
unread = listed_unread;
|
||||||
|
}
|
||||||
Some((
|
Some((
|
||||||
thread_id,
|
thread_id,
|
||||||
(response.thread, unread, latest_prompt),
|
(response.thread, unread, latest_prompt),
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ impl App {
|
|||||||
event: AppServerEvent,
|
event: AppServerEvent,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
|
AppServerEvent::CloudInventoryChanged(lifecycle) => {
|
||||||
|
self.invalidate_cloud_inventory(app_server_client, lifecycle.as_deref())
|
||||||
|
}
|
||||||
AppServerEvent::Lagged { skipped } => {
|
AppServerEvent::Lagged { skipped } => {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
skipped,
|
skipped,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
//! Connection-wide lifecycle and account events may only update the displayed conversation's UI.
|
//! Connection-wide lifecycle and account events may only update the displayed conversation's UI.
|
||||||
|
|
||||||
use super::App;
|
use super::App;
|
||||||
|
use super::agents_overview::AGENTS_OVERVIEW_VIEW_ID;
|
||||||
use super::app_server_event_targets::ServerNotificationThreadTarget;
|
use super::app_server_event_targets::ServerNotificationThreadTarget;
|
||||||
use super::app_server_event_targets::server_notification_thread_target;
|
use super::app_server_event_targets::server_notification_thread_target;
|
||||||
use crate::app_server_session::AppServerSession;
|
use crate::app_server_session::AppServerSession;
|
||||||
@@ -25,6 +26,10 @@ impl App {
|
|||||||
if event.backend_id != app_server.backend_id() {
|
if event.backend_id != app_server.backend_id() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if let AppServerEvent::CloudInventoryChanged(lifecycle) = &event.event {
|
||||||
|
self.invalidate_cloud_inventory(app_server, lifecycle.as_deref());
|
||||||
|
return;
|
||||||
|
}
|
||||||
let invalidates_discovery = match &event.event {
|
let invalidates_discovery = match &event.event {
|
||||||
AppServerEvent::Lagged { .. } | AppServerEvent::Disconnected { .. } => true,
|
AppServerEvent::Lagged { .. } | AppServerEvent::Disconnected { .. } => true,
|
||||||
AppServerEvent::ServerNotification(notification) => matches!(
|
AppServerEvent::ServerNotification(notification) => matches!(
|
||||||
@@ -72,6 +77,69 @@ impl App {
|
|||||||
self.handle_backend_event(app_server, event).await;
|
self.handle_backend_event(app_server, event).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn invalidate_cloud_inventory(
|
||||||
|
&mut self,
|
||||||
|
app_server: &AppServerSession,
|
||||||
|
lifecycle: Option<&ServerNotification>,
|
||||||
|
) {
|
||||||
|
if app_server.thread_params_mode() != crate::app_server_session::ThreadParamsMode::Cloud {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let owner = app_server.backend_id();
|
||||||
|
let status_changed = matches!(lifecycle, Some(ServerNotification::ThreadStatusChanged(_)));
|
||||||
|
if let Some(
|
||||||
|
notification @ (ServerNotification::ThreadArchived(_)
|
||||||
|
| ServerNotification::ThreadUnarchived(_)
|
||||||
|
| ServerNotification::ThreadStatusChanged(_)),
|
||||||
|
) = lifecycle
|
||||||
|
&& let ServerNotificationThreadTarget::Thread(id) =
|
||||||
|
server_notification_thread_target(notification)
|
||||||
|
&& self.backend_registry.observe(owner, id)
|
||||||
|
{
|
||||||
|
self.track_agents_overview_notification(notification);
|
||||||
|
self.repaint_agents_overview();
|
||||||
|
if status_changed && matches!(self.agents_overview.threads.get(&id), Some(Some(_))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if self.agents_overview.cloud_refresh_pending(owner) {
|
||||||
|
self.agents_overview.cloud_inventory_dirty.insert(owner);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.agents_overview.cloud_inventory_dirty.remove(&owner);
|
||||||
|
self.agents_overview.refresh_recent_backends.insert(owner);
|
||||||
|
if self.cloud_inventory_visible(owner) {
|
||||||
|
self.start_agents_overview_refresh_for_backend(owner, app_server.request_handle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn cloud_inventory_visible(&self, owner: BackendId) -> bool {
|
||||||
|
self.app_server_backend_id == Some(owner)
|
||||||
|
&& !self.reconnect.offline
|
||||||
|
&& self
|
||||||
|
.chat_widget
|
||||||
|
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn poll_cloud_inventory(&mut self, app_server: &AppServerSession, attached: bool) {
|
||||||
|
let owner = app_server.backend_id();
|
||||||
|
if self.agents_overview.active_refresh.is_some() || !self.cloud_inventory_visible(owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let overview = &mut self.agents_overview;
|
||||||
|
if !overview.cloud_refresh_pending(owner)
|
||||||
|
&& !overview.cloud_inventory_dirty.remove(&owner)
|
||||||
|
&& !overview.refresh_recent_backends.contains(&owner)
|
||||||
|
&& overview.initialized.contains(&owner)
|
||||||
|
&& attached
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
overview.refresh_recent_backends.insert(owner);
|
||||||
|
self.start_agents_overview_refresh_for_backend(owner, app_server.request_handle());
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_backend_event(
|
pub(super) async fn handle_backend_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
app_server: &AppServerSession,
|
app_server: &AppServerSession,
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
self.agents_overview.active_refresh = None;
|
self.agents_overview.active_refresh = None;
|
||||||
self.agents_overview.refresh_show_more = false;
|
self.agents_overview.refresh_show_more = false;
|
||||||
|
self.agents_overview.active_refresh_recent = false;
|
||||||
self.agents_overview.active_refresh_thread_ids.clear();
|
self.agents_overview.active_refresh_thread_ids.clear();
|
||||||
self.agents_overview.pending_refresh_backends.clear();
|
self.agents_overview.pending_refresh_backends.clear();
|
||||||
self.agents_overview.refresh_notifications.clear();
|
self.agents_overview.refresh_notifications.clear();
|
||||||
|
|||||||
@@ -1343,6 +1343,9 @@ See the Codex keymap documentation for supported actions and examples."
|
|||||||
let mut last_screen_size = tui.terminal.last_known_screen_size;
|
let mut last_screen_size = tui.terminal.last_known_screen_size;
|
||||||
let mut settled_size_tags = crate::terminal_size_telemetry::tags(last_screen_size);
|
let mut settled_size_tags = crate::terminal_size_telemetry::tags(last_screen_size);
|
||||||
let mut pending_resize: Option<(ratatui::layout::Size, Instant)> = None;
|
let mut pending_resize: Option<(ratatui::layout::Size, Instant)> = None;
|
||||||
|
let mut cloud_inventory_poll = tokio::time::interval(Duration::from_secs(/*secs*/ 10));
|
||||||
|
cloud_inventory_poll.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
|
||||||
|
let mut cloud_inventory_owner = None;
|
||||||
let mut reconnect = None;
|
let mut reconnect = None;
|
||||||
let mut cloud_environment_picker: Option<
|
let mut cloud_environment_picker: Option<
|
||||||
futures::future::LocalBoxFuture<'static, crate::bottom_pane::SelectionViewParams>,
|
futures::future::LocalBoxFuture<'static, crate::bottom_pane::SelectionViewParams>,
|
||||||
@@ -1567,6 +1570,15 @@ See the Codex keymap documentation for supported actions and examples."
|
|||||||
.chat_widget
|
.chat_widget
|
||||||
.rate_limit_refresh_interval()
|
.rate_limit_refresh_interval()
|
||||||
.and_then(|interval| app.rate_limit_refresh_state.poll_deadline(interval));
|
.and_then(|interval| app.rate_limit_refresh_state.poll_deadline(interval));
|
||||||
|
let cloud_owner = (backends.is_listening(displayed_owner)
|
||||||
|
&& backends.session_at(displayed_session).thread_params_mode()
|
||||||
|
== crate::ThreadParamsMode::Cloud
|
||||||
|
&& app.cloud_inventory_visible(displayed_owner))
|
||||||
|
.then_some(displayed_owner);
|
||||||
|
if cloud_inventory_owner != cloud_owner {
|
||||||
|
cloud_inventory_owner = cloud_owner;
|
||||||
|
cloud_inventory_poll.reset();
|
||||||
|
}
|
||||||
let control = select! {
|
let control = select! {
|
||||||
result = async {
|
result = async {
|
||||||
match app.daemon_restart.as_mut() {
|
match app.daemon_restart.as_mut() {
|
||||||
@@ -1851,6 +1863,13 @@ See the Codex keymap documentation for supported actions and examples."
|
|||||||
app.refresh_rate_limits(backends.session_at(displayed_session), RateLimitRefreshOrigin::Periodic);
|
app.refresh_rate_limits(backends.session_at(displayed_session), RateLimitRefreshOrigin::Periodic);
|
||||||
AppRunControl::Continue
|
AppRunControl::Continue
|
||||||
}
|
}
|
||||||
|
_ = cloud_inventory_poll.tick(), if cloud_owner.is_some() => {
|
||||||
|
let session = backends.session_at(displayed_session);
|
||||||
|
if let AppServerRequestHandle::Cloud(handle) = session.request_handle() {
|
||||||
|
app.poll_cloud_inventory(session, handle.has_attachment());
|
||||||
|
}
|
||||||
|
AppRunControl::Continue
|
||||||
|
}
|
||||||
() = async {
|
() = async {
|
||||||
match app.chat_widget.terminal_title_next_refresh {
|
match app.chat_widget.terminal_title_next_refresh {
|
||||||
Some(deadline) => {
|
Some(deadline) => {
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ pub(crate) async fn handle_event_during_device_login(
|
|||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
AppServerEvent::ServerNotification(_)
|
AppServerEvent::ServerNotification(_)
|
||||||
|
| AppServerEvent::CloudInventoryChanged(_)
|
||||||
| AppServerEvent::ThreadStreamDisconnected(_)
|
| AppServerEvent::ThreadStreamDisconnected(_)
|
||||||
| AppServerEvent::ThreadStreamReconnected(_) => Ok(false),
|
| AppServerEvent::ThreadStreamReconnected(_) => Ok(false),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,8 @@ stream_max_retries = 0
|
|||||||
return Ok::<_, color_eyre::eyre::Report>(());
|
return Ok::<_, color_eyre::eyre::Report>(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
codex_app_server_client::AppServerEvent::ThreadStreamReconnected(_)
|
codex_app_server_client::AppServerEvent::CloudInventoryChanged(_)
|
||||||
|
| codex_app_server_client::AppServerEvent::ThreadStreamReconnected(_)
|
||||||
| codex_app_server_client::AppServerEvent::ThreadStreamDisconnected(_) => {}
|
| codex_app_server_client::AppServerEvent::ThreadStreamDisconnected(_) => {}
|
||||||
codex_app_server_client::AppServerEvent::Lagged { .. }
|
codex_app_server_client::AppServerEvent::Lagged { .. }
|
||||||
| codex_app_server_client::AppServerEvent::Disconnected { .. } => {
|
| codex_app_server_client::AppServerEvent::Disconnected { .. } => {
|
||||||
|
|||||||
@@ -867,7 +867,8 @@ async fn run_onboarding_screen_inner(
|
|||||||
AppServerEvent::Disconnected { message } => {
|
AppServerEvent::Disconnected { message } => {
|
||||||
return Err(color_eyre::eyre::eyre!(message));
|
return Err(color_eyre::eyre::eyre!(message));
|
||||||
}
|
}
|
||||||
AppServerEvent::ThreadStreamReconnected(_)
|
AppServerEvent::CloudInventoryChanged(_)
|
||||||
|
| AppServerEvent::ThreadStreamReconnected(_)
|
||||||
| AppServerEvent::ThreadStreamDisconnected(_)
|
| AppServerEvent::ThreadStreamDisconnected(_)
|
||||||
| AppServerEvent::Lagged { .. }
|
| AppServerEvent::Lagged { .. }
|
||||||
| AppServerEvent::ServerRequest(_) => {}
|
| AppServerEvent::ServerRequest(_) => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user