mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
fix(agents): clamp zero bash job TTLs (#102855)
Co-authored-by: 0668000787 <ma.weibin@xydigit.com>
This commit is contained in:
parent
79d3daa09b
commit
aaf5af2fbc
2 changed files with 30 additions and 1 deletions
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue