Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(memory): builtin clean-up fails closed and can be retried; connectors off, stray tools stop the run

M3gA-Mindce23461c26df
diff --git a/scripts/memory-scenarios/README.md b/scripts/memory-scenarios/README.md
index 5abbf77ce8..fd6ef0285a 100644
--- a/scripts/memory-scenarios/README.md
+++ b/scripts/memory-scenarios/README.md
@@ -85,15 +85,23 @@ inference, and the report says the recall-quality checks were skipped.
running it.
- **Nothing of the account's own is moved, erased, imported or consolidated.**
- Three guards; any failure aborts the builtin run before a scenario starts:
+ Guards; any failure aborts the builtin run before a scenario starts:
1. the scheduler gate is pre-written **off** in every config the core may
treat as active (the root, the pre-login `users/local/`, and for a session
the account's own `users/<subject>/`), and read back from the config the
core actually activated, so no background job (the layout migration's
tick, import resume, belief builds) runs on its own;
- 2. the active workspace's layout-migration state is written as done
+ 2. **Composio is off** (`[composio] mode = "disabled"`, read back the same
+ way), so no turn can reach the account's connected mail, calendar or
+ repositories;
+ 3. the active workspace's layout-migration state is written as done
(`cleaned`) and read back through `memory_migration_status`;
- 3. no v1 store exists in the throwaway workspace.
+ 4. no v1 store exists in the throwaway workspace.
+
+ A builtin turn may call only memory-side tools (`memory`, `resolve_time`,
+ the harness's own bookkeeping). The shell tool has no off switch, so this one
+ detects rather than prevents: the first turn that calls anything else stops
+ every remaining scenario and is reported as a finding.
Migration, import, erase, disconnect-with-clear and belief-build scenarios
run **local only**. At the end the run asserts the migration state never
@@ -105,6 +113,15 @@ running it.
threads and every item with its tag, then checks each is gone. Survivors are
reported as a finding. Beliefs the engine derives on its own from the run's
items cannot be traced back to the run and are not cleaned up.
+- **The clean-up fails closed.** The ids, threads and marker are written to
+ `<run-dir>/builtin/cleanup.json` before anything is forgotten. Any error
+ listing, forgetting or reading back fails the clean-up (it never reads as
+ "nothing survived") and prints the retry, which boots the same guarded core,
+ runs no scenario and forgets what the file names:
+
+ ```bash
+ node scripts/memory-scenarios/run.mjs --cleanup target/memory-scenarios/<run-id>
+ ```
## Scenarios
diff --git a/scripts/memory-scenarios/engines.mjs b/scripts/memory-scenarios/engines.mjs
index 20cf916103..ea3f7b2ecd 100644
--- a/scripts/memory-scenarios/engines.mjs
+++ b/scripts/memory-scenarios/engines.mjs
@@ -335,16 +335,17 @@ export async function verifyBuiltinUntouched(core) {
* Returns the ids that survived.
*/
export async function forgetLedger(core, ledger) {
+ // core.rpc, not tryRpc: an error here must fail the clean-up, never read as
+ // "nothing survived".
const ids = ledger.list();
for (let i = 0; i < ids.length; i += 50)
- await core.tryRpc("openhuman.memory_forget", { ids: ids.slice(i, i + 50) });
+ await core.rpc("openhuman.memory_forget", { ids: ids.slice(i, i + 50) });
const survivors = [];
for (let i = 0; i < ids.length; i += 50) {
- const got = await core.tryRpc("openhuman.memory_items_get", {
+ const got = await core.rpc("openhuman.memory_items_get", {
ids: ids.slice(i, i + 50),
});
- for (const item of got.ok ? (got.value?.items ?? []) : [])
- survivors.push(item.id);
+ for (const item of got?.items ?? []) survivors.push(item.id);
}
return survivors;
}
diff --git a/scripts/memory-scenarios/run.mjs b/scripts/memory-scenarios/run.mjs
index a83e608f33..71c37e1678 100644
--- a/scripts/memory-scenarios/run.mjs
+++ b/scripts/memory-scenarios/run.mjs
@@ -43,6 +43,19 @@ registerLocalOnly(connectors, migration);
const HERE = path.dirname(fileURLToPath(import.meta.url));
const REPO = path.resolve(HERE, "..", "..");
const FIXTURES = path.join(HERE, "fixtures");
+// Tools a builtin turn may call: memory and the harness's own bookkeeping.
+// Anything else (shell, web, connectors, sub-agents) reaches past the test.
+const BUILTIN_TURN_TOOLS = new Set([
+ "memory",
+ "resolve_time",
+ "todo",
+ "goal_complete",
+ "tool_search",
+ "juice_retrieve",
+ "juice_find",
+ "juice_extract",
+ "juice_summarize",
+]);
function parseArgs(argv) {
const opts = {
@@ -50,6 +63,7 @@ function parseArgs(argv) {
engine: "both",
keep: false,
gradeOnly: "",
+ cleanup: "",
coreBin: path.join(REPO, "target", "debug", "openhuman-core"),
runRoot: path.join(REPO, "target", "memory-scenarios"),
settleMs: 4000,
@@ -61,7 +75,10 @@ function parseArgs(argv) {
else if (a === "--engine") opts.engine = next();
else if (a === "--keep") opts.keep = true;
else if (a === "--grade-only") opts.gradeOnly = next();
- else if (a === "--core-bin") opts.coreBin = next();
+ else if (a === "--cleanup") {
+ opts.cleanup = next();
+ opts.engine = "builtin";
+ } else if (a === "--core-bin") opts.coreBin = next();
else if (a === "--settle-ms") opts.settleMs = Number(next());
else if (a === "--help" || a === "-h") {
console.log(
@@ -153,7 +170,15 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
let home = path.join(dir, "home");
const oh = path.join(home, ".openhuman");
await fsp.mkdir(oh, { recursive: true });
- const marker = `memscen:${runId}`;
+ const prior = opts.cleanup
+ ? JSON.parse(
+ await fsp.readFile(
+ path.join(opts.cleanup, "builtin", "cleanup.json"),
+ "utf8",
+ ),
+ )
+ : null;
+ const marker = prior?.marker ?? `memscen:${runId}`;
const secrets = [];
const extraEnv = {};
const engineResults = { engine, marker, scenarios: {} };
@@ -168,7 +193,9 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
let core = null;
let events = null;
const ledger = new Ledger();
- const threads = [];
+ const threads = [...(prior?.threads ?? [])];
+ ledger.addAll(prior?.ids);
+ const strayTools = [];
// --- engine setup -------------------------------------------------------
if (engine === "local") {
@@ -229,7 +256,16 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
// Guard 0 goes in every config the core may treat as active: the root,
// the pre-login user dir (a key activates none) and, for a session, the
// account's own user dir (`users/<subject>`). Verified after boot.
- const gated = BASE_CONFIG(["[scheduler_gate]", 'mode = "off"', ""]);
+ // Guard 2: Composio is off, so no turn can reach the account's connected
+ // mail, calendar or repos (a memory test must never read real data).
+ const gated = BASE_CONFIG([
+ "[scheduler_gate]",
+ 'mode = "off"',
+ "",
+ "[composio]",
+ 'mode = "disabled"',
+ "",
+ ]);
await fsp.writeFile(path.join(oh, "config.toml"), gated);
for (const id of ["local", ...(cred.subject ? [cred.subject] : [])]) {
await fsp.mkdir(path.join(oh, "users", id), { recursive: true });
@@ -404,6 +440,11 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
throw new Error(
`ABORT builtin: scheduler gate is "${mode}", not "off" (user dir not the one pre-written)`,
);
+ const composioMode = pick(snap, "config.composio.mode");
+ if (composioMode !== "disabled")
+ throw new Error(
+ `ABORT builtin: Composio is "${composioMode}", not "disabled"`,
+ );
const eng = await core.rpc("openhuman.memory_engine_get", {});
if (eng?.engine !== "tinyhumans" || eng?.status === "off")
throw new Error(
@@ -423,7 +464,7 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
);
engineResults.inference = { kind: "managed (account route)" };
log(
- `builtin : guards in place (scheduler gate off, migration state cleaned, no v1 store)`,
+ `builtin : guards in place (scheduler gate off, Composio off, migration state cleaned, no v1 store)`,
);
}
@@ -436,7 +477,8 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
)
.sort((a, b) => Number(!!a.last) - Number(!!b.last));
- for (const scenario of selected) {
+ for (const scenario of opts.cleanup ? [] : selected) {
+ if (strayTools.length) break;
const transcript = new JsonlLog(
path.join(dir, "scenarios", scenario.id, "transcript.jsonl"),
secrets,
@@ -489,6 +531,19 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
ms: r.ms,
tools: r.toolCalls,
});
+ // Guard 3 (builtin): a turn may only use memory-side tools. There is
+ // no config switch for the shell tool, so this detects rather than
+ // prevents: the first stray call stops every remaining scenario.
+ const stray =
+ engine === "builtin"
+ ? (r.toolCalls ?? []).filter((n) => !BUILTIN_TURN_TOOLS.has(n))
+ : [];
+ if (stray.length) {
+ strayTools.push(...stray);
+ throw new Error(
+ `ABORT builtin: a turn called ${[...new Set(stray)].join(", ")} on the real account`,
+ );
+ }
return r;
},
async learn(text, kind = "fact", meta = {}) {
@@ -660,24 +715,30 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
if (engine === "builtin" && core && !core.exited) {
try {
// Everything this run stored: the ledger, every item in its threads,
- // every item carrying its marker.
- for (const t of threads) {
- const items = await core
- .rpc("openhuman.memory_items_list", {
- filter: { thread_id: t },
- limit: 100,
- })
- .catch(() => null);
- ledger.addAll((items?.items ?? []).map((h) => h.id));
- }
- const tagged = await core
- .rpc("openhuman.memory_items_list", {
- filter: { tags_any: [marker] },
+ // every item carrying its marker. Written down first, so a failed
+ // clean-up can be retried with --cleanup <run-dir>.
+ const unlisted = [];
+ for (const filter of [
+ ...threads.map((t) => ({ thread_id: t })),
+ { tags_any: [marker] },
+ ]) {
+ const r = await core.tryRpc("openhuman.memory_items_list", {
+ filter,
limit: 100,
- })
- .catch(() => null);
- ledger.addAll((tagged?.items ?? []).map((h) => h.id));
+ });
+ if (r.ok) ledger.addAll((r.value?.items ?? []).map((h) => h.id));
+ else unlisted.push(JSON.stringify(filter));
+ }
+ await fsp.writeFile(
+ path.join(dir, "cleanup.json"),
+ JSON.stringify({ marker, threads, ids: ledger.list() }, null, 2),
+ );
+ // Fails closed: an error forgetting or reading back throws.
const survivors = await forgetLedger(core, ledger);
+ if (unlisted.length)
+ throw new Error(
+ `could not list ${unlisted.join(", ")}; items there may survive`,
+ );
const untouched = guardPlaced
? await verifyBuiltinUntouched(core)
: {
@@ -700,6 +761,17 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
evidence: "rpc.jsonl",
basis: "READ",
});
+ if (strayTools.length)
+ findings.add({
+ engine,
+ scenario: "guard",
+ id: "stray-tools",
+ severity: "high",
+ expected: "builtin turns use memory-side tools only",
+ actual: [...new Set(strayTools)],
+ evidence: "scenarios/*/transcript.jsonl",
+ basis: "READ",
+ });
if (!untouched.ok)
findings.add({
engine,
@@ -723,7 +795,11 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
expected: "cleanup completes",
actual: scrub(e.message, secrets),
evidence: "rpc.jsonl",
+ basis: "READ",
});
+ console.log(
+ `builtin : CLEANUP FAILED (${scrub(e.message, secrets).slice(0, 200)}); retry: node scripts/memory-scenarios/run.mjs --cleanup ${runDir}`,
+ );
}
}
events?.close();