midReportedcurated
Take-home: implement a minimal workflow engine with graph nodes, state, branching, looping and a 50-step cap. What does a strong submission contain?
30-second answer
- A strong submission has a typed state object, node functions that read and write it, conditional edges, and an explicit step budget with cycle detection rather than reliance on a recursion limit.
- Termination has to be provable: a 50-step cap, a no-progress guard that refuses a repeat only when the edge and normalised state are unchanged, and a distinct error when the budget is exhausted instead of a silent stop.
- Tests matter more than the demo, because the assignment usually says unit tests are mandatory; cover a loop that terminates, one that hits the cap, and a branch that dead-ends.
- Persisting state at each step makes resume cheap but adds serialisation and schema-versioning work, which I would document as out of scope rather than half-build.
- A step cap bounds cost but not correctness, because a run can stop at 50 steps with a valid but wrong answer, so the engine also needs a per-run trace of transitions.
Likely follow-ups
Open a question to rehearse the answer.
How do you stop an infinite cycle deterministically?
- Track a repeat keyed by edge identity and the normalised state or state version, and refuse it only when the state is unchanged, so a loop that legitimately changes state still runs.
- Keep the step cap as the outer bound and return a distinct budget-exhausted error, so a cycle produces a diagnosable failure instead of a silent stop.
- Test it with a graph that revisits the same edge and assert both the guard and the cap fire at the right point.
What would you need to add to make a run resumable after a crash?
- Checkpoint at consistent boundaries with a schema version, a run id and a step index, written atomically with the record of committed side effects.
- Make side effects idempotent or keyed, because a resume after a partial step must not repeat a charge or an email.
- Validate external preconditions and the schema on resume, and keep a migration test that loads a fixture from the previous version, since a checkpoint outlives the code that wrote it.
Red flags
- Relies on a recursion limit as the only loop guard
- No tests, or tests that only cover the happy path
Concepts this tests
Tags
Source: github.com