Fix the root cause check for a failed upload

Review the AI's codeEasy10 min

Your task

Uploads over 5 MB sometimes failed with a 500. An AI agent's fix wrapped the upload handler in a try/catch that returns a friendly 413 (Payload Too Large), and the error stopped showing up. Before you merge it, your team classifies each logged failure to see whether the 413 tells the truth.

An assistant wrote classify_upload_failure(size_bytes, limit_bytes, error_kind). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • size_bytes: the size of the upload that failed.
  • limit_bytes: the configured upload size limit.
  • error_kind: the error the server logged, such as body_size_exceeded.
  • Return "<mechanism>:<verdict>", one of the strings below.

Rules the tests check:

  • When error_kind is body_size_exceeded:
    • "misconfigured_limit:reject_fix" if limit_bytes is 0 or less.
    • "size_cap:accept_413" if size_bytes is greater than limit_bytes.
    • "misconfigured_limit:reject_fix" otherwise.
  • out_of_memory gives "memory_pressure:reject_fix".
  • stream_timeout gives "timeout:reject_fix".
  • multipart_parse_error gives "parser_bug:reject_fix".
  • Any other error kind gives "unknown:reject_fix". Error kinds match exactly, case included.
  • Only body_size_exceeded looks at the sizes.

Examples

classify_upload_failure(size_bytes: int, limit_bytes: int, error_kind: str) -> str
Example 1
Inputclassify_upload_failure(6000000, 5000000, "body_size_exceeded")
Output"size_cap:accept_413"
Example 2
Inputclassify_upload_failure(5200000, 10000000, "body_size_exceeded")
Output"misconfigured_limit:reject_fix"
Example 3
Inputclassify_upload_failure(5200000, 10000000, "out_of_memory")
Output"memory_pressure:reject_fix"