Replay a rule change
You are about to tighten a tool's requireRoles or change its scope. Before you ship it, you want to know which of last week's calls it would have refused. Replay answers that from the audit log. It runs the same checks the pipeline runs, against the calls you already recorded.
A replay changes nothing. It runs no handler, no guard, no approval and no validator, and it writes to no log.
Keep the spec in a constant
Replay needs the spec itself, not the tool gov.tool returns. So write the spec once, and use it in both places:
import * as v from "valibot";
import { govern } from "flue-guard";
declare const crm: { find(customerId: string): Promise<{ name: string }> };
const gov = govern({ audit: "audit.jsonl" });
const parameters = v.object({ customerId: v.string() });
type Args = v.InferOutput<typeof parameters>;
export const lookupCustomer = {
name: "lookup_customer",
description: "Look up a customer record.",
parameters,
requireRoles: ["support"],
scope: (a: Args) => `customer:${a.customerId}`,
execute: (a: Args) => crm.find(a.customerId),
};
// What the agent uses: useTool(lookupCustomerTool).
export const lookupCustomerTool = gov.tool(lookupCustomer);
// What replay reads.
export const tools = [lookupCustomer];Run it
Build your project, then point the command at the log and at the module that exports tools:
npx flue-guard replay audit.jsonl --tools ./dist/tools.js212 calls: 197 unchanged, 3 newly denied, 0 newly allowed, 12 not replayed, 0 without a spec
newly denied seq 41 lookup_customer u-17 allowed -> access_denied [roles]
newly denied seq 88 lookup_customer u-17 allowed -> access_denied [roles]
newly denied seq 140 lookup_customer u-52 allowed -> access_denied [roles]
not replayed 12 inputs not fully recordedThe command exits 1 when a past allowed call would now be refused, so a CI job can stop on it. It exits 2 when it could not run: a missing log, a log that does not verify, or a module it could not load.
If the log was written with an hmacKey, put the same key in the environment variable FLUE_GUARD_AUDIT_HMAC_KEY.
From code, call replay and read the report yourself:
import { HashChainAuditLog } from "flue-guard/audit";
import { replay } from "flue-guard/replay";
const report = await replay({
entries: await new HashChainAuditLog({ path: "audit.jsonl" }).entries(),
tools,
});
for (const call of report.newlyDenied) {
console.log(call.seq, call.actorId, call.was, "->", call.now, call.checked);
}Read the report
| Field | Meaning |
|---|---|
newlyDenied | The call passed its checks when recorded. A replayed check refuses it now. |
newlyAllowed | Roles, scope or authorize refused the call when recorded. Every replayed check passes now. |
unchanged | Same answer as before. |
notReplayed | Replay could not check the call. Each one has a reason. |
noSpec | Calls to tools you passed no spec for, counted per tool. |
Each changed call lists the checks that ran in checked. Read it before you trust a newlyAllowed line. ["roles", "scope"] on a tool that also has authorize means authorize did not run, and it may still refuse the call.
What replay cannot see
Masked arguments. The log stores arguments after masking. The default redactor masks every email and every long run of digits. A call whose arguments were masked gets the roles check only. If its roles pass and the tool has a scope, the call is notReplayed with the reason inputs not fully recorded. Replay never guesses from a masked value.
The same holds for a call whose context had attributes, initiator roles or an initiator tenant. The log does not record them.
authorize. It usually reads your database, and your database has moved on since the call. So replay skips it unless you pass --authorize (authorize: true in code). With it, authorize runs against today's data. Treat those results as a hint, not as history.
Old logs. Replay needs the caller's roles and allowed scopes in each entry. flue-guard records them from this version on. Entries written earlier are notReplayed with the reason recorded before replay support.
Later steps. The guard, approval and idempotency are not replayed. A call that one of them stopped counts as having passed its checks.