fix(agents): clamp zero bash job TTLs (#102855)

Co-authored-by: 0668000787 <ma.weibin@xydigit.com>
This commit is contained in:
Peter Steinberger 2026-07-09 15:43:59 +01:00 committed by GitHub
parent 79d3daa09b
commit aaf5af2fbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import {
markBackgrounded,
markExited,
resetProcessRegistryForTests,
setJobTtlMs,
tail,
} from "./bash-process-registry.js";
import { createProcessSessionFixture } from "./bash-process-registry.test-helpers.js";
@ -171,6 +172,34 @@ describe("bash process registry", () => {
},
]);
});
it("clamps a zero retention TTL to one minute", () => {
vi.useFakeTimers();
try {
vi.setSystemTime(new Date("2026-07-09T00:00:00Z"));
setJobTtlMs(0);
const session = createRegistrySession({
id: "zero-ttl",
maxOutputChars: 100,
pendingMaxOutputChars: 30_000,
backgrounded: true,
});
addSession(session);
markExited(session, 0, null, "completed");
vi.advanceTimersByTime(30_000);
expect(listFinishedSessions()).toHaveLength(1);
vi.advanceTimersByTime(60_000);
expect(listFinishedSessions()).toHaveLength(0);
} finally {
resetProcessRegistryForTests();
setJobTtlMs(30 * 60 * 1000);
resetProcessRegistryForTests();
vi.useRealTimers();
}
});
});
describe("cursorKeyMode", () => {

View file

@ -17,7 +17,7 @@ const MAX_JOB_TTL_MS = 3 * 60 * 60 * 1000; // 3 hours
const DEFAULT_PENDING_OUTPUT_CHARS = 30_000;
function clampTtl(value: number | undefined) {
if (!value || Number.isNaN(value)) {
if (value === undefined || Number.isNaN(value)) {
return DEFAULT_JOB_TTL_MS;
}
return Math.min(Math.max(value, MIN_JOB_TTL_MS), MAX_JOB_TTL_MS);