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

推荐订阅源

月光博客
月光博客
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
H
Help Net Security
小众软件
小众软件
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
爱范儿
爱范儿
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
博客园 - 【当耐特】
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
博客园_首页
Jina AI
Jina AI
D
Docker
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志

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(gateway): tighten session delivery recovery · opencla...
fuller-stack · 2026-04-25 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -72,7 +72,7 @@ export function isSessionDeliveryEligibleForRetry(

7272

entry: QueuedSessionDelivery,

7373

now: number,

7474

): { eligible: true } | { eligible: false; remainingBackoffMs: number } {

75-

const backoff = computeSessionDeliveryBackoffMs(entry.retryCount + 1);

75+

const backoff = computeSessionDeliveryBackoffMs(entry.retryCount);

7676

if (backoff <= 0) {

7777

return { eligible: true };

7878

}

Original file line numberDiff line numberDiff line change

@@ -7,6 +7,7 @@ import { generateSecureUuid } from "./secure-random.js";

77
88

const QUEUE_DIRNAME = "session-delivery-queue";

99

const FAILED_DIRNAME = "failed";

10+

const TMP_SWEEP_MAX_AGE_MS = 5_000;

1011
1112

export type SessionDeliveryContext = {

1213

channel?: string;

@@ -71,6 +72,23 @@ async function unlinkBestEffort(filePath: string): Promise<void> {

7172

}

7273

}

7374
75+

async function unlinkStaleTmpBestEffort(filePath: string, now: number): Promise<void> {

76+

try {

77+

const stat = await fs.promises.stat(filePath);

78+

if (!stat.isFile()) {

79+

return;

80+

}

81+

if (now - stat.mtimeMs < TMP_SWEEP_MAX_AGE_MS) {

82+

return;

83+

}

84+

await unlinkBestEffort(filePath);

85+

} catch (err) {

86+

if (getErrnoCode(err) !== "ENOENT") {

87+

throw err;

88+

}

89+

}

90+

}

91+
7492

async function writeQueueEntry(filePath: string, entry: QueuedSessionDelivery): Promise<void> {

7593

const tmp = `${filePath}.${process.pid}.tmp`;

7694

await fs.promises.writeFile(tmp, JSON.stringify(entry, null, 2), {

@@ -205,9 +223,12 @@ export async function loadPendingSessionDeliveries(

205223

throw err;

206224

}

207225
226+

const now = Date.now();

208227

for (const file of files) {

209-

if (file.endsWith(".delivered") || file.endsWith(".tmp")) {

228+

if (file.endsWith(".delivered")) {

210229

await unlinkBestEffort(path.join(queueDir, file));

230+

} else if (file.endsWith(".tmp")) {

231+

await unlinkStaleTmpBestEffort(path.join(queueDir, file), now);

211232

}

212233

}

213234
Original file line numberDiff line numberDiff line change

@@ -2,6 +2,8 @@ import { describe, expect, it, vi } from "vitest";

22

import { withTempDir } from "../test-helpers/temp-dir.js";

33

import {

44

enqueueSessionDelivery,

5+

failSessionDelivery,

6+

isSessionDeliveryEligibleForRetry,

57

loadPendingSessionDeliveries,

68

recoverPendingSessionDeliveries,

79

} from "./session-delivery-queue.js";

@@ -115,4 +117,35 @@ describe("session-delivery queue recovery", () => {

115117
116118

vi.useRealTimers();

117119

});

120+
121+

it("uses the persisted retryCount for the first backoff tier", async () => {

122+

vi.useFakeTimers();

123+

vi.setSystemTime(new Date("2026-04-23T00:00:00.000Z"));

124+
125+

await withTempDir({ prefix: "openclaw-session-delivery-" }, async (tempDir) => {

126+

const id = await enqueueSessionDelivery(

127+

{

128+

kind: "systemEvent",

129+

sessionKey: "agent:main:main",

130+

text: "retry me",

131+

},

132+

tempDir,

133+

);

134+

await failSessionDelivery(id, "transient failure", tempDir);

135+
136+

const [failedEntry] = await loadPendingSessionDeliveries(tempDir);

137+

expect(failedEntry).toBeDefined();

138+

expect(failedEntry?.retryCount).toBe(1);

139+

expect(failedEntry?.lastAttemptAt).toBeDefined();

140+
141+

const lastAttemptAt = failedEntry?.lastAttemptAt ?? 0;

142+

const notReady = isSessionDeliveryEligibleForRetry(failedEntry, lastAttemptAt + 4_999);

143+

expect(notReady).toEqual({ eligible: false, remainingBackoffMs: 1 });

144+
145+

const ready = isSessionDeliveryEligibleForRetry(failedEntry, lastAttemptAt + 5_000);

146+

expect(ready).toEqual({ eligible: true });

147+

});

148+
149+

vi.useRealTimers();

150+

});

118151

});

Original file line numberDiff line numberDiff line change

@@ -72,10 +72,24 @@ describe("session-delivery queue storage", () => {

7272

);

7373

const tmpPath = path.join(resolveSessionDeliveryQueueDir(tempDir), "orphan-entry.tmp");

7474

fs.writeFileSync(tmpPath, "stale tmp");

75+

const staleAt = new Date(Date.now() - 60_000);

76+

fs.utimesSync(tmpPath, staleAt, staleAt);

7577
7678

await loadPendingSessionDeliveries(tempDir);

7779
7880

expect(fs.existsSync(tmpPath)).toBe(false);

7981

});

8082

});

83+
84+

it("keeps fresh temporary queue files while a write may still be in flight", async () => {

85+

await withTempDir({ prefix: "openclaw-session-delivery-" }, async (tempDir) => {

86+

const tmpPath = path.join(resolveSessionDeliveryQueueDir(tempDir), "active-entry.tmp");

87+

fs.mkdirSync(path.dirname(tmpPath), { recursive: true });

88+

fs.writeFileSync(tmpPath, "active tmp");

89+
90+

await loadPendingSessionDeliveries(tempDir);

91+
92+

expect(fs.existsSync(tmpPath)).toBe(true);

93+

});

94+

});

8195

});