jackwener/OpenCLI · error · CommandExecutionError

MiniMax music returned a malformed response envelope

Error message

MiniMax music returned a malformed response envelope

What it means

A CommandExecutionError thrown by parseCompletedMusic() when the parsed JSON body is not a plain object — null, an array, or a non-object. MiniMax music responses must follow the {base_resp: {...}} envelope, so anything else cannot be interpreted as a generation result.

Source

Thrown at clis/minimax/utils.js:84

    } finally {
        clearTimeout(timer);
    }
    if (response.status === 401 || response.status === 403) {
        throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}).`);
    }
    if (!response.ok) {
        throw new CommandExecutionError(`MiniMax music returned HTTP ${response.status} from ${region.host}`);
    }
    try {
        return await response.json();
    } catch (error) {
        throw new CommandExecutionError(`MiniMax music returned malformed JSON: ${error?.message ?? error}`);
    }
}

export function parseCompletedMusic(payload, region) {
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        throw new CommandExecutionError('MiniMax music returned a malformed response envelope');
    }
    const base = payload.base_resp;
    if (!base || typeof base !== 'object' || !Number.isInteger(base.status_code)) {
        throw new CommandExecutionError('MiniMax music response is missing integer base_resp.status_code');
    }
    if (base.status_code !== 0) {
        const message = typeof base.status_msg === 'string' && base.status_msg.trim()
            ? `: ${base.status_msg.trim()}`
            : '';
        if (AUTH_CODES.has(base.status_code)) {
            throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (service ${base.status_code}${message}).`);
        }
        throw new CommandExecutionError(`MiniMax music failed (service ${base.status_code}${message})`);
    }
    const data = payload.data;
    if (!data || typeof data !== 'object' || Array.isArray(data) || !Number.isInteger(data.status)) {
        throw new CommandExecutionError('MiniMax music response is missing integer data.status');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the raw HTTP body before parsing to confirm what MiniMax actually returned.
  2. Retry the generation — a one-off gateway artifact often resolves on resubmission (check account history first to avoid double billing).
  3. Check MiniMax API changelog/docs for envelope changes if this recurs systematically.
  4. If you feed parseCompletedMusic manually (tests, scripts), pass the full response object, not a sub-field.

Example fix

// before
done(payload.data); // wrong: sub-object, envelope lost

// after
done(payload); // pass the full {base_resp, data} envelope
Defensive patterns

Strategy: type-guard

Type guard

function isMusicEnvelope(v) {
  return v != null && typeof v === 'object' && !Array.isArray(v);
}
// guard before parsing
if (!isMusicEnvelope(raw)) throw new Error('Unexpected non-object MiniMax response');

Try / catch

try {
  const done = parseCompletedMusic(payload, region);
} catch (e) {
  if (e instanceof CommandExecutionError && /malformed response envelope/.test(e.message)) {
    // log raw body, then retry the generation once
  } else throw e;
}

Prevention

When it happens

Trigger: parseCompletedMusic(payload) is called (via the completed step) with a payload that is null, undefined, an Array, or a primitive — e.g. the endpoint returned JSON like "ok", [], or null with HTTP 200, and that body was passed straight through.

Common situations: MiniMax changing or versioning their response schema; a gateway returning a bare JSON literal with 200; mocking/stubbing in tests that supplies the wrong envelope shape; proxy middleware rewriting bodies.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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