Skip to content

bug(acp-bridge): closeSession + killSession use module-scoped channelInfo instead of channelInfoForEntry(entry) #4325

@doudouOUC

Description

@doudouOUC

Tracked as a follow-up to #4319 (F1) review thread — pre-existing bug in cli/src/serve/httpAcpBridge.ts that was preserved verbatim by the F1 lift into @qwen-code/acp-bridge/bridge. Filing here so the lift PR stays mechanical and the fix gets its own scope + tests.

Symptom

Both closeSession (now packages/acp-bridge/src/bridge.ts:~2127) and killSession (now ~3145) capture const ci = channelInfo — the module-scoped current attach target. Other session methods in the same file (setSessionApprovalMode at ~2617, requestSessionStatus at ~1255) correctly use channelInfoForEntry(entry), which searches aliveChannels for the entry's actual channel.

Failure mode

During channel overlap (A dying, B freshly spawned as channelInfo), closing a session on A:

  • Skips ci.sessionIds.delete() because B.channel !== entry.channel — the entry stays in A's sessionIds
  • Calls ci?.client.markSessionClosed() on B's client instead of A's
  • Evaluates the kill condition against B — if B has sessionIds.size === 0, B gets killed unnecessarily, forcing a third spawn

Why now

Pre-existing in httpAcpBridge.ts since the channel-overlap (BkUyD) bookkeeping landed. F1 just moved the code. But:

  • F1 makes the buggy method public API of @qwen-code/acp-bridge. Channels (packages/channels/base/AcpBridge.ts) and the VSCode IDE companion will consume it directly.
  • The inconsistency within the same file (some methods use channelInfoForEntry, two don't) is a maintenance trap.

Fix sketch

Two-line change in packages/acp-bridge/src/bridge.ts:

```diff

  •  const ci = channelInfo;
    
  •  const ci = channelInfoForEntry(entry);
    

```

at both closeSession and killSession sites. The deferred follow-up needs:

  1. The two-line change.
  2. A new test for the channel-overlap scenario (A dying + B fresh) that fails on the buggy version and passes on the fix.
  3. Verify the existing 174 httpAcpBridge.test.ts tests still pass (the bug only manifests during the narrow overlap window, so 99% of existing tests should be unaffected).

Refs

🤖 Generated with Qwen Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions