Skip to content

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

test(memory): builtin uses the account API key from ~/.memscen-key

M3gA-Mind0b0c3b98c026
diff --git a/scripts/memory-scenarios/README.md b/scripts/memory-scenarios/README.md
index 95e1042cb8..5227a3918a 100644
--- a/scripts/memory-scenarios/README.md
+++ b/scripts/memory-scenarios/README.md
@@ -6,7 +6,7 @@ read; **nothing is fixed during a run**.
```bash
# both engines (local first, then Built-in on your real account)
-OPENHUMAN_BACKEND_SESSION_TOKEN=<your session JWT> node scripts/memory-scenarios/run.mjs
+node scripts/memory-scenarios/run.mjs # builtin reads its API key from ~/.memscen-key
# one engine, some scenarios
node scripts/memory-scenarios/run.mjs --engine local --only A,B,E
@@ -48,14 +48,16 @@ session and points memory at the container (`memory_engine_set`).
**builtin** — **your real account**, on its managed route. Read this before
running it:
-- The session JWT comes only from `OPENHUMAN_BACKEND_SESSION_TOKEN`; the core
- reads it at boot (`security/credentials/ops/boot_env.rs`). It is never an RPC
- argument, never printed, never written to the run directory: `rpc.jsonl` and
- `core.log` are scrubbed of it and of anything JWT-shaped.
+- The account's TinyHumans API key is read from `~/.memscen-key` (or
+ `MEMSCEN_KEY_FILE`) at spawn time and reaches the core only as
+ `OPENHUMAN_BACKEND_API_KEY`, which the core seeds at boot
+ (`security/credentials/ops/boot_env.rs`). It is never an RPC argument, never
+ printed, never written to the run directory: `rpc.jsonl` and `core.log` are
+ scrubbed of it and of anything `tiny_…` or JWT-shaped.
- **Nothing of the account's own is moved, erased or imported.** Three guards,
any failure aborts the builtin run before a scenario starts:
- 1. the scheduler gate is pre-written **off** in the account's user dir before
- the core first boots, and read back, so no background job (the layout
+ 1. the scheduler gate is pre-written **off** in the core's config before it
+ first boots (an API key activates no user dir), and read back, so no background job (the layout
migration's tick, import resume, belief builds) runs on its own;
2. this workspace's layout-migration state is written as done (`cleaned`)
and read back through `memory_migration_status`;
diff --git a/scripts/memory-scenarios/engines.mjs b/scripts/memory-scenarios/engines.mjs
index 0cbfe76b94..1dc6895715 100644
--- a/scripts/memory-scenarios/engines.mjs
+++ b/scripts/memory-scenarios/engines.mjs
@@ -209,16 +209,27 @@ export function cortexReader({ endpoint, apiKey }) {
// builtin: the real account
// ---------------------------------------------------------------------------
-export const SESSION_ENV = "OPENHUMAN_BACKEND_SESSION_TOKEN";
+export const API_KEY_ENV = "OPENHUMAN_BACKEND_API_KEY";
+const KEY_FILE =
+ process.env.MEMSCEN_KEY_FILE ||
+ path.join(process.env.HOME || "", ".memscen-key");
-/** The session token from the environment; the run refuses builtin without it. */
-export function builtinToken() {
- const token = process.env[SESSION_ENV];
- if (!token || token.split(".").length !== 3)
- throw new Error(
- `builtin needs a session JWT in ${SESSION_ENV} (it is never printed or written)`,
- );
- return token;
+/**
+ * The account's TinyHumans API key, read from ~/.memscen-key at spawn time.
+ * It reaches the core only as OPENHUMAN_BACKEND_API_KEY (seeded at boot by
+ * security/credentials/ops/boot_env.rs); it is never printed, logged, written
+ * to the run dir or passed to an RPC. The run refuses builtin without it.
+ */
+export async function builtinCredential() {
+ let key;
+ try {
+ key = (await fsp.readFile(KEY_FILE, "utf8")).trim();
+ } catch {
+ throw new Error(`builtin needs a TinyHumans API key in ${KEY_FILE}`);
+ }
+ if (!/^tiny_[A-Za-z0-9_-]{8,}$/.test(key))
+ throw new Error(`${KEY_FILE} does not hold a tiny_ API key`);
+ return { env: { [API_KEY_ENV]: key }, secret: key };
}
/** The active workspace directory, read from the running core. */
diff --git a/scripts/memory-scenarios/lib.mjs b/scripts/memory-scenarios/lib.mjs
index 8cdcbb2124..ce6ca0647c 100644
--- a/scripts/memory-scenarios/lib.mjs
+++ b/scripts/memory-scenarios/lib.mjs
@@ -39,6 +39,7 @@ export function scrub(text, secrets = []) {
/eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g,
"<jwt>",
);
+ out = out.replace(/tiny_[A-Za-z0-9_-]{8,}/g, "<tiny-key>");
out = out.replace(/(bearer\s+)[A-Za-z0-9._~+/-]{16,}/gi, "$1<redacted>");
return out;
}
diff --git a/scripts/memory-scenarios/run.mjs b/scripts/memory-scenarios/run.mjs
index 7f5fefd3f3..8aeddcbd69 100644
--- a/scripts/memory-scenarios/run.mjs
+++ b/scripts/memory-scenarios/run.mjs
@@ -28,8 +28,7 @@ import {
placeMigrationGuard,
verifyBuiltinUntouched,
forgetLedger,
- builtinToken,
- SESSION_ENV,
+ builtinCredential,
} from "./engines.mjs";
import { startMockComposio } from "./mock-composio.mjs";
import { SCENARIOS, registerLocalOnly } from "./scenarios.mjs";
@@ -93,14 +92,6 @@ function mintLocalSessionToken(userId) {
].join(".");
}
-/** The subject of a JWT, read locally (never printed). */
-function jwtSubject(token) {
- const payload = JSON.parse(
- Buffer.from(token.split(".")[1], "base64url").toString(),
- );
- return payload.sub ?? payload._id ?? payload.userId;
-}
-
/** Set `key = value` lines in a TOML section of `file` (a small, line-based edit). */
async function editToml(file, section, kv) {
let text = await fsp.readFile(file, "utf8").catch(() => "");
@@ -164,7 +155,6 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
let events = null;
const ledger = new Ledger();
const threads = [];
- let token = null;
// --- engine setup -------------------------------------------------------
if (engine === "local") {
@@ -191,20 +181,17 @@ async function runEngine(engine, { opts, runDir, runId, findings, results }) {
]),
);
} else {
- token = builtinToken();
- secrets.push(token);
- extraEnv[SESSION_ENV] = token;
- // Guard 0: the scheduler gate is off in the account's user dir before the
- // core first boots, so no background job (migration tick, import resume,
- // belief builds) runs on its own. Verified below; abort if not in effect.
- const sub = jwtSubject(token);
- if (!sub) throw new Error("the session token carries no subject");
- const gated = BASE_CONFIG(["[scheduler_gate]", 'mode = "off"', ""]);
- await fsp.writeFile(path.join(oh, "config.toml"), gated);
- await fsp.mkdir(path.join(oh, "users", String(sub)), { recursive: true });
+ const cred = await builtinCredential();
+ secrets.push(cred.secret);
+ Object.assign(extraEnv, cred.env);
+ // Guard 0: the scheduler gate is off before the core first boots, so no
+ // background job (the migration's tick, import resume, belief builds)
+ // runs on its own. An API key is seeded as a plain profile write with no
+ // user-dir activation (boot_env.rs), so the root config is the active
+ // one. Verified after boot; the run aborts if it is not in effect.
await fsp.writeFile(
- path.join(oh, "users", String(sub), "config.toml"),
- gated,
+ path.join(oh, "config.toml"),
+ BASE_CONFIG(["[scheduler_gate]", 'mode = "off"', ""]),
);
}
@@ -628,7 +615,7 @@ async function main() {
`core binary not found at ${opts.coreBin}\nbuild it (debug, for the Composio override): cargo build -p openhuman-cli --bin openhuman-core`,
);
const engines = opts.engine === "both" ? ["local", "builtin"] : [opts.engine];
- if (engines.includes("builtin")) builtinToken(); // refuse early, before anything starts
+ if (engines.includes("builtin")) await builtinCredential(); // refuse early, before anything starts
const runId = new Date().toISOString().replace(/[:.]/g, "-");
const runDir = path.join(opts.runRoot, runId);
await fsp.mkdir(runDir, { recursive: true });
@@ -644,10 +631,7 @@ async function main() {
try {
await runEngine(engine, { opts, runDir, runId, findings, results });
} catch (e) {
- const secretSafe = scrub(
- e.message,
- process.env[SESSION_ENV] ? [process.env[SESSION_ENV]] : [],
- );
+ const secretSafe = scrub(e.message, []);
console.error(`${engine}: ${secretSafe}`);
findings.add({
engine,
@@ -681,8 +665,6 @@ async function main() {
}
main().catch((e) => {
- console.error(
- `\nfatal: ${scrub(e.stack || e.message, process.env[SESSION_ENV] ? [process.env[SESSION_ENV]] : [])}`,
- );
+ console.error(`\nfatal: ${scrub(e.stack || e.message, [])}`);
process.exit(1);
});