Fix the replay of a Lambda that sends email

Review the AI's codeEasy10 minAmazon style

Your task

Your Lambda sends a welcome email. The first version started the send as a background task and returned 202 at once. Some users never got the email, and nothing was logged. Lambda freezes the environment the moment the handler returns, so the task never ran. Your team now replays a handler's actions to see which jobs survive.

An assistant wrote surviving_jobs(actions). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • actions: what the handler does, in order. Each one is "spawn:<job>" (start a background task and do not wait for it), "await:<job>" (finish the job before going on), "enqueue:<job>" (hand the job to a durable queue) or "return" (the handler returns).
  • Return the names of the jobs that survive, without repeats, sorted by plain character order.

Rules the tests check:

  • Actions after the first "return" never run. With no "return", every action runs.
  • Split an action at its first : into a verb and a job name. The job name is everything after that :. It can be empty or contain :.
  • An action with no :, other than "return" itself, is ignored. So is an unknown verb.
  • A job survives when an await or an enqueue for it runs.
  • A spawn alone never makes a job survive. It also does not stop a later await or enqueue of the same job from counting.

Examples

surviving_jobs(actions: list[str]) -> list[str]
Example 1
Inputsurviving_jobs(["spawn:welcome", "return"])
Output[]
Example 2
Inputsurviving_jobs(["await:welcome", "return"])
Output["welcome"]
Example 3
Inputsurviving_jobs(["enqueue:welcome", "return"])
Output["welcome"]