fix(agents): bound rehearsal inventory at 2048

This commit is contained in:
Peter Steinberger
2026-08-11 11:48:52 -07:00
parent 8c058a0e4f
commit ecc311d910
2 changed files with 49 additions and 1 deletions
+48
View File
@@ -161,6 +161,54 @@ describe("agents database rehearsal", () => {
expect(result.complete).toBe(true);
});
it("accepts exactly 2048 logical inventory references", async () => {
const stateRoot = await makeRoot();
const configPath = path.join(stateRoot, "openclaw.json");
const entries = Object.fromEntries(
Array.from({ length: 1024 }, (_, index) => [
`agent-${index}`,
index === 0 ? { default: true } : {},
]),
);
await fsp.writeFile(
configPath,
JSON.stringify({ agents: { entries }, plugins: { enabled: false } }),
);
const result = (await runAgentDatabaseRehearsal({
schemaVersion: 1,
mode: "inventory",
stateRoot,
configPath,
})) as Extract<RehearsalSuccess, { mode: "inventory" }>;
expect(result.references).toHaveLength(2048);
});
it("rejects the 2049th logical inventory reference", async () => {
const stateRoot = await makeRoot();
const configPath = path.join(stateRoot, "openclaw.json");
const entries = Object.fromEntries(
Array.from({ length: 1025 }, (_, index) => [
`agent-${index}`,
index === 0 ? { default: true } : {},
]),
);
await fsp.writeFile(
configPath,
JSON.stringify({ agents: { entries }, plugins: { enabled: false } }),
);
await expect(
runAgentDatabaseRehearsal({
schemaVersion: 1,
mode: "inventory",
stateRoot,
configPath,
}),
).rejects.toMatchObject({ code: "inventory-limit-exceeded" });
});
it("rejects unsupported plugin persistence before validating or opening any database", async () => {
const root = await makeRoot();
await expect(
+1 -1
View File
@@ -44,7 +44,7 @@ import { VERSION } from "../version.js";
const REHEARSAL_SCHEMA_VERSION = 1;
const REHEARSAL_REQUEST_MAX_BYTES = 256 * 1024;
const REHEARSAL_MAX_AGENT_DATABASES = 256;
const REHEARSAL_MAX_INVENTORY_REFERENCES = 256;
const REHEARSAL_MAX_INVENTORY_REFERENCES = 2048;
type RehearsalMode = "inventory" | "migrate" | "read-only";