


























@@ -2319,6 +2319,112 @@ describe("initSessionState preserves behavior overrides across /new and /reset",
23192319}
23202320});
232123212322+it("keeps provider-owned CLI sessions on implicit daily reset boundaries", async () => {
2323+vi.useFakeTimers();
2324+try {
2325+vi.setSystemTime(new Date(2026, 0, 18, 5, 0, 0));
2326+const storePath = await createStorePath("openclaw-cli-implicit-reset-");
2327+const sessionKey = "agent:main:telegram:dm:claude-cli-user";
2328+const existingSessionId = "provider-owned-session";
2329+const transcriptPath = path.join(path.dirname(storePath), `${existingSessionId}.jsonl`);
2330+const cliBinding = {
2331+sessionId: "claude-session-1",
2332+authProfileId: "anthropic:claude-cli",
2333+mcpResumeHash: "mcp-resume-hash",
2334+};
2335+2336+await writeSessionStoreFast(storePath, {
2337+[sessionKey]: {
2338+sessionId: existingSessionId,
2339+updatedAt: new Date(2026, 0, 18, 3, 0, 0).getTime(),
2340+modelProvider: "claude-cli",
2341+model: "claude-opus-4-6",
2342+cliSessionBindings: {
2343+"claude-cli": cliBinding,
2344+},
2345+cliSessionIds: {
2346+"claude-cli": cliBinding.sessionId,
2347+},
2348+claudeCliSessionId: cliBinding.sessionId,
2349+},
2350+});
2351+await fs.writeFile(transcriptPath, '{"type":"message"}\n', "utf8");
2352+2353+const cfg = { session: { store: storePath } } as OpenClawConfig;
2354+const result = await initSessionState({
2355+ctx: {
2356+Body: "hello",
2357+RawBody: "hello",
2358+CommandBody: "hello",
2359+From: "claude-cli-user",
2360+To: "bot",
2361+ChatType: "direct",
2362+SessionKey: sessionKey,
2363+Provider: "telegram",
2364+Surface: "telegram",
2365+},
2366+ cfg,
2367+commandAuthorized: true,
2368+});
2369+2370+expect(result.isNewSession).toBe(false);
2371+expect(result.sessionId).toBe(existingSessionId);
2372+expect(result.sessionEntry.cliSessionBindings?.["claude-cli"]).toEqual(cliBinding);
2373+expect(await fs.stat(transcriptPath).catch(() => null)).not.toBeNull();
2374+const archived = (await fs.readdir(path.dirname(storePath))).filter((entry) =>
2375+entry.startsWith(`${existingSessionId}.jsonl.reset.`),
2376+);
2377+expect(archived).toHaveLength(0);
2378+} finally {
2379+vi.useRealTimers();
2380+}
2381+});
2382+2383+it("honors explicit reset policies for provider-owned CLI sessions", async () => {
2384+const storePath = await createStorePath("openclaw-cli-explicit-reset-");
2385+const sessionKey = "agent:main:telegram:dm:claude-cli-explicit-user";
2386+const existingSessionId = "provider-owned-explicit-session";
2387+const cfg = {
2388+session: {
2389+store: storePath,
2390+reset: { mode: "idle", idleMinutes: 1 },
2391+},
2392+} as OpenClawConfig;
2393+2394+await writeSessionStoreFast(storePath, {
2395+[sessionKey]: {
2396+sessionId: existingSessionId,
2397+updatedAt: Date.now() - 5 * 60_000,
2398+modelProvider: "claude-cli",
2399+cliSessionBindings: {
2400+"claude-cli": {
2401+sessionId: "claude-session-explicit",
2402+},
2403+},
2404+},
2405+});
2406+2407+const result = await initSessionState({
2408+ctx: {
2409+Body: "hello",
2410+RawBody: "hello",
2411+CommandBody: "hello",
2412+From: "claude-cli-explicit-user",
2413+To: "bot",
2414+ChatType: "direct",
2415+SessionKey: sessionKey,
2416+Provider: "telegram",
2417+Surface: "telegram",
2418+},
2419+ cfg,
2420+commandAuthorized: true,
2421+});
2422+2423+expect(result.isNewSession).toBe(true);
2424+expect(result.sessionId).not.toBe(existingSessionId);
2425+expect(result.sessionEntry.cliSessionBindings).toBeUndefined();
2426+});
2427+23222428it("disposes the previous bundle MCP runtime on session rollover", async () => {
23232429const storePath = await createStorePath("openclaw-stale-runtime-dispose-");
23242430const sessionKey = "agent:main:telegram:dm:runtime-stale-user";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。