A bot that repeats its menu forever

The menu asks the customer to choose 1 or 2. If they type “2, please.”, the bot shows the same menu again. We examine the loop in Lean and TLA+.

To ask about an appointment, a customer enters their ID number and picks a menu option. The bot only recognises the digits 1 and 2 on their own. A customer who adds a few words to ask for an agent can keep replying without reaching anyone or triggering an error.

Ask for IDvalid IDMenuotherreply1 or 2Left the menu
Any reply other than a bare 1 or 2 sends the bot back to the menu.
  1. Bot: To get started, enter your ID number.

  2. Customer: •••• 1234

    Bot: Choose an option. 1. View my appointment 2. Speak to an agent

  3. Customer: 2, please.

    Bot: I didn't recognise your reply. Choose an option. 1. View my appointment 2. Speak to an agent

  4. Customer: 2. Speak to an agent.

    Bot: I didn't recognise your reply. Choose an option. 1. View my appointment 2. Speak to an agent

Loop detected. The bot only accepts a bare 1 or 2. Adding text makes it repeat the menu.

Example conversation after the fix

  1. Customer: 2, please.

    Bot: I'll pass your request to someone on our team.

The bot leaves the menu. In this example it tells the customer it will pass the request to an agent.

The rule

Can a customer keep replying and still be stuck in the menu? The property menu ~> done requires the bot to eventually leave the menu each time it enters.

What Lean shows

In SupportBot.lean, a function computes the next state from the current state, the input and the version of the bot. Lean checks three properties. Both versions require a valid ID to move from identification to the menu. In the original, an unrecognised reply sends the bot back to the menu. In the corrected version, any reply at the menu leads to done.

Show the code SupportBot.lean

SupportBot.lean

inductive State where | id | menu | done inductive Input where | validId | option | other def step (fixed : Bool) : State → Input → State | .id, .validId => .menu | .menu, .option => .done | .menu, _ => if fixed then .done else .menu | state, _ => state theorem menu_requires_id (fixed : Bool) (input : Input) : step fixed .id input = .menu ↔ input = .validId := by cases input <;> simp [step] theorem loop_repeats_menu : step false .menu .other = .menu := rfl theorem reply_moves_forward (reply : Input) : step true (step true .id .validId) reply = .done := by cases reply <;> rfl

What TLC shows

SupportBot.tla makes a weak fairness assumption. If the bot stays at the menu waiting for a reply, it eventually receives one. With Fixed = FALSE, TLC finds a run in which the customer keeps replying without leaving the menu. That run violates MenuProgress. With Fixed = TRUE, the property holds in the model.

Show the code SupportBot.tla, SupportBot.cfg, SupportBotBug.cfg

SupportBot.tla

---- MODULE SupportBot ----CONSTANT FixedVARIABLES state, replyBitvars == <<state, replyBit>> Init == state = "id" /\ replyBit = FALSE AcceptId == /\ state = "id" /\ state' = "menu" /\ UNCHANGED replyBit \* The bit makes each reply visible even when the menu repeats.Reply(input) == /\ state = "menu" /\ state' = IF Fixed \/ input = "option" THEN "done" ELSE "menu" /\ replyBit' = ~replyBit MenuReply == \E input \in {"option", "other"} : Reply(input) Done == /\ state = "done" /\ UNCHANGED vars Next == AcceptId \/ MenuReply \/ DoneSpec == Init /\ [][Next]_vars /\ WF_vars(MenuReply) MenuProgress == (state = "menu") ~> (state = "done")====

SupportBot.cfg

SPECIFICATION SpecCONSTANT Fixed = TRUEPROPERTY MenuProgress

SupportBotBug.cfg

SPECIFICATION SpecCONSTANT Fixed = FALSEPROPERTY MenuProgress

Limits