惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
A
About on SuperTechFans
量子位
Engineering at Meta
Engineering at Meta
B
Blog
The Cloudflare Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
J
Java Code Geeks
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(feishu): cap per-chat queue task wait so a single han...
martingarram · 2026-05-03 · via Recent Commits to openclaw:main

@@ -1,9 +1,50 @@

1-

export function createSequentialQueue() {

1+

/**

2+

* Per-key serial task queue for Feishu inbound message handling.

3+

*

4+

* Tasks enqueued under the same key run in FIFO order. Different keys run

5+

* concurrently. This preserves the channel's same-chat ordering contract

6+

* (see #64324) while letting cross-chat work proceed in parallel.

7+

*

8+

* `taskTimeoutMs` bounds how long the queue will block subsequent same-key

9+

* tasks behind a single in-flight task. After the cap, the in-flight task

10+

* is evicted from the blocking chain so newer messages for the same key

11+

* can proceed. The original task is NOT aborted — it continues running in

12+

* the background; it just stops starving the queue.

13+

*

14+

* Without this cap, a single hung dispatch (e.g. an agent call that never

15+

* resolves) keeps later same-chat messages in `queued` state until the

16+

* gateway is restarted. See #70133.

17+

*/

18+19+

const DEFAULT_TASK_TIMEOUT_MS = 5 * 60 * 1000;

20+21+

export interface SequentialQueueOptions {

22+

/**

23+

* Maximum time (ms) to block subsequent same-key tasks behind a single

24+

* in-flight task. Pass 0 (or a non-finite value) to disable the cap and

25+

* restore unbounded legacy behavior.

26+

*

27+

* Default: 5 minutes.

28+

*/

29+

taskTimeoutMs?: number;

30+31+

/**

32+

* Optional callback fired when a task exceeds `taskTimeoutMs`. The task

33+

* itself is not awaited further; this callback is the only signal the

34+

* caller gets that the queue moved on without it.

35+

*/

36+

onTaskTimeout?: (key: string, timeoutMs: number) => void;

37+

}

38+39+

export function createSequentialQueue(options: SequentialQueueOptions = {}) {

240

const queues = new Map<string, Promise<void>>();

41+

const taskTimeoutMs = options.taskTimeoutMs ?? DEFAULT_TASK_TIMEOUT_MS;

42+

const onTaskTimeout = options.onTaskTimeout;

343444

return (key: string, task: () => Promise<void>): Promise<void> => {

545

const previous = queues.get(key) ?? Promise.resolve();

6-

const next = previous.then(task, task);

46+

const wrapped = () => boundedRun(key, task, taskTimeoutMs, onTaskTimeout);

47+

const next = previous.then(wrapped, wrapped);

748

queues.set(key, next);

849

const cleanup = () => {

950

if (queues.get(key) === next) {

@@ -14,3 +55,30 @@ export function createSequentialQueue() {

1455

return next;

1556

};

1657

}

58+59+

async function boundedRun(

60+

key: string,

61+

task: () => Promise<void>,

62+

timeoutMs: number,

63+

onTaskTimeout: ((key: string, timeoutMs: number) => void) | undefined,

64+

): Promise<void> {

65+

if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {

66+

return task();

67+

}

68+

let timeoutHandle: ReturnType<typeof setTimeout> | undefined;

69+

const timeoutPromise = new Promise<void>((resolve) => {

70+

timeoutHandle = setTimeout(() => {

71+

try {

72+

onTaskTimeout?.(key, timeoutMs);

73+

} catch {

74+

// Swallow logging errors so they cannot poison the queue chain.

75+

}

76+

resolve();

77+

}, timeoutMs);

78+

});

79+

try {

80+

await Promise.race([task(), timeoutPromise]);

81+

} finally {

82+

if (timeoutHandle) clearTimeout(timeoutHandle);

83+

}

84+

}