Agent Host: let archive_chat mark the calling session Done after the turn ends
Summary
Let an agent mark the session it is running in as Done. Apply the archive when the current turn ends, the way set_workspace applies its change after the turn.
This is the agent-tool counterpart of #292426, which asks for a Mark as Done button in the conversation for the user. It extends #344861 rather than repeating it.
Current behavior
#344861 added the archive_chat server tool. It archives another chat or session, and deliberately refuses the chat it runs in and the main session of its own session, so an agent cannot archive the conversation that is calling it. That refusal makes sense for an immediate archive.
Problem
The most common time an agent should mark a session Done is at the end of that same session. A wrap-up workflow, such as a /done skill, checks for uncommitted work, stops helper processes, and summarizes follow-ups. Its last step is to mark the session Done, and that is the one step it cannot take: it has to ask the user to find the session in the Sessions list and click Mark as Done.
Proposal
When archive_chat targets the chat it runs in or its own session, schedule the archive instead of refusing:
- The tool result tells the model to end the turn, as
set_workspacedoes. - When the turn completes, the host archives the target with the same validation and side effects as archiving from the UI, including the worktree commit and cleanup for isolated sessions.
- If the turn fails or is cancelled, or a queued message is waiting to start another turn, the scheduled archive is dropped.
Archiving keeps history and can be undone, so this needs no more confirmation than archive_chat has today.
Alternatives considered
- Ask the user to click Mark as Done: works today, and is the extra step this request removes.
- Have a second session call
archive_chaton this one: leaves the second session needing the same click, and races the turn that is still running. delete_session: refuses the current session, cannot be undone, and removes history.
@sandy081, since you implemented archive_chat in #344861, would you be the right person to assess the proposed deferred self-archive, or could you suggest who should? Thanks!
Drafted with Copilot.