{"record":{"id":"3ac726075d384444","repo":"sipeed/picoclaw","slug":"failed-to-write-model-id-field-w","errorCode":null,"errorMessage":"failed to write model_id field: %w","messagePattern":"failed to write model_id field: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/audio/asr/elevenlabs_transcriber.go","lineNumber":83,"sourceCode":"\t\t\"file_name\":  filepath.Base(audioFilePath),\n\t})\n\n\tvar requestBody bytes.Buffer\n\twriter := multipart.NewWriter(&requestBody)\n\n\tpart, err := writer.CreateFormFile(\"file\", filepath.Base(audioFilePath))\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to create 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 _, err = io.Copy(part, audioFile); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to copy file content\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to copy file content: %w\", err)\n\t}\n\n\tif err = writer.WriteField(\"model_id\", t.modelID); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to write model_id field: %w\", err)\n\t}\n\n\tif err = writer.Close(); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to close multipart writer\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to close multipart writer: %w\", err)\n\t}\n\n\turl := t.apiBase + \"/v1/speech-to-text\"\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", url, &requestBody)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to create request\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\treq.Header.Set(\"Xi-Api-Key\", t.apiKey)\n\n\tlogger.DebugCF(\"voice\", \"Sending transcription request to ElevenLabs API\", map[string]any{","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/audio/asr/elevenlabs_transcriber.go#L65-L101","documentation":"Thrown when writer.WriteField(\"model_id\", t.modelID) fails in ElevenLabsTranscriber.Transcribe. WriteField writes a small form field to an in-memory bytes.Buffer; with a healthy runtime it cannot fail. Seeing this error means memory allocation failed inside bytes.Buffer (OOM killer territory) — the surrounding multipart data (a whole audio file) has already been buffered.","triggerScenarios":"bytes.Buffer.Grow returns an allocation error: process near its memory limit (cgroup OOM pressure) while buffering a large audio file; 32-bit build with >2GB address space exhaustion.","commonSituations":"Container memory limit set lower than the audio file size plus overhead; very long recordings (hundreds of MB) buffered in RAM before upload.","solutions":["Raise the container/process memory limit or cap the accepted audio size.","Reduce recording length or transcribe in chunks.","Switch to a streaming-capable path (write the multipart body to a file or use io.Pipe) instead of buffering."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(path); err == nil && fi.Size() > maxBufferedAudio {\n    return fmt.Errorf(\"audio too large for in-memory multipart build: %d bytes\", fi.Size())\n}","typeGuard":null,"tryCatchPattern":"if _, err := el.Transcribe(ctx, path); err != nil {\n    if runtime/debug memory pressure suspected (OOM kill dmesg entries) {\n        // reduce audio size / raise memory limit; do not retry unchanged\n    }\n    return err\n}","preventionTips":["Cap audio duration/size at intake (e.g. 25MB).","Run with a memory limit comfortably above 2x the largest recording.","Alert on container OOM events next to transcription spikes."],"tags":["multipart","memory","elevenlabs","audio","go"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}