{"record":{"id":"339e55d1499c087d","repo":"sipeed/picoclaw","slug":"failed-to-copy-file-content-w-339e55","errorCode":null,"errorMessage":"failed to copy file content: %w","messagePattern":"failed to copy file content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/audio/asr/whisper_transcriber.go","lineNumber":112,"sourceCode":"\tlogger.InfoCF(\"voice\", \"Starting whisper transcription from memory\", map[string]any{\n\t\t\"bytes\":    len(data),\n\t\t\"filename\": filename,\n\t\t\"model\":    t.modelID,\n\t\t\"provider\": t.providerName,\n\t})\n\n\tvar requestBody bytes.Buffer\n\twriter := multipart.NewWriter(&requestBody)\n\n\tpart, err := writer.CreateFormFile(\"file\", filename)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to create whisper form file\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to create form file: %w\", err)\n\t}\n\n\tif _, copyErr := io.Copy(part, bytes.NewReader(data)); copyErr != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to copy whisper file content\", map[string]any{\"error\": copyErr})\n\t\treturn nil, fmt.Errorf(\"failed to copy file content: %w\", copyErr)\n\t}\n\n\tif err = writer.WriteField(\"model\", t.modelID); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to write whisper model field\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to write model field: %w\", err)\n\t}\n\n\tif err = writer.WriteField(\"response_format\", \"json\"); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to write whisper response_format field\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to write response_format field: %w\", err)\n\t}\n\n\tif err = writer.Close(); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to close whisper multipart writer\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to close multipart writer: %w\", err)\n\t}\n\n\treturn t.doRequest(ctx, &requestBody, writer.FormDataContentType(), int64(len(data)))","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/audio/asr/whisper_transcriber.go#L94-L130","documentation":"Thrown when io.Copy(part, bytes.NewReader(data)) fails while copying the already-in-memory audio bytes into the multipart buffer in WhisperTranscriber. Both ends are memory buffers; a copy error here requires bytes.Buffer write/allocation failure (out of memory). Under a healthy runtime this is unreachable.","triggerScenarios":"Allocation failure while doubling the buffer for a large audio blob; container OOM pressure with a multi-hundred-MB recording duplicated in memory (data + requestBody).","commonSituations":"Transcribing very long in-memory recordings inside memory-capped pods; the copy doubles peak RSS because the audio exists twice (data and multipart copy).","solutions":["Cap accepted audio size before transcription.","Raise memory limits or process audio in segments.","Pre-size the buffer (requestBody.Grow(len(data)+overhead)) to avoid repeated reallocation."],"exampleFix":"// before\nvar requestBody bytes.Buffer\nwriter := multipart.NewWriter(&requestBody)\n\n// after: pre-allocate to avoid mid-copy growth failure\nvar requestBody bytes.Buffer\nrequestBody.Grow(len(data) + len(data)/10 + 1024)\nwriter := multipart.NewWriter(&requestBody)","handlingStrategy":"try-catch","validationCode":"const maxInMemoryAudio = 100 << 20 // 100MB\nif len(data) > maxInMemoryAudio {\n    return fmt.Errorf(\"audio blob %d bytes exceeds in-memory limit %d\", len(data), maxInMemoryAudio)\n}","typeGuard":null,"tryCatchPattern":"if _, err := whisper.TranscribeWithData(ctx, data, name); err != nil {\n    if len(data) > maxInMemoryAudio {\n        return errors.New(\"audio too large for in-memory transcription; use the file-based Transcribe\")\n    }\n    return err\n}","preventionTips":["Enforce a size cap before calling the bytes-based API.","Prefer the file-based Transcribe for large audio; it avoids duplicating the blob."],"tags":["memory","multipart","whisper","audio","go"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}