Skip to content

feat: make v2 close_agent interrupt only#26612

Open
jif-oai wants to merge 1 commit into
jif/agent-residency-runtimefrom
jif/v2-agent-tool-semantics
Open

feat: make v2 close_agent interrupt only#26612
jif-oai wants to merge 1 commit into
jif/agent-residency-runtimefrom
jif/v2-agent-tool-semantics

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented Jun 5, 2026

Summary

Updates V2 agent tool semantics so close_agent only interrupts the target agent instead of recursively closing spawned descendants. This keeps V2 task paths and residency behavior intact while making close behavior explicit and less destructive.

Changes

  • Change V2 close_agent to interrupt only the selected agent.
  • Keep root/self-target rejection behavior for V2 close requests.
  • Document list_agents as resident-only for V2.
  • Document follow-up concurrency failure behavior.
  • Update focused V2 handler and integration coverage for close/list/follow-up behavior.

Stack

  1. refactor: split agent control modules #26610 - Mechanical AgentControl split: extracts spawn and V1 legacy code without behavior changes.
  2. feat: add agent execution slot accounting #26614 - Execution slot accounting: separates logical agents from active execution slots.
  3. feat: add agent residency reload runtime #26611 - Residency and reload runtime: adds resident-agent LRU, eviction/reload, durable lookup, and V2 delivery through reload.
  4. This PR - V2 tool semantics: narrows close_agent to interrupt-only and updates V2 tool coverage.

Copy link
Copy Markdown
Contributor

@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.

Reviewed commit: 99d019708d

ℹ️ 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 thread codex-rs/core/src/tools/handlers/multi_agents_v2/close_agent.rs
.await;
return Err(collab_agent_error(agent_id, err));
}
Ok(_) | Err(CodexErr::ThreadNotFound(_)) | Err(CodexErr::InternalAgentDied) => Ok(()),
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.

P2 Badge Report unloaded close_agent success consistently

When the target is an open-but-unloaded V2 task name, get_status() above returns NotFound and this arm still returns Ok(()); the tool output is successful, but the emitted CollabCloseEnd carries NotFound, which app-server maps to CollabAgentToolCallStatus::Failed in codex-rs/app-server-protocol/src/protocol/event_mapping.rs. In app-server clients this makes the same successful close/interrupt appear as a failed tool call, so use a non-failure event status or adjust the event mapping for this accepted unloaded-agent case.

Useful? React with 👍 / 👎.

ToolSpec::Function(ResponsesApiTool {
name: "close_agent".to_string(),
description: "Close an agent and any open descendants when they are no longer needed, and return the target agent's previous status before shutdown was requested. Idle agents do not count toward the concurrency limit.".to_string(),
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.".to_string(),
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.

P2 Badge Update close_agent presentation for interrupt semantics

This changes V2 close_agent to leave the agent available after only interrupting the current turn, but downstream rendering still treats every completed CloseAgent item as a close: for example codex-rs/tui/src/multi_agents.rs renders the title as Closed. In TUI/app-server-backed UIs, a user who interrupts a running V2 subagent will be told it was closed even though it remains resident and can still receive follow-up tasks, so the event/display semantics need to be updated alongside the new interrupt-only behavior.

Useful? React with 👍 / 👎.

.services
.agent_control
.subscribe_status(agent_id)
.interrupt_agent(agent_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.

P2 Badge Wait for the interrupt before completing close_agent

For a target that is actively running, interrupt_agent() only submits an Op::Interrupt to that thread's submission queue and returns the submission id; it does not wait for abort_all_tasks to run or for a TurnAborted status update. Because this handler immediately emits CollabCloseEnd and returns success, callers and UIs can observe close_agent as completed while the subagent is still executing tools/model work, which breaks the new interrupt semantics whenever the parent proceeds assuming the child has stopped.

Useful? React with 👍 / 👎.

@jif-oai jif-oai force-pushed the jif/agent-residency-runtime branch from 2f32ac2 to 6390bc7 Compare June 5, 2026 13:41
@jif-oai jif-oai force-pushed the jif/v2-agent-tool-semantics branch 2 times, most recently from af46ed6 to 79bec9b Compare June 5, 2026 13:54
@jif-oai jif-oai force-pushed the jif/agent-residency-runtime branch from 3287fc0 to cc46838 Compare June 5, 2026 14:05
@jif-oai jif-oai force-pushed the jif/v2-agent-tool-semantics branch from 79bec9b to d1e98a1 Compare June 5, 2026 14:05
@jif-oai jif-oai changed the title feat: make V2 close_agent interrupt-only feat: make v2 close_agent interrupt only Jun 5, 2026
@jif-oai jif-oai force-pushed the jif/agent-residency-runtime branch from cc46838 to 0ae3083 Compare June 5, 2026 14:22
@jif-oai jif-oai force-pushed the jif/v2-agent-tool-semantics branch from d1e98a1 to 83bbc0d Compare June 5, 2026 14:23
jif-oai added a commit that referenced this pull request Jun 5, 2026
## Summary

Mechanically splits `AgentControl` into focused modules so later agent
runtime changes are easier to review. The shared lookup, messaging, and
completion logic remains in `control.rs`, while spawn-specific code and
V1 legacy close/resume behavior move into dedicated files.

## Changes

- Extract spawn-agent code into `agent/control/spawn.rs`.
- Extract V1-only legacy close/resume behavior into
`agent/control/legacy.rs`.
- Keep shared control-plane behavior in `agent/control.rs`.
- Preserve existing behavior; this PR is intended to be mechanical.

## Stack

1. This PR - Mechanical `AgentControl` split: extracts spawn and V1
legacy code without behavior changes.
2. #26614 - Execution slot accounting: separates logical agents from
active execution slots.
3. #26611 - Residency and reload runtime: adds resident-agent LRU,
eviction/reload, durable lookup, and V2 delivery through reload.
4. #26612 - V2 tool semantics: narrows `close_agent` to interrupt-only
and updates V2 tool coverage.
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.

1 participant