Practice problem · OpenAI · Medium

Incident Routing

A game studio's live-operations team gets alerts from its game servers. 3 stages in Python with an AI assistant. Pro.

Stage 1 of 3: First match

Background. A game studio's live-operations team gets alerts from its game servers. Each alert carries labels such as game, env or region, and a routing tree decides which receiver (a pager, a team channel, a shift's phone) hears about it.

Implement route(alert, tree) in routing.py. It returns the name of the receiver the alert goes to.

Shapes

  • An alert is a dict[str, str] of labels, for example {"game": "heron", "region": "apac"}.
  • A tree is {"default": "<receiver>", "rules": [route, ...]}.
  • A route has two keys, {"to": "<receiver>", "when": [matcher, ...]}. when may be omitted, which is the same as [].
  • A matcher is a tuple, one of:
    • (key, "is", value): the label equals value
    • (key, "is_not", value): the label differs from value
    • (key, "one_of", [value, ...]): the label equals one of the listed values (at least one is listed)
    • (key, "present"): the alert carries the key
    • (key, "absent"): the alert does not carry the key

Keys, values and receiver names are strings and compare exactly, case included. Inputs are well formed.

Routing

The routes in the tree's rules are checked in order. A route matches when every one of its matchers passes; an empty when matches every alert. The first route that matches gives the receiver. If none matches, the alert goes to the tree's default.

A key the alert does not carry reads as the empty string "" for is, is_not and one_of: ("patch", "is", "") matches an alert with no patch label, and so does ("patch", "is_not", "hotfix"). present and absent look at the key itself, so a key whose value is "" is present.

Each call reads the alert and the tree as they are at that call.

Example

tree = {
    "default": "live-desk",
    "rules": [
        {"to": "quiet-log", "when": [("muted", "present")]},
        {"to": "login-pager", "when": [("system", "is", "login"), ("env", "is_not", "playtest")]},
        {"to": "pacific-duty", "when": [("region", "one_of", ["apac", "oceania"]), ("owner", "absent")]},
        {"to": "shop-oncall", "when": [("system", "is", "shop")]},
    ],
}
  • route({"system": "login", "region": "apac"}, tree) is "login-pager". The alert has no env, which reads as "", and "" differs from "playtest". The pacific-duty route matches too, but it comes later.
  • route({"system": "shop", "region": "apac", "owner": ""}, tree) is "shop-oncall". owner is present, with the value "", so ("owner", "absent") fails and pacific-duty does not match.
  • route({"system": "chat", "muted": ""}, tree) is "quiet-log".
  • route({"system": "voice", "region": "eu-west"}, tree) is "live-desk": no route matches.

Done when Submit goes green.

Constraints

  • Python 3.12 standard library only
  • Editable: routing.py
  • Read-only: all tests/test_*.py files
  • A tree holds a few dozen routes at most, a few levels deep

What comes after stage 1

The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.

  1. Stage 2: Nested routes. Routes can hold routes of their own, and the alert has to end up at the right one.
  2. Stage 3: Every receiver. One alert can need more than one receiver, and the tree says how far to look.

The files you get

  • Yours to edit: routing.py.
  • Read-only: tests/__init__.py.
  • Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.

The round: an agent in the editor

The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.

Frequently asked, briefly answered

Is Incident Routing free?

It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.

Which company asks something like this?

OpenAI. Based on candidates' reports of OpenAI interviews. Nyrion wrote this version, so the question you get may differ.

Do I bring my own AI tool?

No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, or an answer-only assistant that can't write code.

What does the interviewer ask?

4 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.

Start this problem → Sign in

More like it: every practice problem, how OpenAI runs its AI round, the AI coding interview guide.