{"record":{"id":"742c77900fbabe5c","repo":"pydantic/monty","slug":"dump-returned-an-unexpected-event","errorCode":null,"errorMessage":"Dump returned an unexpected event","messagePattern":"Dump returned an unexpected event","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/worker/transport.ts","lineNumber":244,"sourceCode":"    return this.turn(\n      {\n        tag: 'resume-futures',\n        val: results.map((result) => ({\n          callId: result.callId,\n          outcome: result.ok\n            ? { tag: 'return-value', val: encodeValue(result.value) }\n            : errorResult(result.excType ?? 'RuntimeError', result.message ?? ''),\n        })),\n      },\n      onPrint,\n    )\n  }\n\n  /** Dumps the current session into opaque bytes. */\n  async dump(): Promise<Uint8Array> {\n    const event = await this.control({ tag: 'dump' }, 'dump-result', 'Dump')\n    if (event.tag === 'dump-result') return event.val\n    throw new Error('Dump returned an unexpected event')\n  }\n\n  /** Restores a previously dumped session into this fresh worker. */\n  async restore(\n    state: Uint8Array,\n    mounts: readonly unknown[],\n    onPrint: OnPrint,\n  ): Promise<NativeTurn | { kind: 'loaded' }> {\n    if (mounts.length > 0) {\n      throw new Error('the wasm worker does not support filesystem mounts (browser has no host filesystem)')\n    }\n    const event = await this.run({ tag: 'load', val: state }, onPrint)\n    if (!event) return crashed('worker exited without a turn-ending event')\n    return event.tag === 'ok' ? { kind: 'loaded' } : this.enforceSuspensionLimit(this.toTurn(event), onPrint)\n  }\n\n  /** Resets a live worker for reuse and disposes a dead worker. */\n  async finish(): Promise<void> {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/worker/transport.ts#L226-L262","documentation":"`session.dump()` sends a dump control request to the worker and expects exactly one `dump-result` event back. If the worker answers with a different event tag, the transport's internal protocol invariant is broken, so it throws instead of returning bogus bytes. This indicates a worker/protocol mismatch rather than bad user input.","triggerScenarios":"The worker responds to a `{ tag: 'dump' }` control request with an event other than `dump-result` — e.g. a crashed/terminated worker surfaced a terminator event, or the wasm component and JS transport versions disagree on the event schema.","commonSituations":"Mixed-version deployments where the compiled wasm component is older/newer than the TypeScript layer; a worker that died mid-request so `run` returned a stale/terminator event; custom forks of the worker protocol changing event tags.","solutions":["Rebuild the wasm component and refresh the WIT-derived declarations together (`make build-wasm`) so the component and `ts/worker` agree on the protocol.","Verify the session's worker is alive (no prior crash/terminate) before dumping; create a fresh session/pool if the worker crashed.","Check that the installed `@pydantic/monty` JS version and the compiled component come from the same source tree / release.","If reproducible, file a bug with the event tag observed — this path should be unreachable for compliant workers."],"exampleFix":"// before\n// component built from an older revision than ts/worker\nconst bytes = await session.dump() // unexpected event tag\n\n// after\nmake build-wasm   # rebuild component + regenerate checked-in declarations\nnpm run build      # rebuild TS layer against them\nconst bytes = await session.dump()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  bytes = await session.dump()\n} catch (err) {\n  if (err instanceof Error && err.message === 'Dump returned an unexpected event') {\n    // protocol skew or dead worker: rebuild session / re-verify component build\n    session = await pool.checkout()\n  } else throw err\n}","preventionTips":["Always build the component and TS layer from the same revision.","Never hand-edit generated WIT-derived component files.","Ensure prior turns completed before issuing dump().","Report reproducible occurrences as protocol bugs with the observed tag."],"tags":["protocol","wasm","wasm-worker","internal"],"backgroundTag":"unexpected-response-shape","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}