Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_conversationsreturns 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 waylock_conversation_connectionsmatches it.ConnectionManager::sweep_idle_except(idle_timeout, &open)skips connections that are working on one of those conversations. This check runs after the existingteardown_blockercheck.sweep_idlekeeps its behaviour and calls it with an empty set.idle_sweep_taskgets 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.codeg-cliand one-shot runs keep the 180 s timeout.CODEG_ACP_OPEN_TAB_KEEP_MAXagents (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.0turns 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_conversationslists 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