@@ -410,6 +410,39 @@ describe("main-session-restart-recovery", () => {
|
410 | 410 | expect(store["agent:main:main"]?.restartRecoveryRuns).toBeUndefined(); |
411 | 411 | }); |
412 | 412 | |
| 413 | +it("does not reopen a completed session via current-generation maintenance-expired abort controller", async () => { |
| 414 | +const sessionsDir = await makeSessionsDir(); |
| 415 | +const lifecycleGeneration = getAgentEventLifecycleGeneration(); |
| 416 | +await writeStore(sessionsDir, { |
| 417 | +"agent:main:main": { |
| 418 | +sessionId: "main-session", |
| 419 | +updatedAt: 3_000, |
| 420 | +status: "done", |
| 421 | +}, |
| 422 | +}); |
| 423 | + |
| 424 | +const result = await markRestartAbortedMainSessions({ |
| 425 | +stateDir: tmpDir, |
| 426 | +sessionKeys: ["agent:main:main"], |
| 427 | +sessionIds: ["main-session"], |
| 428 | +activeRuns: [ |
| 429 | +{ |
| 430 | +runId: "stale-abort-controller-run", |
| 431 | + lifecycleGeneration, |
| 432 | +sessionKey: "agent:main:main", |
| 433 | +sessionId: "main-session", |
| 434 | +observedAt: 5_000, |
| 435 | +}, |
| 436 | +], |
| 437 | +isActiveRun: () => true, |
| 438 | +}); |
| 439 | + |
| 440 | +const store = loadSessionStore(path.join(sessionsDir, "sessions.json")); |
| 441 | +expect(result).toEqual({ marked: 0, skipped: 0 }); |
| 442 | +expect(store["agent:main:main"]?.status).toBe("done"); |
| 443 | +expect(store["agent:main:main"]?.restartRecoveryRuns).toBeUndefined(); |
| 444 | +}); |
| 445 | + |
413 | 446 | it("preserves current-generation markers across repeated restart marking", async () => { |
414 | 447 | const sessionsDir = await makeSessionsDir(); |
415 | 448 | const lifecycleGeneration = getAgentEventLifecycleGeneration(); |
|