{"record":{"id":"9be70e1a95bd435d","repo":"mudler/LocalAI","slug":"acestep-cpp-error-failed-to-write-s-n","errorCode":null,"errorMessage":"[acestep-cpp] ERROR: failed to write %s\\n","messagePattern":"\\[acestep-cpp\\] ERROR: failed to write (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/acestep-cpp/cpp/goacestepcpp.cpp","lineNumber":295,"sourceCode":"        int   n_samples = 2 * T_audio;\n        for (int i = 0; i < n_samples; i++) {\n            float a = audio[i] < 0 ? -audio[i] : audio[i];\n            if (a > peak) {\n                peak = a;\n            }\n        }\n        if (peak > 1e-6f) {\n            const float target_amp = powf(10.0f, -1.0f / 20.0f);\n            float       gain       = target_amp / peak;\n            for (int i = 0; i < n_samples; i++) {\n                audio[i] *= gain;\n            }\n        }\n    }\n\n    // 13. Write WAV output\n    if (!audio_write_wav(dst, audio.data(), T_audio, 48000)) {\n        fprintf(stderr, \"[acestep-cpp] ERROR: failed to write %s\\n\", dst);\n        return 7;\n    }\n\n    fprintf(stderr, \"[acestep-cpp] Wrote %s: %d samples (%.2fs @ 48kHz stereo)\\n\",\n            dst, T_audio, (float)T_audio / 48000.0f);\n    return 0;\n}\n","sourceCodeStart":277,"sourceCodeEnd":303,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/acestep-cpp/cpp/goacestepcpp.cpp#L277-L303","documentation":"audio_write_wav() returned false when writing the normalized stereo PCM to the destination WAV path at 48 kHz. This is an I/O-level failure at the very last step (exit code 7): the generation itself succeeded, only persisting the file failed. Causes are typically an unwritable directory, a full disk, or a path encoding/permission problem.","triggerScenarios":"Calling generate with a dst path whose parent directory does not exist or is not writable, a read-only filesystem or container mount, or disk exhaustion (48 kHz stereo floats are heavy — minutes of audio are tens of MB).","commonSituations":"Output dir not created before the call in a scratch/container environment; running under a user without write permission to the model/output folder; disk-full after large model downloads consumed space; dst containing characters the platform rejects.","solutions":["Check that the parent directory of dst exists and is writable (mkdir -p it before generating).","Verify free disk space — the WAV is uncompressed stereo PCM at 48 kHz.","Run the write path manually (touch the exact dst) to surface permission errors, and inspect errno-level messages on stderr.","If running in a container, confirm the output volume is mounted read-write."],"exampleFix":"// before\nsnprintf(dst, sizeof dst, \"/tmp/out/%s.wav\", name);\n// after: ensure the directory exists before generating\nmkdir(\"/tmp/out\", 0755);\nsnprintf(dst, sizeof dst, \"/tmp/out/%s.wav\", name);","handlingStrategy":"validation","validationCode":"if dir := filepath.Dir(dst); dir != \"\" {\n    if err := os.MkdirAll(dir, 0o755); err != nil {\n        return fmt.Errorf(\"output dir: %w\", err)\n    }\n}\nif err := unix.Access(dir, unix.W_OK); err != nil {\n    return fmt.Errorf(\"output dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create and probe-writable the output directory before an expensive generation run.","Check free disk space proportional to duration (48 kHz stereo PCM ≈ 384 KB/s).","Surface the dst path in errors so users see which path failed."],"tags":["acestep-cpp","wav","io","filesystem","permissions"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}