fix(agents): do not refresh lastUsedAt on MCP lease release

This commit is contained in:
clawsweeper
2026-06-08 01:58:22 +00:00
parent 1092b18a99
commit c9144789fd
2 changed files with 8 additions and 5 deletions

View File

@@ -7,12 +7,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { createBundleMcpJsonSchemaValidator } from "./agent-bundle-mcp-runtime.js";
import { cleanupBundleMcpHarness } from "./agent-bundle-mcp-test-harness.js";
import {
testing,
createSessionMcpRuntime,
getOrCreateSessionMcpRuntime,
materializeBundleMcpToolsForRun,
retireSessionMcpRuntime,
retireSessionMcpRuntimeForSessionKey,
testing,
} from "./agent-bundle-mcp-tools.js";
import type { SessionMcpRuntime } from "./agent-bundle-mcp-types.js";
import { writeExecutable } from "./bundle-mcp-shared.test-harness.js";
@@ -1672,12 +1672,12 @@ process.on("SIGINT", shutdown);`,
});
const releaseLease = runtime.acquireLease?.();
// TTL elapses while the lease is still held sweep skips active runtimes
// TTL elapses while the lease is still held, so sweep skips active runtimes.
now += 60;
await expect(manager.sweepIdleRuntimes()).resolves.toBe(0);
// Release the lease — must not reset lastUsedAt, so the runtime is
// evictable on the very next sweep without waiting another full TTL
// Release must not reset lastUsedAt; the runtime is evictable on the very
// next sweep without waiting another full TTL.
releaseLease?.();
await expect(manager.sweepIdleRuntimes()).resolves.toBe(1);
@@ -1722,6 +1722,9 @@ process.on("SIGINT", shutdown);`,
cfg: { mcp: { servers: {} } },
});
const lastUsedBefore = runtime.lastUsedAt;
if (!runtime.acquireLease) {
throw new Error("Expected production session MCP runtime to expose acquireLease");
}
const release = runtime.acquireLease();
release();
expect(runtime.lastUsedAt).toBe(lastUsedBefore);

View File

@@ -765,7 +765,7 @@ export function createSessionMcpRuntime(params: {
}
released = true;
activeLeases = Math.max(0, activeLeases - 1);
// release use: refreshing lastUsedAt here defeats the idle-sweep TTL.
// Release is not use: refreshing lastUsedAt here defeats the idle-sweep TTL.
};
},
getCatalog,