Skip to content

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

test(memory): judge attribution on the wire through a CortexDB logging proxy

M3gA-Mind737cc9da328a
diff --git a/scripts/memory-scenarios/engines.mjs b/scripts/memory-scenarios/engines.mjs
index 63a658ab12..b99d925b80 100644
--- a/scripts/memory-scenarios/engines.mjs
+++ b/scripts/memory-scenarios/engines.mjs
@@ -312,3 +312,70 @@ export async function forgetLedger(core, ledger) {
}
return survivors;
}
+
+/**
+ * A logging pass-through in front of the run's CortexDB, so checks can read
+ * what the core actually SENT (attribution such as observed_actor and subject
+ * is written on the wire and not returned on read-back). Every request body is
+ * appended to `logFile` (JSONL, scrubbed); responses are passed through as is.
+ */
+export async function startCortexWireLog({ target, logFile, secrets = [] }) {
+ const http = await import("node:http");
+ const { scrub } = await import("./lib.mjs");
+ const requests = [];
+ const server = http.createServer(async (req, res) => {
+ const chunks = [];
+ for await (const c of req) chunks.push(c);
+ const body = Buffer.concat(chunks);
+ let parsed = null;
+ try {
+ parsed = body.length ? JSON.parse(body.toString()) : null;
+ } catch {
+ /* not JSON */
+ }
+ const entry = {
+ at: new Date().toISOString(),
+ method: req.method,
+ path: req.url,
+ body: parsed,
+ };
+ requests.push(entry);
+ await fsp
+ .appendFile(logFile, scrub(JSON.stringify(entry), secrets) + "\n")
+ .catch(() => {});
+ const headers = { ...req.headers };
+ delete headers.host;
+ try {
+ const upstream = await fetch(`${target}${req.url}`, {
+ method: req.method,
+ headers,
+ body: ["GET", "HEAD"].includes(req.method) ? undefined : body,
+ signal: AbortSignal.timeout(300_000),
+ });
+ const out = Buffer.from(await upstream.arrayBuffer());
+ const h = {};
+ upstream.headers.forEach((v, k) => {
+ if (
+ ![
+ "content-encoding",
+ "transfer-encoding",
+ "content-length",
+ "connection",
+ ].includes(k)
+ )
+ h[k] = v;
+ });
+ res.writeHead(upstream.status, h);
+ res.end(out);
+ } catch (e) {
+ res.writeHead(502, { "content-type": "application/json" });
+ res.end(JSON.stringify({ error_code: "PROXY", message: e.message }));
+ }
+ });
+ await new Promise((r) => server.listen(0, "127.0.0.1", r));
+ return {
+ url: `http://127.0.0.1:${server.address().port}`,
+ requests,
+ close: () => new Promise((r) => server.close(r)),
+ };
+}
diff --git a/scripts/memory-scenarios/run.mjs b/scripts/memory-scenarios/run.mjs
index a9859db931..d522e5ee8b 100644
--- a/scripts/memory-scenarios/run.mjs
+++ b/scripts/memory-scenarios/run.mjs
@@ -24,6 +24,7 @@ import {
} from "./lib.mjs";
import {
startLocalCortex,
+ startCortexWireLog,
OLLAMA_URL,
OLLAMA_CHAT_MODEL,
activeWorkspace,
@@ -161,6 +162,7 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
let cortex = null;
let composio = null;
+ let wire = null;
let core = null;
let events = null;
const ledger = new Ledger();
@@ -176,6 +178,13 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
log,
});
secrets.push(cortex.apiKey);
+ // The core talks to CortexDB through a logging pass-through, so checks
+ // can read what was sent (attribution is wire-only).
+ wire = await startCortexWireLog({
+ target: cortex.endpoint,
+ logFile: path.join(dir, "cortex-wire.jsonl"),
+ secrets,
+ });
const stopCortex = () => cortex.stop();
CLEANUPS.add(stopCortex);
engineResults.inference = cortex.inference;
@@ -276,14 +285,14 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
async () => {
await core.rpc("openhuman.memory_engine_set", {
engine: "cortexdb",
- endpoint: cortex.endpoint,
+ endpoint: wire.url,
api_key: cortex.apiKey,
});
const got = await core.rpc("openhuman.memory_engine_get", {});
if (
got?.engine !== "cortexdb" ||
got?.status !== "ok" ||
- got?.endpoint !== cortex.endpoint
+ got?.endpoint !== wire.url
)
throw new Error(
`engine ${got?.engine} ${got?.status} at ${got?.endpoint} ${got?.reason ?? ""}`,
@@ -343,12 +352,12 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
}
// The memory engine must still be the local container after all that.
const final = await core.rpc("openhuman.memory_engine_get", {});
- if (final?.engine !== "cortexdb" || final?.endpoint !== cortex.endpoint)
+ if (final?.engine !== "cortexdb" || final?.endpoint !== wire.url)
throw new Error(
`ABORT local: memory engine moved to ${final?.engine} at ${final?.endpoint}`,
);
log(
- `local : memory on ${cortex.endpoint}, scheduler gate ${gate}, chat ${engineResults.inference.chat_route}`,
+ `local : memory on ${cortex.endpoint} via ${wire.url}, scheduler gate ${gate}, chat ${engineResults.inference.chat_route}`,
);
};
@@ -420,6 +429,7 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
!!engineResults.inference?.recall_quality_checked,
cortex,
composio,
+ wire,
results: sres.results,
get core() {
return core;
diff --git a/scripts/memory-scenarios/scenarios.mjs b/scripts/memory-scenarios/scenarios.mjs
index 46432a3281..135fdb52dc 100644
--- a/scripts/memory-scenarios/scenarios.mjs
+++ b/scripts/memory-scenarios/scenarios.mjs
@@ -411,32 +411,57 @@ const labels = {
"every logged turn carries an agent_id",
off.map((h) => h.meta?.agent_id),
);
- check(
- "F3-actor-off",
- off.every((h) => !h.meta?.observed_actor),
- "with observed_actor off, no item carries an observed_actor",
- off.map((h) => h.meta?.observed_actor ?? null),
- );
+ // Attribution is written on the wire, not returned on read-back
+ // (tinymemory #237/#238): judge it on the requests the core sent.
+ const writesFor = (thread) =>
+ (ctx.wire?.requests ?? []).filter(
+ (r) =>
+ /\/v1\/experience/.test(r.path ?? "") &&
+ JSON.stringify(r.body ?? {}).includes(thread),
+ );
+ const offWrites = writesFor(tOff);
+ if (!offWrites.length)
+ ctx.note(
+ "F3-no-wire",
+ "no experience write for the OFF thread was captured on the wire",
+ );
+ else
+ check(
+ "F3-actor-off-wire",
+ offWrites.every(
+ (r) => !/"observed_actor"|"subject"/.test(JSON.stringify(r.body)),
+ ),
+ "with observed_actor off, no write carries observed_actor or subject (byte-identical)",
+ offWrites.map((r) => Object.keys(r.body ?? {})),
+ );
- // observed_actor ON: assistant turns carry the agent as actor.
+ // observed_actor ON: an assistant-turn write carries the agent as actor.
await ctx.setConfigToml("memory", { observed_actor: true });
await ctx.restartCore();
const tOn = ctx.newThread("F4-actor-on");
await ctx.turn(tOn, "Remember that the railing primer is grey.");
- const on = await ctx.waitItems({ thread_id: tOn }, 2, 60_000);
- const withActor = on.filter((h) => h.meta?.observed_actor);
- check(
- "F4-actor-on",
- withActor.length > 0,
- "with observed_actor on, assistant turns carry an observed_actor",
- on.map((h) => ({
- text: h.text?.slice(0, 40),
- actor: h.meta?.observed_actor ?? null,
- })),
- );
- ctx.results.observed_actor_samples = withActor
- .slice(0, 3)
- .map((h) => h.meta.observed_actor);
+ await ctx.waitItems({ thread_id: tOn }, 2, 60_000);
+ const onWrites = writesFor(tOn);
+ ctx.results.observed_actor_wire = onWrites.map((r) => ({
+ path: r.path,
+ observed_actor: r.body?.observed_actor ?? null,
+ subject: r.body?.subject ?? null,
+ }));
+ const attributed = onWrites.filter((r) =>
+ /agent:/.test(JSON.stringify(r.body?.observed_actor ?? "")),
+ );
+ if (!onWrites.length)
+ ctx.note(
+ "F4-no-wire",
+ "no experience write for the ON thread was captured on the wire",
+ );
+ else
+ check(
+ "F4-actor-on-wire",
+ attributed.length > 0,
+ "with observed_actor on, an assistant-turn write carries observed_actor agent:<id> on the wire",
+ ctx.results.observed_actor_wire,
+ );
await ctx.setConfigToml("memory", { observed_actor: false });
await ctx.restartCore();
},