

























@@ -123,6 +123,40 @@ describe("main-session-restart-recovery", () => {
123123expect(store["agent:main:main"]?.abortedLastRun).toBe(false);
124124});
125125126+it("fails marked sessions with stale approval-pending exec tool results", async () => {
127+const sessionsDir = await makeSessionsDir();
128+await writeStore(sessionsDir, {
129+"agent:main:main": {
130+sessionId: "main-session",
131+updatedAt: Date.now() - 10_000,
132+status: "running",
133+abortedLastRun: true,
134+},
135+});
136+await writeTranscript(sessionsDir, "main-session", [
137+{ role: "user", content: "run a command that needs approval" },
138+{ role: "assistant", content: [{ type: "toolCall", id: "call-1", name: "exec" }] },
139+{
140+role: "toolResult",
141+content: "Approval required (id stale, full stale-approval-id).",
142+details: {
143+status: "approval-pending",
144+approvalId: "stale-approval-id",
145+host: "gateway",
146+command: "echo stale",
147+},
148+},
149+]);
150+151+const result = await recoverRestartAbortedMainSessions({ stateDir: tmpDir });
152+153+expect(result).toEqual({ recovered: 0, failed: 1, skipped: 0 });
154+expect(callGateway).not.toHaveBeenCalled();
155+const store = loadSessionStore(path.join(sessionsDir, "sessions.json"));
156+expect(store["agent:main:main"]?.status).toBe("failed");
157+expect(store["agent:main:main"]?.abortedLastRun).toBe(true);
158+});
159+126160it("does not scan ordinary running sessions without the restart-aborted marker", async () => {
127161const sessionsDir = await makeSessionsDir();
128162await writeStore(sessionsDir, {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。