Skip to content

Commit 0ac090c

Browse files
jasonkeungoz-agent
andauthored
[REMOTE-1326] Link shared sessions to local interactive Oz runs (#9516)
## Description When Warp starts a shared agent session, we now link that shared session to the associated Oz run on the server. This enables the Oz run record to carry the replay session ID, so the session can be surfaced alongside the run. **How it works:** - In `TerminalManager`, when a shared session is created successfully, the Oz task ID is resolved from the active conversation's `task_id` (set when the first `StreamInit` response arrives). If found, `update_agent_task` is called to associate the shared session ID with the Oz run. - In the Oz webapp, the "View session" button links to the conversation, which then redirects to the session if there is one that is active. **Note on CLI agent runs (`warp agent run`):** In the CLI agent driver, the shared session is established *before* the first AI prompt is sent (`wait_for_session_shared()` completes at step 3 of `run_internal`, while the prompt is dispatched at step 5). This means `active_conversation()` returns `None` at link time and the session-to-task link is silently skipped for this path. A follow-up will address linking for CLI agent runs — possible approaches include deferring the link call until after the first prompt is sent, or re-introducing a read from `BlocklistAIController.ambient_agent_task_id` (which the driver sets before sharing begins). Implements [REMOTE-1326](https://linear.app/warpdotdev/issue/REMOTE-1326/link-shared-sessions-to-local-interactive-oz-runs). ## Testing Tested manually by running an in-app Oz agent session, sharing the terminal, and verifying the resulting Oz task record on the server has the shared session ID populated. No automated tests added: the linking path requires a live server round-trip (shared session creation + `update_agent_task`) and the happy-path success is silent by design; only failures are logged. ## Server API dependencies - [ ] Is this change necessary to make the client compatible with a desired server API breaking change? - [x] Does this change rely on a new server API? - [ ] Is this change enabling the use of a server API on client channels that rely on the production server? ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode ## Changelog Entries for Stable Co-Authored-By: Oz <oz-agent@warp.dev> --------- Co-authored-by: Oz <oz-agent@warp.dev>
1 parent a7279b3 commit 0ac090c

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎app/src/terminal/local_tty/terminal_manager.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ use super::recorder;
113113
use super::shell::ShellStarter;
114114
use super::{event_loop::EventLoop, shell::ShellStarterSource};
115115

116+
use crate::server::server_api::ServerApiProvider;
116117
#[cfg(unix)]
117118
use {
118119
super::terminal_attributes::TerminalAttributesPoller,
@@ -1296,6 +1297,15 @@ impl TerminalManager {
12961297
});
12971298
}
12981299

1300+
// Snapshot the conversation the user has selected at click time so the
1301+
// share is linked to that run, even if selection drifts before the
1302+
// server confirms session creation.
1303+
let selected_conversation_id = terminal_view
1304+
.as_ref(ctx)
1305+
.ai_context_model()
1306+
.as_ref(ctx)
1307+
.selected_conversation_id(ctx);
1308+
12991309
let active_prompt = if *SessionSettings::as_ref(ctx).honor_ps1 {
13001310
ActivePrompt::PS1
13011311
} else {
@@ -1484,6 +1494,40 @@ impl TerminalManager {
14841494
if FeatureFlag::AgentSharedSessions.is_enabled() {
14851495
Self::stream_historical_agent_conversations(&terminal_view, &model, ctx);
14861496
}
1497+
1498+
let session_id_for_link = *session_id;
1499+
1500+
// Read task_id lazily so we still pick up a server-assigned
1501+
// task_id that arrived after the user clicked share.
1502+
let task_id = selected_conversation_id.and_then(|conversation_id| {
1503+
BlocklistAIHistoryModel::as_ref(ctx)
1504+
.conversation(&conversation_id)
1505+
.and_then(|c| c.task_id())
1506+
});
1507+
1508+
if let Some(task_id) = task_id {
1509+
let ai_client = ServerApiProvider::as_ref(ctx).get_ai_client();
1510+
terminal_view.update(ctx, |_view, ctx| {
1511+
ctx.spawn(
1512+
async move {
1513+
ai_client
1514+
.update_agent_task(
1515+
task_id,
1516+
None,
1517+
Some(session_id_for_link),
1518+
None,
1519+
None,
1520+
)
1521+
.await
1522+
},
1523+
move |_view, result, _ctx| {
1524+
if let Err(e) = result {
1525+
log::warn!("Failed to link shared session to Oz task: {e}");
1526+
}
1527+
},
1528+
);
1529+
});
1530+
}
14871531
}
14881532
NetworkEvent::FailedToCreateSharedSession {
14891533
reason,

0 commit comments

Comments
 (0)