Parity for Workflows and Case Management
Updated
IntermediateWhat you'll learn
~55 min- Write the case states, events, guards and SLA (service-level agreement: the promised time a step may take) timers as data, with one pure reducer (a function from the current case and an event to the next case) that is the part you test
- Count timer deadlines in business days against a holiday list, and test them with a fake clock (a clock the test sets by hand)
- Replay recorded legacy case histories through the new machine and report the first event where the state or a pending timer differs
- Check invariants (statements that must hold after every step) over seeded random event sequences with no new dependency, and keep an AI-drafted assignment a draft until a named person acts
Lessons 23 to 25 proved that one submission scores the same in both systems. A case lives much longer than a submission. After intake it is triaged, assigned, held for documents, decided and closed, and a clock runs under every step. The old system encodes those moves in a workflow table, a few stored procedures and a job that wakes up on a schedule, and nobody has ever written the moves down in one place. This lesson writes them down as data, runs the legacy system’s recorded case histories through the new machine, and fails on the first event where the state or a pending timer differs.
Before the detail — Artifact: a case-state table with guards, SLA timers counted in business days, one pure reducer, a replay harness over recorded legacy histories, and a seeded invariant test. Acceptance test: all 16 tests pass; with the deadline function swapped for one that counts calendar days, the replay names the first divergent event of 7 of the 8 recorded histories and the invariant test fails on 384 of 500 generated runs, each with the seed that replays it. The reducer counts business days in UTC, so the time base (U-61) must be settled before cutover. Status: reusable guidance; the state-machine and replay ideas are published practice, the file layout and rule ids are this module’s.
The pattern, and where each platform lands it
| Problem | The pattern | Where your platform lesson lands it | You decide |
|---|---|---|---|
| What may happen to a case next | The moves are a table of state, event and guards; one pure reducer applies it; a refused event leaves the case unchanged | Same on every platform: the table and reducer are a library the engine calls | Who owns the table, and what happens to an event it does not list |
| When a promised time runs out | An SLA timer is an open record with a due time, counted in business days, and fires at its own due time however late it is noticed | 34: a Logic Apps or Durable Functions timer · 35: a Step Functions wait · 36: a Workflows step with a scheduler; each only wakes the reducer | The holiday list and its owner; whether a timer due at the instant of an event fires first |
| Who may assign and decide | A named person acts; an AI-drafted suggestion is a draft (lesson 27: accept, modify or reject, recorded) | Same on every platform | Which events a supervisor may override, and that every override carries a reason |
| Whether the new machine behaves like the old one | Replay recorded legacy histories and compare state and pending timers after every event | Same on every platform | Which differences are rulings under lesson 25 |
| What runs the machine | A durable workflow engine (a service that keeps a long-running process alive across restarts and waits) hosts the reducer; the engine is a pattern choice and the reducer stays the tested core | 34 · 35 · 36, each against the facts in the Status box below | Which engine, once you have rechecked those facts |
The names come from lesson 22: rules.md for what the legacy system does with a citation for each line, and unknowns.md for what nobody could settle. This lesson adds rules R-60 to R-64 and unknowns U-60 to U-63 to the running scenario.
Plan the change with your agent
Start your agent in the project root and switch to Plan mode (Shift+Tab, /plan, or the mode picker). Ask it to read modernization/rules.md, unknowns.md, and the recorded legacy case histories in fixtures/workflow/ to plan the workflow state machine and replay harness:
Read modernization/rules.md, unknowns.md, and fixtures/workflow/legacy-histories.json, and plan a pure workflow state machine, business-day SLA timers, and a replay harness in src/modernization/workflow/. Ask me anything unclear before writing code.What to check in the plan before you approve
- Transitions and guards from evidence only: Case states, events, and guards are written as a data table (
TRANSITIONS) derived strictly from the recorded legacy histories andrules.md(including legacy quirks like reassignment keeping its existing deadline anddocuments_receivednever changing the case assignee). - Business-day SLA timers and fake clock: Each open state arms one timer (
TIMERS) counted in business days against an owned holiday list (U-60if the full list is unknown), and expired timers fire stamped with theirdueAttimestamp via an injectedClock(FakeClockin tests). - Human-only assignment and decision guards:
assign,reassign, anddeciderequire a named human (first.last), refusingtriage-agent, andreassignrequires a non-emptyreason. - Replay and invariant tests without agent-invented answers: The replay harness compares state and pending timers against the recorded legacy
aftersnapshots and reports the first divergent event per case; generated event sequences test invariants (Closedaccepts no events,Assignedhas one work timer, all deadlines land on business days) without the agent writing expected state values.
If the first plan re-arms the work_sla timer whenever a case is reassigned, correct it before approving:
Preserve the legacy reassignment behavior from H-1005: when move.to equals the current state, keep the existing timer deadline instead of re-arming it.The referee rule from lesson 25 applies here too: the agent proposes event sequences, and the legacy system supplies what the case should look like afterward. For discovery on a real system, give one subagent each legacy job or procedure that touches case status, and run parallel rebuilds in separate worktrees (Module 19 lesson 5: the subagent, background and worktree ladder).
Watch it work
- Typed in the terminal:
claude - Mode:Plan mode (Shift+Tab)
- You type in the session: Read rules.md, unknowns.md and fixtures/workflow/legacy-histories.json. Propose the case table, the timers and the invariants. Write no expected values.
- The tool replies: Read 8 histories (H-1001 to H-1008), 25 events, each with the state and pending timers the legacy system showed straight after it. Plan: 1. Six states: Submitted, Triaged, Assigned, AwaitingDocuments, Decided, Closed. Eight events. Closed lists no events. 2. One timer per open state: Submitted 2, Triaged 1, Assigned 5, AwaitingDocuments 10, Decided 3 business days, read off the first timer in each history. A fired SLA timer raises the escalation count and re-arms 2 business days on; the documents and close timers close the case. 3. H-1005 shows a refused assignment by triage-agent and a reassignment that kept its deadline; H-1008 shows a documents_received event that carried an assignee and did not change the case's owner. I will write all three as rules, not as bugs. 4. Invariants: nothing changes a Closed case; an Assigned case has exactly one open timer; every deadline falls on a business day. 5. Unknown: the holiday list (the histories skip 2026-11-11 and 2026-11-26 but state no list). Recorded as U-60. Approve to write src/modernization/workflow/ and the tests.
- You type in the session: Approved. Build it, then run the workflow tests.
- The tool replies: Wrote calendar.ts, machine.ts, engine.ts, parity.ts, property.ts and tests/unit/workflow.test.ts. npx vitest run tests/unit/workflow.test.ts ✓ business days (R-61) > skips weekends and listed holidays ✓ case machine > Closed accepts no event (R-60) ✓ case machine > the triage agent can draft but never assign or decide (R-63) ✓ case machine > a reassignment needs a reason and keeps the deadline (R-62, R-63) ✓ case machine > only assign and reassign change the assignee: documents_received from an applicant does not (R-63) ✓ parity with the recorded legacy histories > replays every history with the same state and pending timers after each event ✓ generated case lives: seed 20261105, 500 runs > no event leaves a Closed case, every Assigned case has exactly one open work timer, and every timer is due on a business day ... Tests 16 passed (16)
- You type in the session: Someone 'simplified' the deadline to date plus N days. Make that change in machine.ts and run the tests again.
- The tool replies: machine.ts line 3 now reads: import { addCalendarDays as addBusinessDays, type Calendar } from './calendar.ts'; FAIL replays every history with the same state and pending timers after each event {"caseId":"H-1001","at":"2026-11-02T10:00:00.000Z","event":"triage","field":"escalations","legacy":0,"next":1}: expected [ ...7 divergences ] to deeply equal [] FAIL no event leaves a Closed case, every Assigned case has exactly one open work timer, and every timer is due on a business day seed 20261106: step 0 decide: triage_sla is due on a non-business day: 2026-11-15T15:00:00.000Z Tests 2 failed | 14 passed (16) H-1001 opened Friday 2026-10-30. Two calendar days put the triage deadline on Sunday, so the new machine escalated a case that the legacy system, counting Monday and Tuesday, had not. H-1006 still passes: that case closed before any timer crossed a weekend.
- You type in the session: Revert that line and run the whole file once more.
- The tool replies: Restored machine.ts line 3. Tests 16 passed (16)
Illustrative session; exact output varies by tool and agency configuration.
The test output in this lesson is from running this code in the module’s runnable reference (gov-dev-reference-app), type-checked with npx tsc --noEmit. The legacy histories come from a stand-in, because no legacy case system was part of that run: fixtures/workflow/record-standin.py is written the way a legacy poller would be, shares no code with the TypeScript, and prints the state and pending timers after every event. With a real system you export its event table and timer table in the same shape.
What is recorded
| ID | Rule | Citation | Side effects |
|---|---|---|---|
| R-60 | a case moves only along the listed state and event pairs; any other event is refused and leaves the case unchanged; a Closed case accepts none | recorded legacy histories H-1005, H-1006 | none |
| R-61 | an SLA deadline counts business days (Monday to Friday, less the holiday list), keeping the time of day | recorded legacy histories H-1001, H-1003 | none |
| R-62 | a fired SLA timer raises the escalation count and re-arms 2 business days later; the documents and close timers close the case; a reassignment keeps the existing deadline | recorded legacy histories H-1002, H-1004, H-1005 | none |
| R-63 | triage, assignment, reassignment, documents request, decision and close need a named person; a reassignment also needs a reason; only assign and reassign change the assignee, so a documents_received event that carries one leaves the owner alone | recorded legacy histories H-1005, H-1008 | none |
| R-64 | an open case has exactly one open timer and a Closed case has none | invariant, checked by the generated runs | none |
Unknowns, each with the person who can settle it:
- U-60 the holiday list: the fixture’s three dates are invented for the exercise; the office that owns the SLA owns the list.
- U-61 time base, to be settled before cutover: the legacy system stamps server local time (lesson 24’s R-08: one clock, and local time repeats an hour at the autumn change). This reducer reads weekdays and holidays from the UTC date, so a case submitted on Friday at 21:00 America/New_York is a Saturday in UTC, and its two-business-day deadline lands a day earlier than a local-time legacy would put it. The deadline can also differ by an hour across a clock change. The stand-in recorder counts in UTC, so the main fixture agrees with the reducer by construction;
fixtures/workflow/legacy-histories-local.jsonis the same recorder run with--local(New York wall time) and shows the divergence a local-time legacy would produce. Ask the office which zone its SLA is written in, and record the answer as a ruling, not as a code default. - U-62 a timer due at the same instant as an event: the machine fires the timer first; the histories contain no such pair.
- U-63 the timer lengths (2, 1, 5, 10 and 3 business days, and the 2-day re-arm): the stand-in’s settings, invented for the exercise; on a real system they sit in the legacy job’s configuration table.
The numbers in TIMERS below are therefore the stand-in’s settings, and nothing else in this lesson depends on their values.
The machine is data and one reducer
Here are the reference workflow state and event types in src/modernization/workflow/machine.ts from gov-dev-reference-app (compare with what your agent writes; you do not type them by hand):
// src/modernization/workflow/machine.ts (excerpt)export type State = 'Submitted' | 'Triaged' | 'Assigned' | 'AwaitingDocuments' | 'Decided' | 'Closed';export type EventType = 'triage' | 'assign' | 'reassign' | 'request_documents' | 'documents_received' | 'decide' | 'withdraw' | 'close';export type Guard = 'person' | 'reason' | 'assignee';export type TimerKind = 'triage_sla' | 'assign_sla' | 'work_sla' | 'docs_due' | 'auto_close';
export type CaseEvent = { type: EventType; at: string; by: string; assignee?: string; reason?: string };export type Timer = { kind: TimerKind; openedAt: string; dueAt: string };export type Case = { id: string; state: State; assignee: string | null; escalations: number; timers: Timer[] };export type Rules = { calendar: Calendar; deadline: (from: Date, days: number, cal: Calendar) => Date };The table is the whole of R-60. Reading a row tells you what a caseworker can do from that state; reading the file tells you what they cannot.
REFERENCE CODE src/modernization/workflow/machine.ts (excerpt): TRANSITIONS and TIMERS data tables open reference hide reference Reference implementation from gov-dev-reference-app; open to inspect or compare with what your agent builds.
// src/modernization/workflow/machine.ts (excerpt)// R-60: the only moves. Anything not listed is refused and leaves the case unchanged; Closed lists nothing.export const TRANSITIONS: Record<State, Partial<Record<EventType, { to: State; guards: Guard[] }>>> = { Submitted: { triage: { to: 'Triaged', guards: ['person'] }, withdraw: { to: 'Closed', guards: [] } }, Triaged: { assign: { to: 'Assigned', guards: ['person', 'assignee'] }, withdraw: { to: 'Closed', guards: [] } }, Assigned: { reassign: { to: 'Assigned', guards: ['person', 'assignee', 'reason'] }, request_documents: { to: 'AwaitingDocuments', guards: ['person'] }, decide: { to: 'Decided', guards: ['person'] }, withdraw: { to: 'Closed', guards: [] } }, AwaitingDocuments: { documents_received: { to: 'Assigned', guards: [] }, withdraw: { to: 'Closed', guards: [] } }, Decided: { close: { to: 'Closed', guards: ['person'] } }, Closed: {},};// ...// R-61 and R-62: each open state arms one timer in business days. A fired SLA escalates and re-arms;// docs_due and auto_close close the case. Closed arms nothing.export const TIMERS: Record<State, { kind: TimerKind; businessDays: number; onFire: 'escalate' | 'close' } | null> = { Submitted: { kind: 'triage_sla', businessDays: 2, onFire: 'escalate' }, Triaged: { kind: 'assign_sla', businessDays: 1, onFire: 'escalate' }, Assigned: { kind: 'work_sla', businessDays: 5, onFire: 'escalate' }, AwaitingDocuments: { kind: 'docs_due', businessDays: 10, onFire: 'close' }, Decided: { kind: 'auto_close', businessDays: 3, onFire: 'close' }, Closed: null,};export const REARM_BUSINESS_DAYS = 2;TIMERS is R-61 and R-62 as data. Each open state arms one timer when a case enters it; onFire says whether an expired timer escalates or closes. The reducer that applies both tables is the only place state changes:
REFERENCE CODE src/modernization/workflow/machine.ts (excerpt): pure reduce() transition function open reference hide reference Reference implementation from gov-dev-reference-app; open to inspect or compare with what your agent builds.
// src/modernization/workflow/machine.ts (excerpt)export function reduce(c: Case, e: CaseEvent, rules: Rules): Outcome { const move = TRANSITIONS[c.state][e.type]; if (!move) return { case: c, refused: `${e.type} is not allowed in ${c.state}` }; for (const g of move.guards) { const why = GUARDS[g](e); if (why) return { case: c, refused: why }; } const assigns = e.type === 'assign' || e.type === 'reassign'; // only these two events may change the assignee const next: Case = { ...c, state: move.to, assignee: assigns ? (e.assignee ?? c.assignee) : c.assignee }; if (move.to !== c.state) { // a reassignment keeps its deadline (R-62, a legacy quirk) const spec = TIMERS[move.to]; next.timers = spec ? [arm(spec, e.at, rules)] : []; } return { case: next, refused: null };}It takes the case and the event, and nothing else: no clock, no database, no network. The if (move.to !== c.state) test is R-62’s legacy quirk. A move to the same state (a reassignment) arms nothing, so the deadline the case already had stands. A tidy-minded rewrite would re-arm the timer on every assignment, which is a better rule and a different system. Preserve first, and change the rule through a ruling (lesson 25).
Timers and the clock the test owns
REFERENCE CODE src/modernization/workflow/calendar.ts (excerpt): business-day deadline calculation open reference hide reference Reference implementation from gov-dev-reference-app; open to inspect or compare with what your agent builds.
// src/modernization/workflow/calendar.ts (excerpt)export function isBusinessDay(d: Date, cal: Calendar): boolean { const weekday = d.getUTCDay(); // 0 = Sunday, 6 = Saturday return weekday !== 0 && weekday !== 6 && !cal.holidays.has(d.toISOString().slice(0, 10));}
/** n business days after `from`, same time of day. The count starts the day after `from`, so a Saturday plus 1 business day is Monday. */export function addBusinessDays(from: Date, n: number, cal: Calendar): Date { const d = new Date(from); for (let left = n; left > 0; ) { d.setUTCDate(d.getUTCDate() + 1); if (isBusinessDay(d, cal)) left--; } return d;}// .../** The planted fault: the same call, counting every day. */export function addCalendarDays(from: Date, n: number, _cal: Calendar): Date { const d = new Date(from); d.setUTCDate(d.getUTCDate() + n); return d;}The comment on addBusinessDays used to read “A Saturday start counts from the next business day”, which the code does not do: it counts from the day after from, so a Saturday plus 1 business day is Monday, and a Saturday plus 2 is Tuesday. The comment is corrected to say what the code does. The functions read getUTCDay() and the UTC date, so the zone the reducer uses is UTC (U-61).
The second function is the planted fault, kept in the file so the Prove it section can swap it in. The deadline function sits inside Rules rather than being imported by the reducer, so a test can pass the faulty one without editing a source file.
A timer is not a callback that fires when the process happens to be awake. It is a record with a due time, and the reference fireDue function in gov-dev-reference-app turns each expired record into an event stamped with that due time:
// src/modernization/workflow/machine.ts (excerpt)/** A timer reaching its due time is an event of its own, stamped with the due time, not the time it was noticed. */export function fireDue(c: Case, now: Date, rules: Rules): Case { let cur = c; while (cur.timers.length && new Date(cur.timers[0].dueAt) <= now) { const spec = TIMERS[cur.state]!; const at = cur.timers[0].dueAt; cur = spec.onFire === 'close' ? { ...cur, state: 'Closed', timers: [] } : { ...cur, escalations: cur.escalations + 1, timers: [arm(spec, at, rules, REARM_BUSINESS_DAYS)] }; } return cur;}The re-armed timer starts from at, the time the old one was due, not from the time anyone noticed. That one choice makes the engine’s polling rate irrelevant: a job that wakes every minute and one that wakes after a week produce the same case, which the third property test checks. The engine reads time only through a Clock, so a test holds it:
REFERENCE CODE src/modernization/workflow/engine.ts (excerpt): FakeClock and CaseEngine.send() open reference hide reference Reference implementation from gov-dev-reference-app; open to inspect or compare with what your agent builds.
// src/modernization/workflow/engine.ts (excerpt)export class FakeClock implements Clock { private t: number; constructor(start: string) { this.t = Date.parse(start); } now() { return new Date(this.t); } set(iso: string) { if (Date.parse(iso) < this.t) throw new Error(`clock cannot go back to ${iso}`); this.t = Date.parse(iso); } advanceHours(h: number) { this.t += h * 3_600_000; }}// ... send(id: string, e: Omit<CaseEvent, 'at'>): Outcome { this.settle(id); // timers due by now fire before the event (U-62) const out = reduce(this.get(id), { ...e, at: this.clock.now().toISOString() }, this.rules); this.cases.set(id, out.case); return out; }send settles first (U-62), so every timer that came due before the event has already fired when the event is applied. FakeClock.set refuses to go backwards, which catches a history whose rows are out of order before it can give a confusing diff.
Assignments and human overrides
The reference guard table in src/modernization/workflow/machine.ts from gov-dev-reference-app enforces lesson 27 in four lines:
// src/modernization/workflow/machine.ts (excerpt)// R-63: a named person acts; the triage agent only drafts. A reassignment also carries its reason.const PERSON = /^[a-z]+\.[a-z]+$/;export const GUARDS: Record<Guard, (e: CaseEvent) => string | null> = { person: (e) => (PERSON.test(e.by) ? null : `${e.type} needs a named person, not "${e.by}"`), assignee: (e) => (e.assignee && PERSON.test(e.assignee) ? null : `${e.type} needs an assignee`), reason: (e) => (e.reason?.trim() ? null : `${e.type} needs a reason`),};A model may suggest a queue or an assignee (lesson 26 puts the model call behind your API). Its suggestion is not an event the machine accepts, because the machine accepts assign and decide only from a named person. The test the triage agent can draft but never assign or decide shows triage-agent refused and the case left in Triaged with no assignee. The person who accepts, modifies or rejects the suggestion, with their reason, is the by on the event, which is the record lesson 27 stores.
An override is an ordinary event with a stricter guard: reassign needs a reason as well as a person. When the escalation count rises, nothing is assigned or decided on anyone’s behalf. Escalation tells a supervisor, and the supervisor’s next event is the human act.
Replaying the legacy histories
Each fixture in fixtures/workflow/legacy-histories.json is one case’s life as the legacy system recorded it: the events, and after each event the state and the pending timers it showed (reference excerpt from gov-dev-reference-app):
{ "at": "2026-11-02T14:00:00.000Z", "type": "assign", "by": "a.nguyen", "assignee": "b.ortiz", "after": { "state": "Assigned", "assignee": "b.ortiz", "escalations": 0, "timers": [{ "kind": "work_sla", "dueAt": "2026-11-09T14:00:00.000Z" }] } }The harness sets the fake clock to each event’s time, sends the event, and compares what the new machine holds with what the legacy system showed:
REFERENCE CODE src/modernization/workflow/parity.ts (excerpt): replay() harness over recorded legacy case histories open reference hide reference Reference implementation from gov-dev-reference-app; open to inspect or compare with what your agent builds.
// src/modernization/workflow/parity.ts (excerpt)export function replay(h: LegacyHistory, rules: Rules): Divergence | null { const clock = new FakeClock(h.openedAt); const engine = new CaseEngine(clock, rules); engine.open(h.caseId); for (const ev of h.events) { clock.set(ev.at); const { type, by, assignee, reason } = ev; const { case: c } = engine.send(h.caseId, { type, by, assignee, reason }); const d = firstDifference(ev.after, observe(c)); if (d) return { caseId: h.caseId, at: ev.at, event: ev.type, ...d }; } clock.set(h.asOf); const d = firstDifference(h.final, observe(engine.settle(h.caseId))); return d && { caseId: h.caseId, at: h.asOf, event: '(as of)', ...d };}It stops at the first difference and says where: the case, the instant, the event, the field and both values. A first-difference report is short enough to act on; thirty downstream differences from one wrong deadline are not. The final comparison, at asOf, covers the case that had no events for days: the escalations and closures that happened between the last event and the snapshot. Eight histories cover a normal path across a weekend (H-1001), escalation (H-1002), a holiday inside a deadline (H-1003), a documents wait that runs across Thanksgiving’s holiday and closes (H-1004), a refused agent assignment and a reassignment (H-1005), events after withdrawal (H-1006), a long silence (H-1007) and a documents-received event that carries an assignee but changes nothing about the owner (H-1008). A ninth, H-1009, sits in the separate local-time file: a case submitted Friday 21:00 America/New_York, recorded by a legacy that counts in local time, which the UTC reducer does not match (U-61). The set is small; lesson 25’s recorded-property approach, with generated sequences recorded once against the legacy system, is how it grows.
Invariants without a library
The reference generator in src/modernization/workflow/property.ts from gov-dev-reference-app is a small seeded function, and a run is identified by its seed alone:
// src/modernization/workflow/property.ts (excerpt)export function rng(seed: number) { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };}Each run builds a random life: a gap of up to three days, or occasionally one to two weeks, then a random event from a random actor, which includes the triage agent and events the state does not allow. After every step the reference violations check in gov-dev-reference-app verifies the invariants:
// src/modernization/workflow/property.ts (excerpt)function violations(before: Case, after: Case, rules: Rules): string[] { const bad: string[] = []; if (before.state === 'Closed' && JSON.stringify(before) !== JSON.stringify(after)) bad.push('an event changed a Closed case'); if (after.state === 'Assigned' && !(after.timers.length === 1 && after.timers[0].kind === 'work_sla')) bad.push(`Assigned case has ${after.timers.length} open timers`); if (after.timers.length !== (after.state === 'Closed' ? 0 : 1)) bad.push(`${after.state} case has ${after.timers.length} open timers`); for (const t of after.timers) { if (!isBusinessDay(new Date(t.dueAt), rules.calendar)) bad.push(`${t.kind} is due on a non-business day: ${t.dueAt}`); if (t.dueAt <= t.openedAt) bad.push(`${t.kind} is due before it opened`); } return bad;}This is R-64, the first half of R-60 and R-61 stated as things that must always be true. Seed 20261105 plus the run number means a failure prints the seed that replays it, exactly as in lesson 25’s property replay. The tests also check that the 500 runs reach all six states. An invariant checked on an unreachable state proves nothing, and that test is the only thing that says so.
What a library adds, and this lesson does not have, is shrinking: reducing a failing 30-step sequence to the shortest one that still fails. At 30 steps and a printed seed, the failing step is already named. Adopt a library when sequences get long enough that the step name stops being enough.
Which engine runs it
Everything above is ordinary code with no engine in it. Putting it into production means choosing something that holds a case’s timers across restarts and waits days between events. The engine is a pattern decision; each option does the same two jobs, waking the reducer when an event or a timer arrives and storing the case between wakes, and none of them replaces the table, the reducer or the replay test. Move from one engine to another and the replay is the proof that behavior did not move with it.
Availability, authorization, agency approval, region support, and price are five separate facts. What was read, and what was not:
AWS Step Functions in GovCloud (US). The GovCloud user guide says “This service is available in the following AWS GovCloud (US) Regions” and lists both US-West and US-East. It lists two differences: “US GovCloud West only supports FIPS endpoints.” and “Support to call HTTPS APIs is not available.” FIPS endpoints are service addresses for callers who require FIPS 140-3 cryptography. The page does not say which Step Functions feature the second sentence refers to; read it as a warning that a state which calls an HTTPS endpoint cannot be assumed, and test that before designing around it. The consequence for this lesson is to run the reducer where the engine can reach it by a service integration, not by an HTTPS call to your app’s route. (https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-step-functions.html, no date shown.)
Azure Logic Apps and Functions in Azure Government. Both appear in the Azure Government services table with FedRAMP High, DoD IL2, IL4 and IL5 (the page labels the last column IL5WI; IL4 and IL5 are the Defense Department’s tiers for controlled unclassified information). (https://learn.microsoft.com/en-us/azure/azure-government/compliance/azure-services-in-fedramp-auditscope, updated 2026-09-21; its tables read “Last updated: February 2026”.) Durable Functions is a Functions extension and has no row of its own. The Durable Functions overview says “The recommended option is Durable Task Scheduler.” (https://learn.microsoft.com/en-us/azure/durable-task/durable-functions/durable-functions-overview, ms.date 2026-05-20.) Whether the Durable Task Scheduler, or every other Durable backend, is available in Azure Government: UNVERIFIED.
Google Cloud Workflows under Assured Workloads. The supported-products page lists Workflows (workflows.googleapis.com, workflowexecutions.googleapis.com) under FedRAMP High, along with Cloud Run, Cloud SQL, Cloud Scheduler and Cloud Composer. Only the first 100,000 characters of that page were read. IL4 and IL5 status for Workflows: UNVERIFIED. (https://docs.cloud.google.com/assured-workloads/docs/supported-products, no date shown.)
Temporal. Nothing was fetched about it in any government region: UNVERIFIED. Self-hosting it on your own government Kubernetes is the wording to use until a source says more.
Recheck the cited source and your agency’s authorization boundary before you rely on any of it.
Lessons 34, 35 and 36 land the seam on each cloud. For this lesson’s code the effect is narrow: whichever engine you pick calls reduce and fireDue and stores the Case they return, and the replay in this lesson runs in your pipeline, not in the engine.
Prove it
Run these from gov-dev-reference-app in order.
1. The suite is green. npx vitest run tests/unit/workflow.test.ts passes 16 tests: two for business days, six for the machine (Closed accepts nothing, the agent cannot assign or decide, a reassignment keeps its deadline, only assign and reassign change the assignee, a fired timer escalates and a documents timer closes, a late settle equals an early one), two for the histories, two for the time base (the Friday-evening instant is Saturday in UTC; the local-time legacy diverges at escalations, legacy 0, next 1), four over generated runs.
2. The plant the histories catch. In machine.ts line 3 change import { addBusinessDays, type Calendar } to import { addCalendarDays as addBusinessDays, type Calendar }. Run the file again. Expected: 2 failed, 11 passed.
- The replay reports 7 of the 8 histories. The first is H-1001:
event: triage, field: escalations, legacy: 0, next: 1. Two calendar days from Friday is Sunday, so the new machine escalated a case the legacy system had not. H-1002 fails at itstriageevent onescalations(legacy 1, next 2). H-1003, H-1004, H-1005, H-1007 and H-1008 fail at theirassignevent ontimers[0].dueAt, with a legacy deadline later than the new one by the weekend or the holiday (H-1004: legacy2026-11-09T11:00:00.000Z, next2026-11-07T11:00:00.000Z). - The invariant test fails on 384 of the 500 runs, the first at
seed 20261106, with atriage_sladue on a Sunday. - H-1006 still passes, because that case closed before any deadline crossed a weekend. A history that never meets the rule cannot catch its breakage, which is why the generated runs sit beside the recorded ones. Restore the line and the file is green again.
3. The other direction. Delete reason: (e) => ... from GUARDS and make reassign list only ['person', 'assignee']. The test a reassignment needs a reason and keeps the deadline fails on refused being null (expected null to contain 'needs a reason'). A recorded history that contains a refused reassignment (H-1005) fails too, at its first reassign (2026-11-04T09:00:00.000Z): field: assignee, legacy: b.ortiz, next: c.diaz. Expected: 2 failed, 14 passed.
4. The assignee leak. In machine.ts replace the assigns ? (...) : c.assignee expression with e.assignee ?? c.assignee (the earlier code). The test only assign and reassign change the assignee fails with expected 'triage-agent' to be 'b.ortiz', and the replay fails too, at H-1008’s documents_received event (field: assignee, legacy: b.ortiz, next: triage-agent). Expected: 2 failed, 14 passed. Restore the line.
4. The referee. fixtures/workflow/ and tests/unit/workflow.test.ts belong in referee-paths.txt from lesson 25, with the code owner’s review. An agent that makes a red replay green by editing a recorded after has rewritten the legacy system’s answer.
The generated-runs test passes 500 of 500. A teammate says the machine is proven. What is the missing check?
The parity replay diverges at every reassignment: the new machine keeps the old work deadline, and the team thinks re-arming it on reassignment is fairer. What is the right response?
Practice status — moving case workflow to a new engine without changing what cases do
| Practice | Status | Also called |
|---|---|---|
| States, events and guards written as data with a pure transition function | common baseline | finite-state machine; statechart; transition table |
| SLA deadlines counted in business days against an owned holiday list | common baseline | business-calendar arithmetic; working-time rules |
| Timers fire at their due time however late they are noticed | strong optional | deterministic timers; due-time scheduling |
| Recorded legacy histories replayed, comparing state and pending timers after every event | emerging | history replay; characterization of a workflow |
| Hand-seeded generated event sequences with invariants | strong optional | property-based testing; model-based testing |
| Named person required for assignment and decision; AI suggestion stays a draft | common baseline | human in the loop; four-eyes rule |
| Engine chosen after the reducer is tested, behind the same replay | emerging | engine-agnostic core; hexagonal workflow |
Scale: required | common baseline | strong optional | reference-shop (seen only at organizations that publish their own practice) | emerging
Key takeaway
A case’s life is a table, a reducer and a set of timers, and all three can be tested without the engine that will run them. The timer fires at its own due time, counted in business days, so how often anything wakes up changes nothing. Recorded legacy histories give the answers; the replay stops at the first event where the state or a pending timer differs. Seeded random sequences check what must always hold, and a test confirms they reach the states that matter. A model may draft an assignment, and only a named person makes it. Lesson 32 puts a public status page in front of these states, and the replay keeps guarding what the page is allowed to say.
- LEADERSHIP DECISION
- which engine hosts the case machine is chosen after the replay passes, and a rule changes only through a ruling by a named person who did not propose it
- PRACTITIONER ACTION
- write the table and reducer, record the legacy case histories, run the replay and the seeded invariants in every build, and keep the histories out of the agent's reach
- SUCCESS MEASURE
- contract or revenue risk avoided: no missed or invented SLA escalation between the legacy system and the new one across the recorded histories
Legend: LEADERSHIP DECISION = what a leader decides · PRACTITIONER ACTION = what the engineer does next · SUCCESS MEASURE = how you know, in calendar time, assessor-hours or cost, contract or revenue risk, or audit finding avoided