Replay Modes

MDWR supports three replay modes for testing, debugging, and policy optimization.

Exact Replay

Replays the workflow with the exact same decisions:

const execution = await workflow.execute({ amount: 1000 });

const replayed = await execution.replay({ mode: "exact" });

Use cases:

Policy-Aware Replay

Replays with different policy parameters:

const execution = await workflow.execute({
  amount: 1500,
  policyVersion: "v1"
});

const replayed = await execution.replay({
  mode: "policy-aware",
  overrides: {
    policyVersion: "v2"
  }
});

Use cases:

Memory-Informed Replay

Replays using accumulated historical insights:

const execution = await workflow.execute({ amount: 1000 });

const replayed = await execution.replay({
  mode: "memory-informed"
});

Use cases:

Replay Options

interface ReplayOptions {
  mode: "exact" | "policy-aware" | "memory-informed";
  overrides?: Record<string, any>;
  fromStep?: string;
  skipSteps?: string[];
}

Replay from Specific Step

await execution.replay({
  mode: "policy-aware",
  fromStep: "evaluate_risk",
  overrides: { policyVersion: "v3" }
});

Skip Steps

await execution.replay({
  mode: "exact",
  skipSteps: ["validate_input"]
});

Comparing Replays

const original = await workflow.execute({ amount: 1500 });
const replayed = await original.replay({
  mode: "policy-aware",
  overrides: { policyVersion: "v2" }
});

// Compare decisions
const originalDecision = original.getStepResults().get("evaluate_risk");
const replayedDecision = replayed.getStepResults().get("evaluate_risk");

console.log("Original:", originalDecision?.decision);
console.log("Replayed:", replayedDecision?.decision);

Best Practices

1. Use Exact Replay for Testing

// Test that workflow produces consistent results
const exec1 = await workflow.execute(input);
const exec2 = await exec1.replay({ mode: "exact" });

expect(exec1.getStepResults()).toEqual(exec2.getStepResults());

2. Use Policy-Aware for Optimization

// Test different thresholds
const results = [];
for (const threshold of [1000, 2000, 3000]) {
  const replayed = await execution.replay({
    mode: "policy-aware",
    overrides: { threshold }
  });
  results.push({ threshold, decision: replayed.getStepResults() });
}

3. Use Memory-Informed for Learning

// Let workflow learn from accumulated decisions
const replayed = await execution.replay({
  mode: "memory-informed"
});

Next Steps