Skip to content

Instantly share code, notes, and snippets.

@jalehman
Created September 30, 2026 19:13
Show Gist options
  • Select an option

  • Save jalehman/9f327760f2965e00cfe1dd8416e8e2e4 to your computer and use it in GitHub Desktop.

Select an option

Save jalehman/9f327760f2965e00cfe1dd8416e8e2e4 to your computer and use it in GitHub Desktop.
PR151218 final guarded HTTP consent proof, tree 4ebb2b6a
import { defineConfig } from "vitest/config";
import { sharedVitestConfig } from "../test/vitest/vitest.shared.config.ts";
export default defineConfig({ ...sharedVitestConfig, test: { ...sharedVitestConfig.test, include: [".local/final-io-proof.test.ts"], exclude: [], maxWorkers: 1, setupFiles: ["test/setup.ts", "test/setup-openclaw-runtime.ts"] } });
import { createServer } from "node:http";
import { once } from "node:events";
import { afterEach, expect, it } from "vitest";
import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../src/config/runtime-snapshot.js";
import type { OpenClawConfig } from "../src/config/types.openclaw.js";
import { evaluateDecisionInRegistry, prepareDecisionProviderReload } from "../src/decisions/runtime.js";
import type { DecisionOutcome } from "../src/decisions/types.js";
import { createTestPluginRegistry } from "../src/plugins/registry-runtime.test-helpers.js";
import { createPluginRecord } from "../src/plugins/loader-records.js";
import { runPluginRegisterSyncInRegistry } from "../src/plugins/loader-module-runtime.js";
import { getPluginInstance } from "../src/plugins/plugin-instance-scope.js";
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../src/plugins/runtime.js";
import { createDecisionProvider } from "../extensions/typesafe/src/decisions.js";
import { createActiveMemoryTurnEscalationDecider } from "../extensions/active-memory/decision-escalation.js";
import { resolveRecallEscalationDecisionWithDecider } from "../extensions/active-memory/escalation.js";
afterEach(() => { resetPluginRuntimeStateForTest(); clearRuntimeConfigSnapshot(); });
// Synthetic loopback fixture; all host, consumer, provider and HTTP transport code is real.
it.each(["allowed", "withdraw-opt-in", "withdraw-target", "withdraw-answer"] as const)(
"production Active Memory to TypeSafe HTTP boundary: %s",
async (scenario) => {
let config: OpenClawConfig = {
agents: { defaults: { decisionModel: "typesafe/jev-latest", experimental: { decisionAssistance: true } } },
plugins: { entries: { "active-memory": { enabled: true, config: {
mode: "escalate", escalationDecision: true, agents: ["main"], allowedChatTypes: ["group"]
} } } }
};
const withdraw = () => {
config = structuredClone(config);
if (scenario === "withdraw-target") {
config.plugins!.entries!["active-memory"]!.config!.deniedChatIds = ["team"];
} else {
config.agents!.defaults!.experimental!.decisionAssistance = false;
}
setRuntimeConfigSnapshot(config);
};
let requests = 0;
const wire: unknown[] = [];
const server = createServer(async (req, res) => {
requests++;
const chunks: Buffer[] = [];
for await (const chunk of req) chunks.push(Buffer.from(chunk));
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
wire.push({ method: req.method, path: req.url, state: body.state });
if (scenario === "withdraw-answer") withdraw();
res.setHeader("content-type", "application/json");
res.end(JSON.stringify({ model: "jev-latest", answers: { deepRecall: { type: "noul", noul: 0.1 } }, usage: { input_tokens: 4, output_tokens: 1 } }));
});
server.listen(0, "127.0.0.1");
await once(server, "listening");
const address = server.address();
if (!address || typeof address === "string") throw new Error("Missing loopback listener");
let reads = 0;
const provider = createDecisionProvider(() => {
reads++;
// Real provider's second read happens after its awaited lazy client import,
// strictly after the host's initial admission and before its HTTP dispatch.
if (reads === 2 && (scenario === "withdraw-opt-in" || scenario === "withdraw-target")) withdraw();
return { baseUrl: "http://127.0.0.1:" + address.port, timeoutMs: 1000 };
});
const builder = createTestPluginRegistry();
const record = createPluginRecord({ id: "typesafe", source: "/synthetic/typesafe.ts", origin: "global", enabled: true, configSchema: false, contracts: { decisionProviders: ["typesafe"] } });
const api = builder.createApi(record, { config });
runPluginRegisterSyncInRegistry((registration) => registration.registerDecisionProvider(provider), api, builder.registry, record.id);
builder.registry.plugins.push(record);
setActivePluginRegistry(builder.registry);
setRuntimeConfigSnapshot(config);
let outcome: DecisionOutcome | undefined;
const fallback: string[] = [];
const debug: string[] = [];
try {
const decider = createActiveMemoryTurnEscalationDecider({
requested: true, agentId: "main", config, readCurrentConfig: () => config,
target: { chatType: "group", privateDestination: false, destination: { sessionKey: "agent:main:telegram:group:team", messageProvider: "telegram", channelId: "team" } },
decisions: { evaluate: async (batch, options) => (outcome = await evaluateDecisionInRegistry(batch, options, builder.registry, config)) },
logger: { debug: (message) => debug.push(message) }
});
expect(decider).toBeDefined();
const result = await resolveRecallEscalationDecisionWithDecider({
mode: "escalate", message: "What did we decide last time?", searchQuery: "synthetic earlier decision",
hasStrongLaneOneHit: false, signal: new AbortController().signal, decider,
onDeciderFallback: (reason) => fallback.push(reason)
});
const beforeIO = scenario === "withdraw-opt-in" || scenario === "withdraw-target";
expect(requests).toBe(beforeIO ? 0 : 1);
expect(outcome).toMatchObject(scenario === "allowed" ? { status: "ok" } : { status: "unavailable", reason: "disabled" });
expect(result).toBe(scenario === "allowed" ? "decision-skip" : "recall");
expect(fallback).toEqual(scenario === "allowed" ? [] : ["abstain"]);
console.log("FINAL_IO_PROOF " + JSON.stringify({ scenario, requests, reads, outcome: outcome?.status, reason: outcome?.status === "unavailable" ? outcome.reason : undefined, result, fallback, wire, debug }));
} finally {
prepareDecisionProviderReload(builder.registry, new Set([record.id]));
await getPluginInstance(record)?.dispose();
server.closeAllConnections();
await new Promise<void>((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
}
}
);
{"scenario":"allowed","requests":1,"reads":2,"outcome":"ok","result":"decision-skip","fallback":[],"wire":[{"method":"POST","path":"/v1/systemone","state":{"latestUserMessage":"What did we decide last time?","searchQuery":"synthetic earlier decision"}}],"debug":[]}
{"scenario":"withdraw-opt-in","requests":0,"reads":2,"outcome":"unavailable","reason":"disabled","result":"recall","fallback":["abstain"],"wire":[],"debug":["active-memory: escalation decision unavailable reason=revoked; using built-in matcher"]}
{"scenario":"withdraw-target","requests":0,"reads":2,"outcome":"unavailable","reason":"disabled","result":"recall","fallback":["abstain"],"wire":[],"debug":["active-memory: escalation decision unavailable reason=revoked; using built-in matcher"]}
{"scenario":"withdraw-answer","requests":1,"reads":2,"outcome":"unavailable","reason":"disabled","result":"recall","fallback":["abstain"],"wire":[{"method":"POST","path":"/v1/systemone","state":{"latestUserMessage":"What did we decide last time?","searchQuery":"synthetic earlier decision"}}],"debug":["active-memory: escalation decision unavailable reason=revoked; using built-in matcher"]}

PR151218 final Decision I/O consent proof

Published candidate: 8638062c818f7709d3019d031eabcf9d71f9479b Shared admission commit: 199de39d778082a771949701f0e609f9e50127a7 Shared test typing correction: bcf13984c973c5480dcc41736d4142395e6cdc5b

Candidate source tree: 4ebb2b6af196ca9ffd3d5c30e8b330c7e58bc86d Seed head: a9fc279a322c0cb04b7f6ed6db4e5b195d4e43e1 Compared base: 357f9b8a961ba8318bdd3480c957331ba3a80bd1

Boundary

The attached harness runs the production Active Memory live-consent derivation and escalation consumer, the production Decision registry/provider host, and the production TypeSafe Decision provider, lazy client import and guarded HTTP transport. A synthetic plugin registration fixture supplies the real provider. A loopback HTTP receiver counts actual POSTs and returns a synthetic answer. It is not an installed Gateway, a published-driver upgrade, a hosted Jev evaluation, or semantic-quality evidence.

The TypeSafe configuration callback changes live consent after the real awaited lazy client import, strictly after the initial host admission but before HTTP dispatch. This is not a mocked Decision runtime or mocked fetch. A separate checked-in core runtime regression holds DNS preparation, withdraws consent, then releases it before the canonical final-fetch assertion.

Observed passing results:

  • allowed: one POST, ok outcome, decision-skip, no matcher fallback.
  • opt-in withdrawal before I/O: zero POSTs, disabled outcome, matcher recall fallback.
  • per-turn targeting withdrawal before I/O: zero POSTs, disabled outcome, matcher recall fallback.
  • withdrawal after POST and before answer use: one POST, disabled outcome, matcher fallback; withdrawn skip is not accepted.

The runtime tests also verify sticky withdrawal and invalid admission across provider error translation and delayed cleanup beyond deadline without degrading shared provider health. Cancellation and closed consumer authority remain terminal; unavailable remains fallback-eligible.

Isolation and reproducibility

Fresh direct AWS Crabbox, public networking, no Tailscale, no instance profile, IMDS IAM-credentials endpoint verified HTTP404, no hydration, isolated HOME and only CI forwarded. Trusted bootstrap verifies the seed commit and reconstructed git tree before installing pinned Node24.21.0/pnpm12.5.1 and running contributor source.

Place the two harness files in .local/ in the recorded candidate, then run:

node scripts/run-vitest.mjs run --config .local/final-io-proof.config.ts
pnpm test src/decisions/runtime.test.ts src/infra/net/fetch-guard.authority.test.ts --maxWorkers=1
pnpm test:extension active-memory
pnpm test:extension typesafe
pnpm test:contracts:plugins
pnpm check:changed --staged --base 357f9b8a961ba8318bdd3480c957331ba3a80bd1
pnpm build

An equal source tree transfers source-scoped test evidence, not commit-derived build identity or hosted CI. Exact published-head CI is separately required. The earlier installed hosted Jev evidence on e71491d83d2 remains limited to its two authored examples. No product or merge approval is claimed.

Terminal results

On candidate tree 4ebb2b6af196ca9ffd3d5c30e8b330c7e58bc86d: full check:changed exit 0; Decision runtime 66 and guarded authority 4 tests pass (44.24s wrapper wall); four actual HTTP boundary cases pass (17.87s Vitest duration). Signed remote terminal receipt records exit 0 at 2026-09-30T19:11:42Z.

On predecessor tree b72e2a13b3c55d76f722b9767d4bffa2f4a5deb6: Active Memory 360, TypeSafe 159 and plugin contracts 1153 tests pass; pnpm build exit 0. The only subsequent source change is an explicit unknown cast for the intentionally invalid admission callback test. Production, extension tests, package/toolchain and dependency inputs are unchanged. The predecessor full changed check failed TS2352 in that fixture; this is retained as a failed attempt, corrected and passed in the final candidate. Build is source-scoped prior-tree evidence, not an exact published-commit build.

Fresh independent static autoreviews report scoped-clean P0-P2 for the full repair and its final test correction. These do not grant feature acceptance. Hosted CI and fresh durable review are pending on the published head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment