Skip to content
Visual explainer 2h 30m to learn 5 steps

Proposal states for AI-drafted bookings and approvals

Model a booking proposal through proposed, approved, rejected, expired, applied and failed states bound to an exact version.

By Invicly Tech, , in n8n, AI Automation and Voice Agents. About 8 minutes to read.

Topic 17 of 43

In short

When a model drafts a booking, treat it as a proposal with a state, not as a done deal. A proposal moves through proposed, approved, rejected, expired, applied or failed. Approval applies to one exact version, so an edit means a new review.

Think of it like this: It is like a purchase order: someone signs a specific order, and changing it needs a new signature.

Explained simply

When a model drafts something, such as a booking for Tuesday at 10:00, nothing has happened yet. It is only a proposal. Treating it that way keeps your system safe, because a proposal can be checked, changed or thrown away.

A proposal has a state, which is a label for where it is in its life. Six are enough. Proposed means waiting for a person. Approved means a person said yes. Rejected means a person said no. Expired means it waited too long. Applied means the booking was written. Failed means the write did not work.

Not every move is allowed. A proposal can go from proposed to approved, but never from rejected to approved. Writing these rules down, and enforcing them in the database, stops odd bugs such as a booking appearing from a proposal someone refused.

Approval must point at an exact version. If the draft changes from 10:00 to 11:00, the earlier yes does not count. A new version needs a new review. Just before applying, the workflow also checks that the approver is still allowed to approve.

Press Play on a diagram to walk through it one step at a time.

MapThe six proposal states
Proposal
  • proposed
    • Waiting for review
  • approved
    • Ready to apply
  • rejected
    • Final, nothing written
  • expired
    • Too old to apply
  • applied
    • Booking written once
  • failed
    • Write did not succeed
FlowAllowed path
  1. Step 1
    proposed
  2. Step 2
    approved

    Bound to version N

  3. Step 3
    Recheck permission

    Still allowed? Still fresh?

  4. Step 4
    applied or failed
SequenceA stale approval is refused
Reviewer
Workflow
Database
  1. 1Draft v1 sent for review
    Workflow to Reviewer: Draft v1 sent for review
  2. 2Draft edited, now v2
    Database to Workflow: Draft edited, now v2
  3. 3Approve v1
    Reviewer to Workflow: Approve v1
  4. 4UPDATE where version = 1
    Workflow to Database: UPDATE where version = 1
  5. 50 rows updated
    Database to Workflow: 0 rows updated
  6. 6Draft changed, please review v2
    Workflow to Reviewer: Draft changed, please review v2

In depth

The transition table

A state machine is a list of allowed moves. Keep it as data or in one place in code so every workflow uses the same rules. From proposed you may go to approved, rejected or expired. From approved you may go to applied, failed or expired. Rejected, expired and applied are final. Failed may move to approved again only if a retry policy says so. Anything else is an error you log and ignore. This table is your main protection against late or duplicate messages.

  • proposed to approved, rejected or expired
  • approved to applied, failed or expired
  • rejected, expired, applied are final
  • Everything else is refused and logged
CompareMoves that are allowed and moves that are not
Allowed
  • proposed to approved
  • approved to applied
  • approved to failed
  • proposed to expired
Refused
  • rejected to approved
  • applied to proposed
  • expired to applied
  • failed to applied without a retry rule

Bind approval to a version

Give every proposal a version number that goes up each time its content changes. Store the version in the approval message and send it back in the callback. When the answer arrives, update only if the stored version still matches. This is called optimistic concurrency: you do not lock the row, you just make the update fail if someone changed it. A zero-row result means the state or version moved on, so the workflow tells the reviewer their view is out of date. A content hash of the draft works the same way.

  • Version goes up on every edit
  • Callback carries the version
  • UPDATE has version in the WHERE clause
  • Zero rows updated means stale

Expiry and the recheck before applying

A slot that was free yesterday may not be free now. Give every proposal an expires_at time and check it both when approving and when applying. Also recheck authorisation at apply time, because the approver may have left or lost rights between the click and the write. A scheduled workflow can mark old proposals expired so dashboards stay honest. Record the reason for every state change, so later you can explain why a booking did or did not happen.

  • expires_at on every proposal
  • Check expiry at approve and at apply
  • Recheck the approver's rights before writing
  • Log a reason for each change

Learn it in 5 short steps

About 30m each. Track them with a timer in your plan.

  1. 1
    Define the six proposal states~30m
  2. 2
    Allow only valid transitions~30m
  3. 3
    Bind approval to a proposal version~30m
  4. 4
    Expire stale proposals~30m
  5. 5
    Recheck permission before applying~30m

Key points

  • Allow only listed transitions. For example, rejected never becomes approved.
  • Store a version number or content hash. An approval only counts for that version.
  • Expire proposals after a set time so old slots are not booked by surprise.
  • Recheck that the approver may still approve just before applying.

Key terms

Tap a card to flip it. 0/5 known

Examples

sql
UPDATE proposals
SET state = 'approved', decided_by = $1, decided_at = now()
WHERE id = $2 AND version = $3 AND state = 'proposed'
  AND expires_at > now()
RETURNING id;

Move to approved only from the right state and version

Table and guarded update

A proposals table holds the state, version and expiry. The update only succeeds from the right state and version, and only if not expired.

sql
CREATE TABLE proposals (
  id uuid PRIMARY KEY,
  version int NOT NULL DEFAULT 1,
  state text NOT NULL DEFAULT 'proposed'
    CHECK (state IN ('proposed','approved','rejected','expired','applied','failed')),
  expires_at timestamptz NOT NULL,
  decided_by text, decided_at timestamptz
);
UPDATE proposals SET state='approved', decided_by=$1, decided_at=now()
WHERE id=$2 AND version=$3 AND state='proposed' AND expires_at>now();

Walking one proposal through its life

A caller asks for Tuesday 10:00. The workflow saves proposal v1 as proposed. The reviewer edits the time to 11:00, which creates v2. They approve v2. Before applying, the workflow confirms the reviewer still has the right and the proposal has not expired. The booking is written and the state becomes applied. If the calendar had refused, the state would be failed with the error stored.

Quick reference

  • Six states: proposed, approved, rejected, expired, applied, failed
  • Final states: rejected, expired, applied
  • Approve with WHERE state and version match, check rows updated
  • Every proposal carries expires_at
  • Recheck approver rights right before applying
  • A CHECK constraint stops bad state values

Common mistakes

  • Approving by proposal id alone, so an edited draft is applied unreviewed.
  • Checking permission once at review time and never again.
  • Updating state in the workflow without a guard in the WHERE clause.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A reviewer approves version 1, but the draft is now version 2. What should happen?

Question 2

2Which of these is a final state?

Question 3

3What does an UPDATE returning zero rows tell you?

Question 4

4Why recheck authorisation just before applying?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List the allowed transitions for the six states in a small table.

  2. Exercise 2medium

    Create the proposals table with a CHECK constraint, insert one row, and approve it with a guarded UPDATE.

  3. Exercise 3hard

    In n8n, build a workflow that approves a proposal via the Postgres node, and branches on whether a row came back.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Why not just use a yes or no flag?
Flags cannot show expiry, failure or what was applied. States describe the full story.
Do I need a database for this?
You need somewhere durable. A Postgres table is a good fit because of constraints and guarded updates.
What is optimistic concurrency?
Letting several actors work freely, but making an update fail if the row changed since it was read.

Go deeper

ShareXLinkedInWhatsApp