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

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

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: clear phantom Claude CLI resumes (#70317) · openclaw...
steipete · 2026-04-23 · via Recent Commits to openclaw:main

@@ -9,6 +9,7 @@ import type { EmbeddedPiRunResult } from "../pi-embedded.js";

99

import { persistCliTurnTranscript, runAgentAttempt } from "./attempt-execution.js";

10101111

const runCliAgentMock = vi.hoisted(() => vi.fn());

12+

const ORIGINAL_HOME = process.env.HOME;

12131314

vi.mock("../cli-runner.js", () => ({

1415

runCliAgent: runCliAgentMock,

@@ -75,11 +76,28 @@ describe("CLI attempt execution", () => {

7576

});

76777778

afterEach(async () => {

79+

if (ORIGINAL_HOME === undefined) {

80+

delete process.env.HOME;

81+

} else {

82+

process.env.HOME = ORIGINAL_HOME;

83+

}

7884

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

7985

});

80868187

it("clears stale Claude CLI session IDs before retrying after session expiration", async () => {

8288

const sessionKey = "agent:main:subagent:cli-expired";

89+

const homeDir = path.join(tmpDir, "home");

90+

const projectsDir = path.join(homeDir, ".claude", "projects", "demo-workspace");

91+

process.env.HOME = homeDir;

92+

await fs.mkdir(projectsDir, { recursive: true });

93+

await fs.writeFile(

94+

path.join(projectsDir, "stale-cli-session.jsonl"),

95+

`${JSON.stringify({

96+

type: "assistant",

97+

message: { role: "assistant", content: [{ type: "text", text: "old reply" }] },

98+

})}\n`,

99+

"utf-8",

100+

);

83101

const sessionEntry: SessionEntry = {

84102

sessionId: "session-cli-123",

85103

updatedAt: Date.now(),

@@ -143,6 +161,144 @@ describe("CLI attempt execution", () => {

143161

expect(persisted[sessionKey]?.claudeCliSessionId).toBeUndefined();

144162

});

145163164+

it("does not pass --resume when the stored Claude CLI transcript is missing", async () => {

165+

const sessionKey = "agent:main:direct:claude-missing-transcript";

166+

const homeDir = path.join(tmpDir, "home");

167+

process.env.HOME = homeDir;

168+

const sessionEntry: SessionEntry = {

169+

sessionId: "openclaw-session-123",

170+

updatedAt: Date.now(),

171+

cliSessionBindings: {

172+

"claude-cli": {

173+

sessionId: "phantom-claude-session",

174+

authProfileId: "anthropic:claude-cli",

175+

},

176+

},

177+

cliSessionIds: { "claude-cli": "phantom-claude-session" },

178+

claudeCliSessionId: "phantom-claude-session",

179+

};

180+

const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };

181+

await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");

182+

runCliAgentMock.mockResolvedValueOnce(makeCliResult("fresh cli response"));

183+184+

await runAgentAttempt({

185+

providerOverride: "claude-cli",

186+

modelOverride: "opus",

187+

cfg: {} as OpenClawConfig,

188+

sessionEntry,

189+

sessionId: sessionEntry.sessionId,

190+

sessionKey,

191+

sessionAgentId: "main",

192+

sessionFile: path.join(tmpDir, "session.jsonl"),

193+

workspaceDir: tmpDir,

194+

body: "remember me",

195+

isFallbackRetry: false,

196+

resolvedThinkLevel: "medium",

197+

timeoutMs: 1_000,

198+

runId: "run-cli-missing-transcript",

199+

opts: { senderIsOwner: false } as Parameters<typeof runAgentAttempt>[0]["opts"],

200+

runContext: {} as Parameters<typeof runAgentAttempt>[0]["runContext"],

201+

spawnedBy: undefined,

202+

messageChannel: undefined,

203+

skillsSnapshot: undefined,

204+

resolvedVerboseLevel: undefined,

205+

agentDir: tmpDir,

206+

onAgentEvent: vi.fn(),

207+

authProfileProvider: "claude-cli",

208+

sessionStore,

209+

storePath,

210+

sessionHasHistory: false,

211+

});

212+213+

expect(runCliAgentMock).toHaveBeenCalledTimes(1);

214+

expect(runCliAgentMock.mock.calls[0]?.[0]?.cliSessionId).toBeUndefined();

215+

expect(runCliAgentMock.mock.calls[0]?.[0]?.cliSessionBinding).toBeUndefined();

216+

expect(sessionStore[sessionKey]?.cliSessionBindings?.["claude-cli"]).toBeUndefined();

217+

expect(sessionStore[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();

218+

expect(sessionStore[sessionKey]?.claudeCliSessionId).toBeUndefined();

219+220+

const persisted = JSON.parse(await fs.readFile(storePath, "utf-8")) as Record<

221+

string,

222+

SessionEntry

223+

>;

224+

expect(persisted[sessionKey]?.cliSessionBindings?.["claude-cli"]).toBeUndefined();

225+

expect(persisted[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();

226+

expect(persisted[sessionKey]?.claudeCliSessionId).toBeUndefined();

227+

});

228+229+

it("keeps Claude CLI resume when the stored transcript has assistant content", async () => {

230+

const sessionKey = "agent:main:direct:claude-transcript-present";

231+

const cliSessionId = "existing-claude-session";

232+

const homeDir = path.join(tmpDir, "home");

233+

const projectsDir = path.join(homeDir, ".claude", "projects", "demo-workspace");

234+

process.env.HOME = homeDir;

235+

await fs.mkdir(projectsDir, { recursive: true });

236+

await fs.writeFile(

237+

path.join(projectsDir, `${cliSessionId}.jsonl`),

238+

`${JSON.stringify({

239+

type: "assistant",

240+

message: {

241+

role: "assistant",

242+

content: [{ type: "text", text: "previous reply" }],

243+

},

244+

})}\n`,

245+

"utf-8",

246+

);

247+

const sessionEntry: SessionEntry = {

248+

sessionId: "openclaw-session-456",

249+

updatedAt: Date.now(),

250+

cliSessionBindings: {

251+

"claude-cli": {

252+

sessionId: cliSessionId,

253+

authProfileId: "anthropic:claude-cli",

254+

},

255+

},

256+

cliSessionIds: { "claude-cli": cliSessionId },

257+

claudeCliSessionId: cliSessionId,

258+

};

259+

const sessionStore: Record<string, SessionEntry> = { [sessionKey]: sessionEntry };

260+

await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2), "utf-8");

261+

runCliAgentMock.mockResolvedValueOnce(makeCliResult("resumed cli response"));

262+263+

await runAgentAttempt({

264+

providerOverride: "claude-cli",

265+

modelOverride: "opus",

266+

cfg: {} as OpenClawConfig,

267+

sessionEntry,

268+

sessionId: sessionEntry.sessionId,

269+

sessionKey,

270+

sessionAgentId: "main",

271+

sessionFile: path.join(tmpDir, "session.jsonl"),

272+

workspaceDir: tmpDir,

273+

body: "continue",

274+

isFallbackRetry: false,

275+

resolvedThinkLevel: "medium",

276+

timeoutMs: 1_000,

277+

runId: "run-cli-transcript-present",

278+

opts: { senderIsOwner: false } as Parameters<typeof runAgentAttempt>[0]["opts"],

279+

runContext: {} as Parameters<typeof runAgentAttempt>[0]["runContext"],

280+

spawnedBy: undefined,

281+

messageChannel: undefined,

282+

skillsSnapshot: undefined,

283+

resolvedVerboseLevel: undefined,

284+

agentDir: tmpDir,

285+

onAgentEvent: vi.fn(),

286+

authProfileProvider: "claude-cli",

287+

sessionStore,

288+

storePath,

289+

sessionHasHistory: false,

290+

});

291+292+

expect(runCliAgentMock).toHaveBeenCalledTimes(1);

293+

expect(runCliAgentMock.mock.calls[0]?.[0]?.cliSessionId).toBe(cliSessionId);

294+

expect(runCliAgentMock.mock.calls[0]?.[0]?.cliSessionBinding).toEqual({

295+

sessionId: cliSessionId,

296+

authProfileId: "anthropic:claude-cli",

297+

});

298+

expect(sessionStore[sessionKey]?.cliSessionIds?.["claude-cli"]).toBe(cliSessionId);

299+

expect(sessionStore[sessionKey]?.claudeCliSessionId).toBe(cliSessionId);

300+

});

301+146302

it("persists CLI replies into the session transcript", async () => {

147303

const sessionKey = "agent:main:subagent:cli-transcript";

148304

const sessionEntry: SessionEntry = {