Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/adapters/channel/feishu/FeishuChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class FeishuChannel implements ChannelAdapter {
if (!mapped.message) return;

if (this.activeChats.has(chatId)) {
this.logger?.info?.(`feishu: chat ${chatId} already active, skipping`);
await this.send({ chatId, text: "⏳ 上一次消息还在处理中,请稍等片刻再试。" });
return;
}

Expand All @@ -284,12 +284,21 @@ export class FeishuChannel implements ChannelAdapter {
let errorMessages = "";
let inToolCall = false;
try {
for await (const event of this.gateway.submitTurn({
sessionKey: mapped.sessionKey,
channelKey: "feishu",
message: mapped.message,
...(mapped.projectKey ? { projectKey: mapped.projectKey } : {}),
})) {
// 60s timeout prevents activeChats deadlock if LLM hangs
const timer = setTimeout(() => { throw new Error("submitTurn timeout 60s"); }, 60_000);
const collected: any[] = [];
try {
for await (const event of (this.gateway.submitTurn as any)({
sessionKey: mapped.sessionKey, channelKey: "feishu", message: mapped.message,
...(mapped.projectKey ? { projectKey: mapped.projectKey } : {}),
})) {
collected.push(event);
if (collected.length > 10000) break; // safety cap
}
} finally {
clearTimeout(timer);
}
for (const event of collected) {
switch (event.type) {
case "assistant_text_delta":
if (!inToolCall) lastTextSegment += event.text;
Expand Down Expand Up @@ -366,6 +375,7 @@ export class FeishuChannel implements ChannelAdapter {
}
} catch (e) {
this.logger?.error?.(`feishu: send threw: ${e}`);
throw e;
}
}

Expand Down
27 changes: 26 additions & 1 deletion src/mcp/client/McpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class McpClient {
private serverInstructions = "";
private connectPromise: Promise<void> | null = null;
private reconnectInFlight = false;

/** PID for process-group kill. -1 = not yet set. */
private _transportPid: number = -1;
private perSessionDir: string | null = null;

constructor(
Expand Down Expand Up @@ -168,12 +171,19 @@ export class McpClient {
this.perSessionDir = dir;
args = [...(args ?? []), `--user-data-dir=${dir}`];
}
return new StdioClientTransport({
const _transport = new StdioClientTransport({
command: this.spec.command,
args,
env: this.spec.env,
cwd: this.spec.cwd,
});
// Capture tsx PID immediately or on spawn event for process-group kill
const _t = _transport as any;
this._transportPid = _t.pid ?? -1;
if (this._transportPid === -1 && typeof _t.once === "function") {
_t.once("spawn", () => { this._transportPid = _t.pid ?? -1; });
}
return _transport;
}
if (this.spec.transport === "streamable_http") {
const url = new URL(this.spec.url);
Expand Down Expand Up @@ -343,6 +353,21 @@ export class McpClient {
try {
rmSync(this.perSessionDir, { recursive: true, force: true });
} catch { /* best effort cleanup */ }
// PATCH: kill entire process group BEFORE perSessionDir cleanup.
// Root cause: tsx does NOT forward SIGTERM → node → Chromium.
// Solution: kill(-pid, SIGKILL) wipes the whole tree atomically.
if (this._transportPid > 0) {
try {
process.kill(-this._transportPid, "SIGKILL");
} catch (e) {
if ((e as NodeJS.ErrnoException).code !== "ESRCH") {
// eslint-disable-next-line no-console
console.warn("[McpClient] process-group SIGKILL failed:", (e as Error).message);
}
}
this._transportPid = -1;
}

this.perSessionDir = null;
}
}
Expand Down