diff --git a/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts b/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts index 66b8323de..74a651a74 100644 --- a/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts +++ b/src/shared/tmux/tmux-utils/stale-session-sweep.test.ts @@ -99,6 +99,19 @@ describe("sweepStaleOmoAgentSessionsWith", () => { expect(fixture.killed).toEqual(["omo-agents-99991", "omo-agents-99992"]) }) + it("#given suffixed sessions with dead PIDs #when sweep called #then they are also killed", async () => { + // given + fixture.setCandidates(["omo-agents-99991-1", "omo-agents-99992-abc123"]) + fixture.setAlive(() => false) + + // when + const result = await sweepStaleOmoAgentSessionsWith(fixture.deps) + + // then + expect(result).toBe(2) + expect(fixture.killed).toEqual(["omo-agents-99991-1", "omo-agents-99992-abc123"]) + }) + it("#given session matches current PID #when sweep called #then it is NOT killed", async () => { // given fixture.setCandidates([`omo-agents-${fixture.deps.currentPid}`, "omo-agents-99999"]) @@ -139,9 +152,9 @@ describe("sweepStaleOmoAgentSessionsWith", () => { expect(fixture.killSessionMock).toHaveBeenCalledTimes(1) }) - it("#given non-matching sessions mixed in #when sweep called #then only omo-agents- sessions are considered", async () => { + it("#given non-matching sessions mixed in #when sweep called #then only supported omo-agents session names are considered", async () => { // given - fixture.setCandidates(["main", "omo-agents-99999", "other-session", "omo-agents-abc"]) + fixture.setCandidates(["main", "omo-agents-99999", "omo-agents-99999-1-2", "other-session", "omo-agents-abc"]) fixture.setAlive(() => false) // when diff --git a/src/shared/tmux/tmux-utils/stale-session-sweep.ts b/src/shared/tmux/tmux-utils/stale-session-sweep.ts index 48b88ad52..0ecb79110 100644 --- a/src/shared/tmux/tmux-utils/stale-session-sweep.ts +++ b/src/shared/tmux/tmux-utils/stale-session-sweep.ts @@ -1,4 +1,4 @@ -const STALE_SESSION_PATTERN = /^omo-agents-(\d+)$/ +const STALE_SESSION_PATTERN = /^omo-agents-(\d+)(?:-([A-Za-z0-9]+))?$/ function getErrorMessage(error: unknown): string { if (error instanceof Error) {