Skip to content

feat(acp): keep the agent of a conversation open in a tab - #1268

Open
Mistic92 wants to merge 2 commits into
spacering-net:mainfrom
Mistic92:feat/open-tabs-keep-agents
Open

Mistic92 wants to merge 2 commits into
spacering-net:mainfrom
Mistic92:feat/open-tabs-keep-agents

Conversation

@Mistic92

@Mistic92 Mistic92 commented Nov 21, 2026 •

Copy link
Copy Markdown

Closes #1237

Why

The idle sweep ends an idle agent that no client has touched for CODEG_ACP_IDLE_TIMEOUT_SECS (180 s). A client touches its connections only while its page is running. So the agent dies when a laptop goes to sleep, or when mobile Chrome freezes the page in the background, even though the conversation is still open in the tabs on every device. When the user picks it up on another device, the CLI starts again from scratch.

What changes

The sweep skips a connection whose conversation is open in a workspace tab. The open tab set is already stored on the server (opened_tab) and is shared by every client, so this does not depend on which device is looking.

  • tab_service::open_conversations returns the conversation ids of the open tabs, plus their agent sessions (agent_type + external_id). A connection binds its conversation only on its first prompt. A conversation that was opened from history and only read is therefore matched by its session, the same way lock_conversation_connections matches it.
  • ConnectionManager::sweep_idle_except(idle_timeout, &open) skips connections that are working on one of those conversations. This check runs after the existing teardown_blocker check. sweep_idle keeps its behaviour and calls it with an empty set.
  • idle_sweep_task gets the database connection and reads the set on every tick. If the read fails, the tick logs a warning and spares nothing, so the sweep works exactly as it does today.
  • Closing a tab removes the conversation from the set. Closing the tab of an idle agent still ends that agent right away, as it does today.
  • Conversations that are not open in a tab, automations, codeg-cli and one-shot runs keep the 180 s timeout.
  • Open tabs keep at most CODEG_ACP_OPEN_TAB_KEEP_MAX agents (default 3), the ones with the most recent activity. The others fall back to the idle timeout. Each kept agent is a whole process tree: one idle Claude Code session takes about 0.6–0.7 GB on Linux, about half of it in the stdio MCP servers each session starts. 0 turns the open-tab exemption off.

The timeout is unchanged. No frontend change.

Not covered: on mobile, switching to the file pane or to an overlay route unmounts the conversation view. The frontend then ends an idle owner's agent while its tab stays open. That is frontend unmount logic and is left for a separate change (see #1237).

Tests

  • manager: an idle connection bound to an open conversation is spared, and one bound to a closed conversation is swept. Once the tab is closed, the spared connection is swept too. A connection that has had no prompt yet is matched by its session, and only for the same agent.
  • manager: with more open tabs than the limit, the least recently active idle agents are swept, and a limit of 0 spares none.
  • conversations: open_conversations lists the conversations of pinned and preview tabs, ignores a draft tab with no conversation, and returns a session only for a conversation that has one. A conversation drops out when its tab is closed.

I have been running this, together with #1124, on my own server since Dec 4. The server lib tests pass on that build.

🤖 Generated with Claude Code

Mistic92 and others added 2 commits November 20, 2026 23:52
The idle sweep ended any idle agent no client had touched for 180 s.
A client touches only while its page runs, so a laptop going to sleep or
a phone with the browser in the background ended every idle agent, even
for conversations still open in the workspace tabs and picked up a
moment later on another device.

The open tab set already lives in the database and is shared by every
client. The sweep now reads it each tick and spares connections bound to
a conversation open in a tab. Closing the tab still ends an idle agent
right away, and everything else (closed or historical conversations,
automations, one-shot runs) keeps the timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every agent an open tab keeps is a process tree in memory (about
0.7-0.9 GB for Claude Code with its MCP servers). With many tabs open
that alone can fill a small server. Open tabs now keep at most
CODEG_ACP_OPEN_TAB_KEEP_MAX agents (default 3), the most recently
active ones; the others fall back to the idle timeout. 0 turns the
open-tab exemption off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Keep the agent of a conversation that is open in a tab

1 participant