Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

Multi-step flows stop at the audit trail

A multi-step approval flow that moves documents from submitted to approved to registered has one failure mode nobody tests: a record whose current state is correct but whose history is empty. The screen looks right, and

A multi-step approval flow that moves documents from submitted to approved to registered has one failure mode nobody tests: a record whose current state is correct but whose history is empty. The screen looks right, and six weeks later nobody can answer "who moved this, and when".

The fix is one append-only table written inside the same transaction as the state change:

CREATE TABLE flow_audit (
  id           bigserial PRIMARY KEY,
  record_id    text        NOT NULL,
  from_state   text        NOT NULL,
  to_state     text        NOT NULL,
  actor_id     text        NOT NULL,
  actor_role   text        NOT NULL,
  changed_at   timestamptz NOT NULL DEFAULT now(),
  request_id   text        NOT NULL,
  before_json  jsonb       NOT NULL,
  after_json   jsonb       NOT NULL
);
CREATE INDEX ON flow_audit (record_id, changed_at);

Three rules make it usable in an acceptance test:

  1. The transition and its audit row are one transaction — if the audit insert fails, the transition fails.
  2. before_json and after_json hold the fields that changed, not the whole row, so a diff stays readable a year later.
  3. request_id matches the caller's log, so a support ticket can be traced to the exact transition.

At OBSIDIAN Studio we put those three rules in the four-row acceptance sheet (input, expected, actual, verdict) before work starts, and the same checks run on delivery:

  • surface (UI) and wiring (form to CRM) built by one team — it does not stop at the form
  • the four-field form posts to a server function, not a mail app; no account or password
  • a resent request_id is deduplicated, so one opportunity stays one record
  • a CRM 503 write is queued instead of lost, with a written manual re-processing step
  • the four-row acceptance sheet is agreed before work starts, and re-run on delivery with execution ids
  • anything short is fixed free and re-checked once inside the agreed scope
  • Korean/English toggle 100%, no horizontal overflow from 320 to 1920 px, zero console errors
  • domain, DNS, HTTPS, cache and security headers set up, with a rollback-able deploy handover
  • a handover document so the team can run the same checks without us

Free scenario demos and the scope/price sheet:
https://web.intelliliving.kr?utm_source=devto&utm_medium=organic&utm_campaign=b2b_obsidian&utm_content=dv_08

Which transition in your flow is currently written with no audit row — submitted to approved, approved to registered, or the cancellation path?

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.