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

推荐订阅源

D
DataBreaches.Net
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
腾讯CDC
博客园 - Franky
Engineering at Meta
Engineering at Meta
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学

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(session): surface previous-transcript archive failure...
clawsweeper · 2026-05-23 · via Recent Commits to openclaw:main

@@ -1,16 +1,20 @@

11

import fs from "node:fs";

22

import os from "node:os";

33

import path from "node:path";

4-

import { afterEach, describe, expect, it } from "vitest";

4+

import { afterEach, describe, expect, it, vi } from "vitest";

55

import {

66

onSessionTranscriptUpdate,

77

type SessionTranscriptUpdate,

88

} from "../sessions/transcript-events.js";

9-

import { archiveFileOnDisk } from "./session-transcript-files.fs.js";

9+

import {

10+

archiveFileOnDisk,

11+

archiveSessionTranscriptsDetailed,

12+

} from "./session-transcript-files.fs.js";

10131114

const subscriptions: Array<() => void> = [];

12151316

afterEach(() => {

17+

vi.restoreAllMocks();

1418

while (subscriptions.length > 0) {

1519

subscriptions.pop()?.();

1620

}

@@ -65,3 +69,113 @@ describe("archiveFileOnDisk transcript updates", () => {

6569

}

6670

});

6771

});

72+73+

describe("archiveSessionTranscriptsDetailed failure surface", () => {

74+

it("invokes onArchiveError when fs.renameSync fails and returns only successful entries", () => {

75+

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "oc-archive-failure-"));

76+

try {

77+

const sessionId = "11111111-1111-4111-8111-111111111111";

78+

const sessionFile = path.join(tmpDir, `${sessionId}.jsonl`);

79+

fs.writeFileSync(sessionFile, '{"type":"session-meta","agentId":"main"}\n');

80+81+

const renameError = Object.assign(new Error("EACCES: permission denied"), {

82+

code: "EACCES",

83+

});

84+

const renameSpy = vi.spyOn(fs, "renameSync").mockImplementation(() => {

85+

throw renameError;

86+

});

87+88+

const errors: Array<{ err: unknown; sourcePath: string }> = [];

89+

const archived = archiveSessionTranscriptsDetailed({

90+

sessionId,

91+

storePath: path.join(tmpDir, "store.json"),

92+

sessionFile,

93+

agentId: "main",

94+

reason: "reset",

95+

onArchiveError: (err, sourcePath) => {

96+

errors.push({ err, sourcePath });

97+

},

98+

});

99+100+

renameSpy.mockRestore();

101+102+

expect(archived).toEqual([]);

103+

expect(errors.length).toBeGreaterThan(0);

104+

expect(errors[0].err).toBe(renameError);

105+

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

106+

} finally {

107+

fs.rmSync(tmpDir, { recursive: true, force: true });

108+

}

109+

});

110+111+

it("archives normally when no onArchiveError is provided", () => {

112+

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "oc-archive-success-"));

113+

try {

114+

const sessionId = "22222222-2222-4222-8222-222222222222";

115+

const sessionFile = path.join(tmpDir, `${sessionId}.jsonl`);

116+

fs.writeFileSync(sessionFile, '{"type":"session-meta","agentId":"main"}\n');

117+118+

const archived = archiveSessionTranscriptsDetailed({

119+

sessionId,

120+

storePath: path.join(tmpDir, "store.json"),

121+

sessionFile,

122+

agentId: "main",

123+

reason: "reset",

124+

});

125+126+

expect(archived.length).toBe(1);

127+

expect(archived[0].archivedPath).toContain(".jsonl.reset.");

128+

expect(fs.existsSync(archived[0].archivedPath)).toBe(true);

129+

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

130+

} finally {

131+

fs.rmSync(tmpDir, { recursive: true, force: true });

132+

}

133+

});

134+135+

it("surfaces real chmod archive failures through onArchiveError", () => {

136+

if (process.platform === "win32" || process.getuid?.() === 0) {

137+

return;

138+

}

139+140+

const tmpDir = fs.realpathSync(

141+

fs.mkdtempSync(path.join(os.tmpdir(), "oc-archive-real-eacces-")),

142+

);

143+

try {

144+

const sessionId = "33333333-3333-4333-8333-333333333333";

145+

const sessionFile = path.join(tmpDir, `${sessionId}.jsonl`);

146+

fs.writeFileSync(sessionFile, '{"type":"session-meta","agentId":"main"}\n');

147+

fs.chmodSync(tmpDir, 0o555);

148+149+

const errors: Array<{ code?: string; sourcePath: string }> = [];

150+

let archived: ReturnType<typeof archiveSessionTranscriptsDetailed> = [];

151+

try {

152+

archived = archiveSessionTranscriptsDetailed({

153+

sessionId,

154+

storePath: path.join(tmpDir, "store.json"),

155+

sessionFile,

156+

agentId: "main",

157+

reason: "reset",

158+

onArchiveError: (err, sourcePath) => {

159+

const code = (err as NodeJS.ErrnoException | undefined)?.code;

160+

errors.push({ code, sourcePath });

161+

},

162+

});

163+

} finally {

164+

fs.chmodSync(tmpDir, 0o755);

165+

}

166+167+

expect(archived).toEqual([]);

168+

expect(errors.length).toBeGreaterThan(0);

169+

expect(errors[0].sourcePath).toBe(sessionFile);

170+

expect(errors[0].code).toMatch(/^(EACCES|EPERM)$/);

171+

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

172+

} finally {

173+

try {

174+

fs.chmodSync(tmpDir, 0o755);

175+

} catch {

176+

// Already restored.

177+

}

178+

fs.rmSync(tmpDir, { recursive: true, force: true });

179+

}

180+

});

181+

});