{"record":{"id":"aa35acb7e207fbc1","repo":"microsoft/typescript-go","slug":"invalid-message-type-from-child-this-msgtype","errorCode":null,"errorMessage":"Invalid message type from child: ${this._msgType}","messagePattern":"Invalid message type from child: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"_packages/native-preview/src/api/syncChannel.ts","lineNumber":324,"sourceCode":"                    if (this.collectTiming) {\r\n                        this.lastBytesReceived = this._msgPayload.length;\r\n                    }\r\n                    return this._msgPayload;\r\n                }\r\n                case MSG_ERROR: {\r\n                    if (methodBuf.equals(this._msgName)) {\r\n                        throw new Error(this._msgPayload.toString(\"utf-8\"));\r\n                    }\r\n                    throw new Error(\r\n                        `name mismatch for response: expected \\`${method}\\`, got \\`${this._msgName.toString(\"utf-8\")}\\``,\r\n                    );\r\n                }\r\n                case MSG_CALL: {\r\n                    this.handleCall(this._msgName.toString(\"utf-8\"), this._msgPayload);\r\n                    break;\r\n                }\r\n                default:\r\n                    throw new Error(`Invalid message type from child: ${this._msgType}`);\r\n            }\r\n        }\r\n    }\r\n\r\n    // ── Callback handling ───────────────────────────────────────────\r\n\r\n    /**\r\n     * Handle an incoming MSG_CALL from the child process.\r\n     *\r\n     * After sending the error response back to the child, this method\r\n     * intentionally re-throws to abort the caller's request loop.\r\n     * A failed callback is treated as unrecoverable to match the\r\n     * behavior of the native libsyncrpc addon.\r\n     */\r\n    private handleCall(name: string, payload: Buffer): void {\r\n        const cb = this.callbacks.get(name);\r\n        if (!cb) {\r\n            const errMsg = `unknown callback: \\`${name}\\`. Please make sure to register it on the JavaScript side before invoking it.`;\r","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/_packages/native-preview/src/api/syncChannel.ts#L306-L342","documentation":"Thrown by the parent side of the synchronous MessagePack RPC channel (SyncChannel) when an incoming [type, name, payload] tuple parses correctly but its type byte is neither MSG_RESPONSE nor MSG_CALL. It means the child process is speaking a different revision of the wire protocol than the JavaScript host expects.","triggerScenarios":"Reading a response loop iteration after the framing decoded a tuple whose first element is an unknown message type constant — typically a Go child binary built from a newer/older commit than the @typescript/native-preview JS package driving it.","commonSituations":"Mixed versions: a locally built tsgo child paired with an npm-installed native-preview host (or vice versa); stale child binary cached on disk after upgrading the package; protocol constants changed in a refactor.","solutions":["Rebuild or re-download the native child binary so it matches the installed @typescript/native-preview version (the package's postinstall/download step)","Delete any stale cached tsgo binary and reinstall the package","Check that nothing else writes into the child's stdin/stdout","If developing the protocol, verify the MSG_* constants in syncChannel.ts and the Go child agree"],"exampleFix":"// before\nconst channel = new SyncChannel(oldCachedChildPath, args);\n\n// after\n// force re-download of the child matching the host package\nawait ensureValidCachedBinary(version); // reinstall/update @typescript/native-preview\nconst channel = new SyncChannel(cachedBinaryPathFor(version), args);","handlingStrategy":"validation","validationCode":"import { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\nconst hostPkg = require('@typescript/native-preview/package.json').version;\n// ensure the spawned child binary was produced for this host version\nclassert(childVersionTag === hostPkg.version, 'host/child version skew');","typeGuard":null,"tryCatchPattern":"try { channel.call(/* ... */); } catch (e) { if (String(e.message).startsWith('Invalid message type from child')) { /* respawn child with matching version */ } throw e; }","preventionTips":["Always spawn the child via the package's own binary-resolution helper","Pin host and child versions together in lockfiles","Never write raw logs to the child's stdout"],"tags":["rpc","protocol","messagepack","native-preview","version-mismatch"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}