Refactor AmbientAgentViewModel to handle follow-up run executions.#9316
Refactor AmbientAgentViewModel to handle follow-up run executions.#9316
Conversation
004a070 to
6c976cb
Compare
0cf8a89 to
318f8b9
Compare
9f26d7d to
7ebd2fc
Compare
318f8b9 to
184e5a8
Compare
7ebd2fc to
73f4edc
Compare
184e5a8 to
0440a49
Compare
73f4edc to
c7794fd
Compare
0440a49 to
3d57414
Compare
3d57414 to
5fa260b
Compare
|
I'm starting a first review of this pull request. I completed the review and posted feedback on this pull request. Comment I completed the review and posted feedback on this pull request. Comment I completed the review and posted feedback on this pull request. Comment I completed the review and posted feedback on this pull request. Comment You can view the conversation on Warp. I completed the review and posted feedback on this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR refactors ambient agent spawning into reusable run polling, adds a follow-up submission path, and wires the ambient view model/terminal manager to recognize follow-up execution sessions.
Concerns
- The terminal manager bookkeeping block does not compile because it treats
ambient_agent_view_model()as optional and calls.cloned()on aModelHandlereference. - Follow-up polling uses
previous_session_idas the only signal that the stream is handling a follow-up; when the previous session is unknown, terminal states or session links without parsed IDs can end the stream without transitioning the model out ofWaitingForSession. - Security pass found no diff-tied security findings.
Verdict
Found: 1 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
There was a problem hiding this comment.
Overview
This PR refactors ambient agent startup polling into reusable run polling, adds a follow-up submission path on AmbientAgentViewModel, records ended execution session IDs, and wires the new follow-up dispatch/readiness events through the cloud-mode viewer.
Concerns
- Follow-up submissions can proceed without a recorded previous session ID, which lets the poller accept the still-published stale session as the new execution session for existing/reopened ambient sessions.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| .clone() | ||
| .or_else(|| self.last_ended_execution_session_id.clone()); | ||
| let ai_client = ServerApiProvider::as_ref(ctx).get_ai_client(); | ||
| let stream = submit_run_followup(prompt, task_id, previous_session_id, ai_client, None); |
There was a problem hiding this comment.
previous_session_id can be None for existing/reopened ambient sessions because active_execution_session_id is only set by spawn/attach paths and last_ended_execution_session_id is only populated if this model observed the session end; in that case submit_run_followup treats the old session as immediately joinable, so the follow-up can reattach the dead VM instead of waiting for a fresh execution. Record the joined session ID when entering an existing session or block follow-up submission until a previous session ID is known.
There was a problem hiding this comment.
addressing in follow-up
c7794fd to
a488b58
Compare
5fa260b to
7abe5b4
Compare
757d5b5 to
61b3a3c
Compare
7abe5b4 to
36a1eac
Compare
36a1eac to
cb69d57
Compare
61b3a3c to
9e0ab1e
Compare
9e0ab1e to
5762baa
Compare
cb69d57 to
a9e2039
Compare
d4e99a0 to
bf8c47e
Compare
There was a problem hiding this comment.
Overview
This PR refactors ambient agent spawning into reusable run polling and adds a follow-up execution path through the ambient view model, plus session-ended bookkeeping and stream tests.
Concerns
- Follow-up submission currently uses the ambient task ID instead of the run ID returned by spawn, so the follow-up endpoint can target the wrong run when those IDs diverge.
- Follow-up polling can emit
SessionStartedwithout a parsedSessionIdwhen no previous session ID is known; the model ignores that event and the UI remains stuck waiting because the stream has ended. - Security pass: no security-specific issues found in the inlined diff.
Verdict
Found: 0 critical, 2 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| .active_execution_session_id | ||
| .or(self.last_ended_execution_session_id); | ||
| let ai_client = ServerApiProvider::as_ref(ctx).get_ai_client(); | ||
| let stream = submit_run_followup(prompt, task_id, previous_session_id, ai_client, None); |
There was a problem hiding this comment.
agent/runs/{task_id} because only self.task_id is stored, but spawn_agent returns a distinct run_id; store the run ID from TaskSpawned and use it here so follow-ups attach to the existing run when IDs diverge.
There was a problem hiding this comment.
task_id and run_id are the same thing
| let has_new_session = match &mode { | ||
| RunPollMode::InitialRun | ||
| | RunPollMode::Followup { | ||
| previous_session_id: None, | ||
| } => true, | ||
| RunPollMode::Followup { | ||
| previous_session_id: Some(previous_session_id), | ||
| } => session_join_info | ||
| .session_id | ||
| .as_ref() | ||
| .is_some_and(|session_id| session_id != previous_session_id), | ||
| }; |
There was a problem hiding this comment.
handle_ambient_agent_event ignores SessionStarted without a SessionId, so the follow-up stream ends while the UI stays in WaitingForSession. Require a parsed session ID for all follow-up readiness.
| let has_new_session = match &mode { | |
| RunPollMode::InitialRun | |
| | RunPollMode::Followup { | |
| previous_session_id: None, | |
| } => true, | |
| RunPollMode::Followup { | |
| previous_session_id: Some(previous_session_id), | |
| } => session_join_info | |
| .session_id | |
| .as_ref() | |
| .is_some_and(|session_id| session_id != previous_session_id), | |
| }; | |
| let has_new_session = match &mode { | |
| RunPollMode::InitialRun => true, | |
| RunPollMode::Followup { | |
| previous_session_id: None, | |
| } => session_join_info.session_id.is_some(), | |
| RunPollMode::Followup { | |
| previous_session_id: Some(previous_session_id), | |
| } => session_join_info | |
| .session_id | |
| .as_ref() | |
| .is_some_and(|session_id| session_id != previous_session_id), | |
| }; |
bf8c47e to
560ca94
Compare
There was a problem hiding this comment.
Overview
This PR refactors ambient agent startup polling to support follow-up run executions, adds model state for initial vs follow-up session startup, and wires follow-up readiness through the existing shared-session hotswap path.
Concerns
submit_cloud_followupcan be called while the model is already waiting for a session, which leaves multiple follow-up streams active and allows an older success or later error to overwrite the current status/session.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
560ca94 to
3db61ca
Compare
There was a problem hiding this comment.
Overview
This PR refactors ambient agent spawning to add follow-up run submission/polling, tracks initial-vs-follow-up session startup in the ambient view model, and wires follow-up session readiness into the existing shared-session hotswap path.
Concerns
- The follow-up model method can submit without any recorded active or ended session ID; in that case polling accepts any joinable session on the run, including the stale/dead session it is supposed to ignore.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| return; | ||
| }; | ||
|
|
||
| let previous_session_id = self |
There was a problem hiding this comment.
previous_session_id can be None if the model missed or never recorded the active/ended execution, and then follow-up polling accepts the run's existing joinable session as fresh; require a recorded previous session (or fail visibly) before submitting so hotswap cannot reconnect to the stale/dead session.
There was a problem hiding this comment.
this comment doesn't make sense
3db61ca to
036037d
Compare
036037d to
7c1b05f
Compare
over-aggressive requesting changes

Description
Update data model to support triggering a follow-up execution on an existing ambient agent conversation with a dead VM.
AmbientAgentViewModelto understand run executionsFixes APP-4320