Skip to content

Commit d9afbce

Browse files
lishuceoclaude
andauthored
fix: 收到 result 后立即跳出消息循环,避免 idle timeout 误报 (#258)
* fix: 收到 result 后立即跳出消息循环,避免 idle timeout 误报 问题:SDK 返回 result 消息后,如果有 background task 仍在运行, for-await 循环不会结束,导致 idle timer 继续倒计时最终触发超时。 实际查询已经成功完成,不应该报超时。 修复:用 labeled break 在收到 result 后立即跳出循环, 并调用 q.close() 确保子进程不泄漏。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: settingSources 加入 'local' 以加载 settings.local.json 权限白名单 问题:urhox-bench 的 .claude/settings.local.json 包含完整的 bash 命令 白名单(git/npm/npx/gh 等),但 SDK 只传了 ['user', 'project'], 'local' 未包含,导致这些权限不生效。SDK 弹窗请求授权时飞书 bot 无法交互,报 "Stream closed"。 修复:settingSources 加入 'local',优先级:user < project < local。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7107288 commit d9afbce

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/claude/executor.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,8 @@ export class ClaudeExecutor {
946946
: { type: 'preset', preset: 'claude_code', append: promptAppend },
947947

948948
// 加载项目设置 (CLAUDE.md 等);路由 agent 传 [] 避免加载
949-
settingSources: settingSourcesOverride ?? ['user', 'project'],
949+
// 'local' 加载 .claude/settings.local.json(优先级最高,覆盖 project)
950+
settingSources: settingSourcesOverride ?? ['user', 'project', 'local'],
950951

951952
// MCP 服务器:工作区管理工具 + 飞书工具 (空对象等同于无 MCP 服务器)
952953
mcpServers: Object.keys(mcpServers).length > 0 ? mcpServers : undefined,
@@ -984,7 +985,8 @@ export class ClaudeExecutor {
984985

985986
try {
986987
// 遍历 SDK 流式消息
987-
for await (const message of q) {
988+
// label 用于在收到 result 后跳出循环(result 是 SDK 协议的终止消息)
989+
messageLoop: for await (const message of q) {
988990
// 每收到消息重置 idle 计时器
989991
resetIdleTimer(`msg:${message.type}${'subtype' in message ? ':' + (message as Record<string, unknown>).subtype : ''}`);
990992

@@ -1123,7 +1125,7 @@ export class ClaudeExecutor {
11231125

11241126
case 'result':
11251127
resultMessage = message;
1126-
break;
1128+
break messageLoop;
11271129

11281130
default:
11291131
// tool_progress, stream_event 等其他消息类型 — 记录以便诊断 idle timeout 间隙
@@ -1132,6 +1134,10 @@ export class ClaudeExecutor {
11321134
break;
11331135
}
11341136
}
1137+
1138+
// 提前 break(收到 result)时子进程可能仍在运行(如有 background task),
1139+
// 主动 close 确保不泄漏;正常迭代结束时 close 是幂等的 no-op
1140+
q.close();
11351141
} catch (err) {
11361142
clearTimeout(idleTimer);
11371143
if (hardTimer) clearTimeout(hardTimer);

0 commit comments

Comments
 (0)