jackwener/OpenCLI · error · CommandExecutionError

MiniMax music audio size mismatch (expected ${expectedBytes}

Error message

MiniMax music audio size mismatch (expected ${expectedBytes} bytes, got ${bytes.length})

What it means

After hex decoding, if the response supplied a trusted expected byte count (extra_info.music_size), the decoded buffer length must match exactly. A mismatch means the audio payload was truncated, padded, or corrupted in transit, so the client refuses to write a defective file.

Source

Thrown at clis/minimax/utils.js:154

    let url;
    try {
        url = new URL(value);
    } catch {
        throw new CommandExecutionError('MiniMax music returned data.audio that is not a URL');
    }
    if (url.protocol !== 'https:') {
        throw new CommandExecutionError(`MiniMax music returned a non-HTTPS audio URL (${url.protocol})`);
    }
    return url.toString();
}

export function decodeAudioHex(value, expectedBytes, format) {
    if (value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-f]+$/i.test(value)) {
        throw new CommandExecutionError('MiniMax music returned invalid hexadecimal audio');
    }
    const bytes = Buffer.from(value, 'hex');
    if (expectedBytes != null && bytes.length !== expectedBytes) {
        throw new CommandExecutionError(`MiniMax music audio size mismatch (expected ${expectedBytes} bytes, got ${bytes.length})`);
    }
    if (format === 'wav' && (bytes.length < 12 || bytes.subarray(0, 4).toString('ascii') !== 'RIFF' || bytes.subarray(8, 12).toString('ascii') !== 'WAVE')) {
        throw new CommandExecutionError('MiniMax music returned bytes that are not a WAV file');
    }
    if (format === 'mp3' && !isMp3(bytes)) {
        throw new CommandExecutionError('MiniMax music returned bytes that are not an MP3 file');
    }
    return bytes;
}

function isMp3(bytes) {
    return bytes.length >= 3 && bytes.subarray(0, 3).toString('ascii') === 'ID3'
        || bytes.length >= 2 && bytes[0] === 0xff && (bytes[1] & 0xe0) === 0xe0;
}

export function resolveOutputDir(value) {
    const raw = String(value ?? '').trim();
    if (!raw) return path.join(os.homedir(), 'Music', 'minimax');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Compare got vs expected in the message — a difference of a few bytes suggests truncation; re-run the request
  2. Increase your HTTP client's max response body size / disable streaming limits
  3. Fetch the audio over a direct connection to rule out proxy interference
  4. Log payload.extra_info.music_size against the decoded length; if MiniMax consistently reports wrong sizes, report it and verify the audio manually (e.g. play the WAV)

Example fix

// before: single attempt, hard failure
const bytes = decodeAudioHex(data.audio, expectedBytes, 'wav');
// after: re-fetch on mismatch
let bytes;
try {
  bytes = decodeAudioHex(data.audio, expectedBytes, 'wav');
} catch (e) {
  if (!/size mismatch/.test(e.message)) throw e;
  const retry = await fetchMusicAgain();
  bytes = decodeAudioHex(retry.data.audio, retry.extra_info?.music_size ?? null, 'wav');
}
Defensive patterns

Strategy: retry

Validate before calling

// After decoding, verify before writing:
const bytes = Buffer.from(data.audio, 'hex');
if (expectedBytes != null && bytes.length !== expectedBytes) {
  console.warn(`size mismatch: expected ${expectedBytes}, got ${bytes.length} — refetch`);
}

Type guard

function decodedSizeMatches(hex, expectedBytes) {
  const bytes = Buffer.from(hex, 'hex');
  return expectedBytes == null || bytes.length === expectedBytes;
}

Try / catch

try {
  const bytes = decodeAudioHex(value, expectedBytes, format);
} catch (e) {
  if (/size mismatch/.test(e.message)) {
    // retry the fetch once over a direct connection before giving up
  } else throw e;
}

Prevention

When it happens

Trigger: Network/proxy truncation of the response body; text-encoding mangling (e.g. the hex string passing through a UTF-16 or newline-joined transformation); mismatched music_size metadata from a buggy MiniMax job; double-decoding (decoding an already-decoded buffer re-encoded as hex).

Common situations: Corporate proxies or CDNs cutting off very large responses; shell pipelines stripping trailing characters from the hex string; custom HTTP clients with small default body buffers.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1f3c96d906c57d23. Report an issue: GitHub.