Skip to content

Interview question · Planning & Control Patterns

A plan-and-execute agent keeps running an obsolete plan after the world changes. Fix it.

The plan was right when it was written. The fix is to record what it was right about, check that before every step that changes anything, and replan from where the world is now.

hardEssentialNewUpdated Nov 2026

TL;DR: The executor runs steps without checking whether the facts the plan was built on still hold. Make plans record what they depend on: the versions of the records they read, preconditions per step, and assumptions about the world. Before each step with side effects, compare those against the current state (compare-and-set where the system supports it), and on a mismatch stop and replan from the current state, accounting for steps already done. Add event-driven triggers for long runs, a plan lifetime, and a replan cap.

How to approach it

Get a concrete failure from the traces: what changed (a record, a price, a person's decision), how long after planning, and what the executor did next. The fix depends on whether the change was visible to the agent (it read it and ignored it) or invisible (nothing told it).

A strong answer

The failure. An operations agent plans at 09:00 to rebalance stock: move 300 units from Pune to Delhi, then raise Delhi's reorder point, then notify the planning team. At 09:20 a person manually moves 250 units to Delhi. At 09:40 the executor runs step one anyway, because nothing in the plan said it depended on Delhi's stock level being what it was at 09:00. Delhi now has far too much stock.

Fix 1: plans carry their dependencies. Each step records the state it was planned against:

PLAN = [
    {"step": "transfer", "args": {"from": "pune", "to": "delhi", "units": 300},
     "read_versions": {"stock:delhi": 17, "stock:pune": 42}},
    {"step": "set_reorder", "args": {"site": "delhi", "point": 500},
     "read_versions": {"stock:delhi": 17}},
]

def run_step(step, current_versions, do):
    seen = step["read_versions"]
    stale = {k: (v, current_versions[k]) for k, v in seen.items()
             if current_versions[k] != v}
    if stale:
        return {"status": "replan", "changed": stale}
    return {"status": "done", "result": do(step)}

now = {"stock:delhi": 18, "stock:pune": 42}   # someone changed Delhi at 09:20
out = run_step(PLAN[0], now, lambda s: "moved")
print(out["status"], out["changed"])  # => replan {'stock:delhi': (17, 18)}

Fix 2: check where the change happens. A version check in the agent still leaves a gap between the check and the write. Where the target system supports it, send the expected version with the write (compare-and-set, an If-Match header, a conditional update) so the system itself refuses a write against a changed record. The agent then treats the refusal as a replan trigger.

Fix 3: replan from the current state. The replan gets: the original goal, steps already completed and their effects, what changed and its new value, and remaining budget. Here: Delhi already received 250; the new plan might move 50, or nothing, and adjust the reorder point accordingly.

Fix 4: triggers for long runs.

  • Before every write: the version check above.
  • On events: subscribe to changes on the records the plan depends on, and pause the plan when one fires.
  • On time: a plan older than its lifetime (an hour for stock, a day for a migration) is revalidated before continuing.
  • On surprise: a step result outside what the plan expected.

Fix 5: limits. Cap replans per run; a run that keeps replanning because the world is changing faster than it can act should hand off to a person.

What interviewers probe next

"Why not replan before every step?" It costs a planning call each time and makes runs unpredictable. Version checks are cheap and say precisely when a replan is needed.

"What about steps already executed that the change made wrong?" The replan must consider compensation: reversing or adjusting completed steps (a transfer back, a cancelled order), with the same idempotency and approval rules as forward steps.

"The changed fact was in a document, not a versioned record." Use what freshness signals exist (a modified timestamp, an ETag, a hash of what was read) and recheck them before acting.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

Your agent's plans record read versions and check them before each write.

  1. Start here

    What if the version changes for a reason that does not matter (an unrelated field)?

How it's scored

Weak: Replans on a timer, or tells the planner to "consider that things may change".

Hire: Records preconditions and checks them before each step, replanning on mismatch.

Strong Hire: Records read versions or hashes per step, enforces them at the target with conditional writes, replans from current state with completed steps and compensation, adds event and lifetime triggers, scopes dependencies to the fields that matter, and caps replans.

Common mistakes

  • Checking freshness in the agent but writing unconditionally, leaving a race window.
  • Replanning from the original request, repeating completed steps.
  • Coarse dependencies that cause constant replanning.
  • No cap, so a busy system keeps the agent replanning forever.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 6, and the site remembers where you stopped in each one.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in raises your free answers from 5 to 6 per topic, adds an applied lesson in every topic and easy practice tests, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

Nobody has commented. Post a correction or another way to answer.