microsoft/typescript-go · critical · Error

name mismatch for response: expected `${method}`, got `${thi

Error message

name mismatch for response: expected `${method}`, got `${this._msgName.toString("utf-8")}`

What it means

In the request loop, a MSG_RESPONSE frame must echo the method name of the outstanding request. The channel is strictly synchronous (one request, one matched reply), so receiving a response named differently from the request means the message stream is out of alignment — responses are being matched to the wrong calls. The channel throws rather than returning mismatched payloads, because the payload would belong to a different method.

Source

Thrown at _packages/native-preview/src/api/syncChannel.ts:302

    private requestBytesSync(method: string, payload: Buffer | Uint8Array | string): Buffer {
        const methodBuf = this.getMethodBuf(method);
        if (this.collectTiming) {
            this.lastBytesSent = typeof payload === "string"
                ? Buffer.byteLength(payload, "utf-8")
                : payload.length;
            this.lastBytesReceived = 0;
        }
        this.writeTuple(MSG_REQUEST, methodBuf, payload);

        for (;;) {
            this.readTuple();

            switch (this._msgType) {
                case MSG_RESPONSE: {
                    // Compare raw bytes instead of decoding to string.
                    if (!methodBuf.equals(this._msgName)) {
                        throw new Error(
                            `name mismatch for response: expected \`${method}\`, got \`${this._msgName.toString("utf-8")}\``,
                        );
                    }
                    if (this.collectTiming) {
                        this.lastBytesReceived = this._msgPayload.length;
                    }
                    return this._msgPayload;
                }
                case MSG_ERROR: {
                    if (methodBuf.equals(this._msgName)) {
                        throw new Error(this._msgPayload.toString("utf-8"));
                    }
                    throw new Error(
                        `name mismatch for response: expected \`${method}\`, got \`${this._msgName.toString("utf-8")}\``,
                    );
                }
                case MSG_CALL: {
                    this.handleCall(this._msgName.toString("utf-8"), this._msgPayload);

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Update @typescript/native-preview so client and bundled binary match
  2. Recreate the Client — the channel state is untrustworthy after desync and cannot recover in place
  3. Report upstream with both names from the message ('expected X, got Y') — it localizes the desync
Defensive patterns

Strategy: fallback

Try / catch

try { resp = channel.request(method, payload); } catch (e) { if ((e as Error).message.includes("name mismatch for response")) { /* channel desynced: recreate Client, do not reuse */ } else throw e; }

Prevention

When it happens

Trigger: Protocol desync: a previous request/response got corrupted or partially read (transport issue), the server emitted frames out of order, or client and server disagree on the framing protocol (version mismatch). Should never happen in normal operation.

Common situations: Client package and tsgo binary from different releases; corrupted pipe data on flaky transports; a bug in the channel or server framing. Essentially always a bug report candidate, not a caller error.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/326103a3417b3501. Report an issue: GitHub.