Skip to content

Conversation

@zemaj
Copy link

@zemaj zemaj commented Oct 29, 2025

Summary

  • cancel agent subprocesses when runs are stopped and avoid flipping cancelled agents to failed
  • cap agent backlog by pruning completed runs and trimming terminal view state
  • reuse bounded payload builder for status events so the TUI only sees active agents

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 376 to 387
pub async fn cancel_agent(&mut self, agent_id: &str) -> bool {
if let Some(token) = self.cancel_tokens.remove(agent_id) {
token.cancel();
}
if let Some(handle) = self.handles.remove(agent_id) {
handle.abort();
if let Some(agent) = self.agents.get_mut(agent_id) {
agent.status = AgentStatus::Cancelled;
agent.completed_at = Some(Utc::now());
}
self.prune_finished_agents();
true

Choose a reason for hiding this comment

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

P1 Badge Avoid aborting agent tasks before cancellation cleanup runs

The new cancellation flow creates CancellationTokens and teaches execute_cloud_built_in_streaming to kill the spawned child when the token is tripped, but cancel_agent still calls handle.abort() immediately after cancelling the token. Aborting the task drops the whole future before it can reach the tokio::select! that sends child.start_kill() and awaits the child, so the subprocess keeps running just as before. For a user that stops an agent run, the task is removed from the manager yet the external process continues executing in the background. To actually reap the child, let the task observe the cancellation token (or wait for the task to finish) instead of aborting it right away.

Useful? React with 👍 / 👎.

@github-actions
Copy link

Preview Build

You can run this right now! In your terminal just use:

code preview agents-cleanup

This will run the version of Code we've created for this issue.

Direct downloads:

After you run it, please comment here and let me know if it does what you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants