`session.disconnect()` is cooperative; doesn't abort `sendAndWait` or close the transport
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- node.js, typescript
调研方向
从 nodejs/src/session.ts 开始,重点关注 disconnect()、abort()、sendAndWait() 以及它们对 MessageConnection 的使用。跟踪正在进行的请求和传输关闭是如何处理的,然后明确取消操作应当保留 session 的有效性,还是强制 teardown;当所选行为得到明确规定,并且正在进行的调用能够及时以干净的错误结束时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Summary
session.disconnect() sends session.destroy over RPC and clears local handlers, but does not close the underlying MessageConnection. Any in-flight sendAndWait() continues to await events from the CLI for up to TCP-timeout duration. The method name implies abortive semantics; the behavior is cooperative signaling.
Repro
const client = new CopilotClient();
await client.start();
const session = await client.createSession({ /* ... */ });
// Start a long-running call
const inflight = session.sendAndWait({ prompt: "Write a very long story..." });
// Try to abort after 5 seconds
setTimeout(async () => {
await session.disconnect();
console.log("disconnect() returned");
}, 5000);
// `inflight` does NOT reject after disconnect returns; it continues to
// pend for up to 30–90 minutes (until the CLI's natural completion or
// TCP timeout).
await inflight;
Expected
disconnect() returns → underlying transport closed → in-flight sendAndWait() rejects with a clean SessionAborted (or similar) error → consumer can release resources immediately.
Actual
disconnect() returns immediately but the JSON-RPC transport stays open. The in-flight sendAndWait() is unaffected and continues running until the CLI naturally returns or TCP times out (often 30+ minutes).
Evidence (SDK source)
nodejs/src/session.ts (v0.3.0): disconnect() calls sendRequest("session.destroy", { sessionId }) and clears local eventHandlers. No call to connection.close() or transport-level termination. session.abort() (same file, line ~1073) sends session.abort to cancel the current message at the CLI but also doesn't close the SDK-side transport.
Workaround (consumer-side)
Layer an AbortController on the polling layer plus a "session result ignored" flag so the eventually-resolving sendAndWait doesn't pollute downstream state. ~50–100 LOC of scaffolding that every consumer with reliability requirements has to reinvent.
Suggested fix (pick one)
- Enhance
abort()to also reject in-flightsendAndWaitwith a cleanSessionAbortederror, preserving session validity for new messages. Suits "cancel and retry" consumers. - Add
session.disconnect({ force: true })(orsession.kill()) that closes the underlying JSON-RPC connection immediately. Suits "tear down for good" consumers — the watchdog scenario above. Keep current cooperativedisconnect()behavior as the default.
Related
- #590 — "Long-running prompt suddenly hangs forever with no error or exception" — describes the symptom from the consumer side. The disconnect-doesn't-abort behavior is one mechanism that contributes to this symptom: even when the consumer notices the hang and tries to recover,
disconnect()doesn't free the in-flight call cleanly.
Environment
- SDK: @github/copilot-sdk@0.3.0
- CLI: @github/copilot@1.0.45
- Node: 22 LTS
- OS: Windows 11 (primary), macOS 14 (secondary)
- Model: claude-sonnet-4-6 (CLI default routing)
- 主要语言
- Java
- 星标
- 10.5k
- 派生
- 1.5k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 131
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/copilot-sdk 的其他 Issue
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 65/100
github/copilot-sdk#2760 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
github/copilot-sdk#2759 ·
-
documentation
难度 1/5 1 小时以内 新手友好度 85/100
github/copilot-sdk#2758 ·
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 68/100
github/copilot-sdk#2709 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 78/100
github/copilot-sdk#2673 ·
查看 github/copilot-sdk 的全部 Issue
相似的 Issue
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
apache/flink-agents#1152 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 70/100
jenkinsci/blueocean-plugin#5417 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
objectionary/eo-graphs#75 ·