Skip to content

Refactor AmbientAgentViewModel to handle follow-up run executions.#9316

Merged
zachbai merged 2 commits intomasterfrom
zb/add-execution-support-ambient-agent-model
May 1, 2026
Merged

Refactor AmbientAgentViewModel to handle follow-up run executions.#9316
zachbai merged 2 commits intomasterfrom
zb/add-execution-support-ambient-agent-model

Conversation

@zachbai
Copy link
Copy Markdown
Contributor

@zachbai zachbai commented Apr 28, 2026

Description

Update data model to support triggering a follow-up execution on an existing ambient agent conversation with a dead VM.

  • Updates AmbientAgentViewModel to understand run executions
  • Support spawning follow-up run execution for existing task/conversation and connecting to new shared session

Fixes APP-4320

@cla-bot cla-bot Bot added the cla-signed label Apr 28, 2026
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch from 004a070 to 6c976cb Compare April 28, 2026 22:56
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch 2 times, most recently from 0cf8a89 to 318f8b9 Compare April 28, 2026 22:59
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch 2 times, most recently from 9f26d7d to 7ebd2fc Compare April 28, 2026 23:08
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 318f8b9 to 184e5a8 Compare April 28, 2026 23:08
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch from 7ebd2fc to 73f4edc Compare April 28, 2026 23:36
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 184e5a8 to 0440a49 Compare April 28, 2026 23:36
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch from 73f4edc to c7794fd Compare April 28, 2026 23:41
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 0440a49 to 3d57414 Compare April 28, 2026 23:41
@zachbai zachbai requested a review from harryalbert April 28, 2026 23:46
@zachbai zachbai marked this pull request as ready for review April 28, 2026 23:46
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 3d57414 to 5fa260b Compare April 28, 2026 23:46
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Apr 28, 2026

@zachbai

I'm starting a first review of this pull request.

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

@harryalbert

You can view the conversation on Warp.

I completed the review and posted feedback on this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a ModelHandle reference.
  • Follow-up polling uses previous_session_id as 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 of WaitingForSession.
  • 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

Comment thread app/src/ai/ambient_agents/spawn.rs Outdated
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressing in follow-up

@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch from c7794fd to a488b58 Compare April 29, 2026 18:45
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 5fa260b to 7abe5b4 Compare April 29, 2026 18:45
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch 2 times, most recently from 757d5b5 to 61b3a3c Compare April 29, 2026 19:24
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 7abe5b4 to 36a1eac Compare April 29, 2026 19:25
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 36a1eac to cb69d57 Compare April 29, 2026 21:32
@zachbai zachbai force-pushed the zb/cloud-cloud-handoff-scaffolding branch from 61b3a3c to 9e0ab1e Compare April 29, 2026 21:32
@zachbai zachbai changed the base branch from zb/cloud-cloud-handoff-scaffolding to graphite-base/9316 April 29, 2026 21:53
@zachbai zachbai force-pushed the graphite-base/9316 branch from 9e0ab1e to 5762baa Compare April 29, 2026 21:53
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from cb69d57 to a9e2039 Compare April 29, 2026 21:53
@graphite-app graphite-app Bot changed the base branch from graphite-base/9316 to master April 29, 2026 21:54
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch 4 times, most recently from d4e99a0 to bf8c47e Compare April 30, 2026 17:23
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SessionStarted without a parsed SessionId when 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] This submits the follow-up to 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task_id and run_id are the same thing

Comment on lines +218 to +229
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),
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] For follow-ups with no previous session ID, this accepts link-only join info; 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.

Suggested change
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),
};

@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from bf8c47e to 560ca94 Compare April 30, 2026 18:25
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_followup can 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

Comment thread app/src/terminal/view/ambient_agent/model.rs
@harryalbert harryalbert force-pushed the zb/add-execution-support-ambient-agent-model branch from 560ca94 to 3db61ca Compare April 30, 2026 19:38
oz-for-oss[bot]
oz-for-oss Bot previously requested changes Apr 30, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't make sense

@harryalbert harryalbert force-pushed the zb/add-execution-support-ambient-agent-model branch from 3db61ca to 036037d Compare April 30, 2026 22:43
@zachbai zachbai force-pushed the zb/add-execution-support-ambient-agent-model branch from 036037d to 7c1b05f Compare May 1, 2026 17:29
@zachbai zachbai dismissed oz-for-oss[bot]’s stale review May 1, 2026 17:54

over-aggressive requesting changes

@zachbai zachbai merged commit 6184f4e into master May 1, 2026
26 checks passed
@zachbai zachbai deleted the zb/add-execution-support-ambient-agent-model branch May 1, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants