Skip to content

Commit 4eb0f51

Browse files
committed
fix: harden thread status probe fallback and retry list
1 parent 83c24f2 commit 4eb0f51

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

packages/bridge-core/src/agent.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ export class BridgeAgent extends EventEmitter {
10201020
if (statuses.some((status) => status === 'queued' || status === 'pending')) {
10211021
return 'queued';
10221022
}
1023-
if (statuses.some((status) => status === 'completed' || status === 'failed' || status === 'cancelled' || status === 'canceled')) {
1023+
if (statuses.some((status) => status === 'completed' || status === 'failed' || status === 'cancelled' || status === 'canceled' || status === 'interrupted')) {
10241024
return 'idle';
10251025
}
10261026
return 'unknown';
@@ -1048,16 +1048,24 @@ export class BridgeAgent extends EventEmitter {
10481048

10491049
for (let i = 0; i < toProbe.length; i += THREAD_STATUS_PROBE_BATCH_SIZE) {
10501050
const batch = toProbe.slice(i, i + THREAD_STATUS_PROBE_BATCH_SIZE);
1051-
const settled = await Promise.allSettled(
1051+
const settled = await Promise.all(
10521052
batch.map(async (thread) => {
1053-
const snapshot = await this.fetchThreadConversationSnapshot(thread.id);
1054-
return { threadId: thread.id, taskState: this.inferThreadTaskStateFromSnapshot(snapshot) };
1053+
try {
1054+
const snapshot = await this.fetchThreadConversationSnapshot(thread.id);
1055+
return { threadId: thread.id, taskState: this.inferThreadTaskStateFromSnapshot(snapshot) as ThreadTaskState };
1056+
} catch (error: any) {
1057+
this.logger.warn('Thread status probe failed; falling back to idle', {
1058+
threadId: thread.id,
1059+
error: error?.message || String(error),
1060+
});
1061+
return { threadId: thread.id, taskState: 'idle' as ThreadTaskState };
1062+
}
10551063
}),
10561064
);
10571065

10581066
for (const item of settled) {
1059-
if (item.status === 'fulfilled') {
1060-
states.set(item.value.threadId, item.value.taskState);
1067+
if (item.threadId) {
1068+
states.set(item.threadId, item.taskState);
10611069
}
10621070
}
10631071
}
@@ -1633,11 +1641,23 @@ export class BridgeAgent extends EventEmitter {
16331641
}
16341642

16351643
private async handleThreadsCommand(event: IncomingControlCommandEvent): Promise<void> {
1636-
const threads = await withTimeout(
1637-
this.listThreads(THREAD_LIST_LIMIT),
1638-
Math.min(this.options.requestTimeoutMs, 12_000),
1639-
'thread/list',
1640-
);
1644+
let threads: ThreadSummary[] = [];
1645+
try {
1646+
threads = await withTimeout(
1647+
this.listThreads(THREAD_LIST_LIMIT),
1648+
Math.min(this.options.requestTimeoutMs, 12_000),
1649+
'thread/list',
1650+
);
1651+
} catch (firstError: any) {
1652+
this.logger.warn('thread/list fast path failed, retrying once with longer timeout', {
1653+
error: firstError?.message || String(firstError),
1654+
});
1655+
threads = await withTimeout(
1656+
this.listThreads(THREAD_LIST_LIMIT),
1657+
Math.max(this.options.requestTimeoutMs, 25_000),
1658+
'thread/list(retry)',
1659+
);
1660+
}
16411661
if (threads.length === 0) {
16421662
this.emitFinal(event.chatId, event.messageId, this.t('当前没有可用会话。', 'No available threads found.'));
16431663
return;

0 commit comments

Comments
 (0)