Skip to content

Commit c914478

Browse files
fix(agents): do not refresh lastUsedAt on MCP lease release
1 parent 1092b18 commit c914478

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/agents/agent-bundle-mcp-runtime.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
77
import { createBundleMcpJsonSchemaValidator } from "./agent-bundle-mcp-runtime.js";
88
import { cleanupBundleMcpHarness } from "./agent-bundle-mcp-test-harness.js";
99
import {
10-
testing,
1110
createSessionMcpRuntime,
1211
getOrCreateSessionMcpRuntime,
1312
materializeBundleMcpToolsForRun,
1413
retireSessionMcpRuntime,
1514
retireSessionMcpRuntimeForSessionKey,
15+
testing,
1616
} from "./agent-bundle-mcp-tools.js";
1717
import type { SessionMcpRuntime } from "./agent-bundle-mcp-types.js";
1818
import { writeExecutable } from "./bundle-mcp-shared.test-harness.js";
@@ -1672,12 +1672,12 @@ process.on("SIGINT", shutdown);`,
16721672
});
16731673
const releaseLease = runtime.acquireLease?.();
16741674

1675-
// TTL elapses while the lease is still held sweep skips active runtimes
1675+
// TTL elapses while the lease is still held, so sweep skips active runtimes.
16761676
now += 60;
16771677
await expect(manager.sweepIdleRuntimes()).resolves.toBe(0);
16781678

1679-
// Release the lease — must not reset lastUsedAt, so the runtime is
1680-
// evictable on the very next sweep without waiting another full TTL
1679+
// Release must not reset lastUsedAt; the runtime is evictable on the very
1680+
// next sweep without waiting another full TTL.
16811681
releaseLease?.();
16821682
await expect(manager.sweepIdleRuntimes()).resolves.toBe(1);
16831683

@@ -1722,6 +1722,9 @@ process.on("SIGINT", shutdown);`,
17221722
cfg: { mcp: { servers: {} } },
17231723
});
17241724
const lastUsedBefore = runtime.lastUsedAt;
1725+
if (!runtime.acquireLease) {
1726+
throw new Error("Expected production session MCP runtime to expose acquireLease");
1727+
}
17251728
const release = runtime.acquireLease();
17261729
release();
17271730
expect(runtime.lastUsedAt).toBe(lastUsedBefore);

src/agents/agent-bundle-mcp-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ export function createSessionMcpRuntime(params: {
765765
}
766766
released = true;
767767
activeLeases = Math.max(0, activeLeases - 1);
768-
// release ≠ use: refreshing lastUsedAt here defeats the idle-sweep TTL.
768+
// Release is not use: refreshing lastUsedAt here defeats the idle-sweep TTL.
769769
};
770770
},
771771
getCatalog,

0 commit comments

Comments
 (0)