Skip to content

fix(acp): remove a new session on close if it was never prompted - #56088

Open
bercedev wants to merge 1 commit into
anomalyco:devfrom
bercedev:fix/acp-discard-unused-session
Open

bercedev wants to merge 1 commit into
anomalyco:devfrom
bercedev:fix/acp-discard-unused-session

Conversation

@bercedev

@bercedev bercedev commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #55293

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

newSession in packages/cli/src/acp/service.ts saves the session right away, and closeSession only stopped and detached it. A client that opens a session and closes it without prompting leaves an empty New session - <ISO> behind, and IDE integrations do this on every startup.

closeSession now removes the session when all of these hold:

  • this ACP process created it with session/new
  • it was never prompted through this process
  • the server has no messages for it, in case another client of the same server used it

Loaded, resumed and forked sessions are never removed, and neither is anything with messages. If removing fails, it logs a warning and the close still succeeds.

This covers the bot's reproduction and any client that closes what it opens. It doesn't cover a process that is killed without session/close. That needs either a sweep before opencode acp exits (the handler currently calls process.exit without closing scopes) or deferring persistence until the first prompt, as the issue suggests. I kept this to the close path. Happy to do either as a follow-up if you want one.

How did you verify your code works?

  • New test in packages/cli/test/acp/session.test.ts: after session/close, an unprompted new session is gone, while a prompted one, one with messages from elsewhere and a loaded one are kept. It fails on dev. The existing close/delete test in prompt.test.ts still passes.
  • Ran the bot's steps against opencode acp from source, in a container with no network: session/new then session/close three times, then session/list from a new opencode acp process.
    • dev: 3 sessions (New session - 2026-10-16T13:51:07.727Z, …)
    • This branch: 0 sessions
  • bun test in packages/cli: 323 pass, 8 fail. The same 8 fail on clean dev in my container (the service and acp lifecycle subprocess tests).
  • tsgo -b in packages/cli is clean. Prettier is clean.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #54478

session/new saves the session right away, and session/close only detached
it, so every client that opens a session and never prompts leaves an empty
"New session" behind. IDE integrations do this on every startup, and the
stubs pile up in the session list.

Close now removes a session this process created with session/new when it
was never prompted here and the server has no messages for it. Loaded,
resumed and forked sessions, and anything with messages, are left alone.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

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.

Looks good. I ran the reproduction from #55293 from source. On the base, three session/new + session/close runs left 3 empty New session - <ISO> sessions. With this change, a fresh session/list returns none. The new test fails on the base and passes here, the existing ACP session and prompt tests pass, and tsgo -b reports no errors in packages/cli.

Public API: unchanged. session/close still returns {}; the only change is that an unused session created by this process is removed on the server.

The guards look right: only sessions created with session/new in this process are removed; prompt and delete take them out of the set; the server is asked for messages first, so a session used by another client is kept; loaded, resumed and forked sessions are never touched; and if removal fails, the close still succeeds. The limitation you describe (a process killed without session/close) seems reasonable to leave for a follow-up.

Related: #54478

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

acp: eagerly persisted empty sessions still accumulate in v2 (IDE integrations) — cleanup never happens

1 participant