{"record":{"id":"ace94d3979f452af","repo":"xai-org/grok-build","slug":"task-panicked","errorCode":null,"errorMessage":"Task panicked: {}","messagePattern":"Task panicked: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-file-utils/src/storage_client.rs","lineNumber":1730,"sourceCode":"        &self,\n        tasks: Vec<(u32, tokio::task::JoinHandle<Result<UploadedPartInfo>>)>,\n    ) -> Result<Vec<UploadedPartInfo>> {\n        let mut uploaded_parts = Vec::with_capacity(tasks.len());\n        let mut upload_errors = Vec::new();\n\n        for (part_num, task) in tasks {\n            match task.await {\n                Ok(Ok(part_info)) => {\n                    tracing::debug!(\"Part {} uploaded successfully\", part_num);\n                    uploaded_parts.push(part_info);\n                }\n                Ok(Err(e)) => {\n                    tracing::error!(\"Part {} upload failed: {}\", part_num, e);\n                    upload_errors.push((part_num, e));\n                }\n                Err(e) => {\n                    tracing::error!(\"Part {} task panicked: {}\", part_num, e);\n                    upload_errors.push((part_num, anyhow::anyhow!(\"Task panicked: {}\", e)));\n                }\n            }\n        }\n\n        if !upload_errors.is_empty() {\n            let error_msgs: Vec<String> = upload_errors\n                .iter()\n                .map(|(part, e)| format!(\"part {}: {}\", part, e))\n                .collect();\n            anyhow::bail!(\"Multipart upload failed: {}\", error_msgs.join(\"; \"));\n        }\n\n        Ok(uploaded_parts)\n    }\n\n    /// Initialize a multipart upload session with signed URLs for direct upload.\n    /// Includes retry logic for transient failures.\n    async fn multipart_init(&self, file_size: u64) -> Result<MultipartInitResponse> {","sourceCodeStart":1712,"sourceCodeEnd":1748,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-file-utils/src/storage_client.rs#L1712-L1748","documentation":"During multipart upload, each part is uploaded in a spawned task; if the task's JoinHandle returns Err (the task panicked or was cancelled rather than returning a result), the code wraps it as \"Task panicked: {e}\" and records it as a part upload error. It indicates an internal panic in a part-upload task, not an HTTP failure from the server.","triggerScenarios":"A part-upload task panicking (e.g. unwrap on None, index out of bounds, or an abort inside the task future); runtime shutdown or JoinError::Cancel aborting the task mid-upload.","commonSituations":"Bug in the part-upload path triggered by unusual part sizes or content; tokio runtime dropping tasks during shutdown; OOM or other panics inside reqwest handling for very large parts; panic in a custom resolver/callback invoked in the task.","solutions":["Inspect the wrapped JoinError/panic message to find the panicking code path.","Ensure the runtime is not shut down while multipart uploads are in flight.","Reduce part size or validate part counts to avoid edge cases triggering the panic.","Upgrade/patch the library if the panic is an internal bug; enable panic backtraces (RUST_BACKTRACE=1) to locate it."],"exampleFix":"// before\nRUST_BACKTRACE=0 ./my-uploader\n\n// after\nRUST_BACKTRACE=full ./my-uploader","handlingStrategy":"try-catch","validationCode":"// Catch panics in your own per-part logic before spawning, and keep runtime alive\nlet result = std::panic::catch_unwind(|| prepare_part(part));\nif result.is_err() {\n    anyhow::bail!(\"part {} preparation panicked; fix inputs before multipart upload\", part_num);\n}","typeGuard":null,"tryCatchPattern":"match client.upload_multipart(reader, part_size).await {\n    Ok(resp) => use(resp),\n    Err(e) if e.to_string().contains(\"Task panicked\") => {\n        tracing::error!(\"multipart worker panicked: {e:#}; retrying smaller parts\");\n        // fallback: re-run with smaller part_size or sequential uploads\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run with RUST_BACKTRACE=1 in staging to catch panicking paths early.","Avoid unwraps in any custom code invoked from part-upload tasks.","Never shut down the tokio runtime while multipart uploads are in flight.","Fuzz unusual part sizes/content to trigger latent panics before production."],"tags":["rust","multipart-upload","panic","tokio","concurrency"],"backgroundTag":"upload-task-panicked","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}