Fix the root cause check for a failed upload
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 asbody_size_exceeded.- Return
"<mechanism>:<verdict>", one of the strings below.
Rules the tests check:
- When
error_kindisbody_size_exceeded:"misconfigured_limit:reject_fix"iflimit_bytesis 0 or less."size_cap:accept_413"ifsize_bytesis greater thanlimit_bytes."misconfigured_limit:reject_fix"otherwise.
out_of_memorygives"memory_pressure:reject_fix".stream_timeoutgives"timeout:reject_fix".multipart_parse_errorgives"parser_bug:reject_fix".- Any other error kind gives
"unknown:reject_fix". Error kinds match exactly, case included. - Only
body_size_exceededlooks at the sizes.
Examples
classify_upload_failure(size_bytes: int, limit_bytes: int, error_kind: str) -> strExample 1
Input
classify_upload_failure(6000000, 5000000, "body_size_exceeded")Output
"size_cap:accept_413"Example 2
Input
classify_upload_failure(5200000, 10000000, "body_size_exceeded")Output
"misconfigured_limit:reject_fix"Example 3
Input
classify_upload_failure(5200000, 10000000, "out_of_memory")Output
"memory_pressure:reject_fix"