{"record":{"id":"84a2c158b12a06c8","repo":"pydantic/monty","slug":"resumenothandled-is-only-valid-for-os-call-snapshots","errorCode":null,"errorMessage":"resumeNotHandled is only valid for OS-call snapshots","messagePattern":"resumeNotHandled is only valid for OS-call snapshots","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/session.ts","lineNumber":1002,"sourceCode":"  }\n\n  /** Resumes as \"no such function\": the sandbox raises `NameError`. */\n  resumeNotFound(): Promise<Snapshot> {\n    this.claim()\n    return this.driver.resumeNotFound()\n  }\n\n  /** Registers the call as a pending future; other sandbox tasks keep\n   *  running and surface later as a [`FutureSnapshot`]. */\n  resumeFuture(): Promise<Snapshot> {\n    this.claim()\n    return this.driver.resumeFuture()\n  }\n\n  /** Resumes an OS call with monty's default unhandled behaviour. */\n  resumeNotHandled(): Promise<Snapshot> {\n    if (!this.isOsFunction) {\n      throw new Error('resumeNotHandled is only valid for OS-call snapshots')\n    }\n    this.claim()\n    return this.driver.resumeNotHandled()\n  }\n\n  /** Serializes the paused worker; restore with `session.loadSnapshot`. */\n  dump(): Promise<Buffer> {\n    return this.driver.dump()\n  }\n}\n\n/** A paused execution waiting for the value of an undefined name. */\nexport class NameLookupSnapshot extends SingleUse {\n  readonly variableName: string\n  /** Set for lazy attribute lookups on a host-backed object (a class\n   *  instance, or a class type): the receiver's store uuid. `null` for\n   *  plain name lookups. */\n  readonly objectId: string | null","sourceCodeStart":984,"sourceCodeEnd":1020,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/session.ts#L984-L1020","documentation":"`resumeNotHandled` tells monty to apply its default unhandled behaviour for an OS-call suspension. It is only meaningful when the snapshot paused on an OS function call; the method checks `isOsFunction` and throws this Error otherwise. This guards the protocol: every resume variant only accepts the suspension kind it was designed for.","triggerScenarios":"Calling `snapshot.resumeNotHandled()` when the snapshot was paused on an external-function call (`# call-external`) or a future rather than an `os`/OsFunctionCall suspension.","commonSituations":"A generic drive loop that handles all suspensions with one code path and unconditionally calls resumeNotHandled; confusion between external-function snapshots (resumeReturn/resumeError/resumeNotFound) and OS-call snapshots.","solutions":["Only call resumeNotHandled on snapshots representing OS calls; dispatch on the snapshot/turn kind first.","For external-function suspensions use resumeReturn/resumeError/resumeNotFound; for futures use resumeFuture.","In a generic driver, check the snapshot type (e.g. `instanceof OsFunctionSnapshot` or an `isOsFunction` flag) before choosing the resume method."],"exampleFix":"// before\nasync function resumeAny(snap: Snapshot) {\n  return snap.resumeNotHandled()\n}\n\n// after\nasync function resumeAny(snap: Snapshot) {\n  if (snap.isOsFunction) return snap.resumeNotHandled()\n  return snap.resumeNotFound()\n}","handlingStrategy":"type-guard","validationCode":"// Check snapshot kind before resuming:\n// if ('isOsFunction' in snap && snap.isOsFunction) { ... }\nconst isOsSnapshot = typeof (snap as { isOsFunction?: boolean }).isOsFunction === 'boolean'\n  ? (snap as { isOsFunction: boolean }).isOsFunction\n  : false","typeGuard":"function isOsCallSnapshot(snap: Snapshot): snap is Snapshot & { isOsFunction: true } {\n  return (snap as { isOsFunction?: boolean }).isOsFunction === true\n}","tryCatchPattern":"try {\n  await snap.resumeNotHandled()\n} catch (err) {\n  if (err instanceof Error && err.message.includes('resumeNotHandled is only valid')) {\n    await snap.resumeNotFound() // or dispatch per kind\n  } else {\n    throw err\n  }\n}","preventionTips":["Dispatch on the suspension kind before choosing a resume method.","External-function suspensions: resumeReturn/resumeError/resumeNotFound; OS calls: resumeNotHandled/resumeReturn-style; futures: resumeFuture.","Write the drive loop as an exhaustive switch over snapshot kinds so wrong-method calls are unrepresentable."],"tags":["typescript","os-call","snapshot","api-misuse"],"backgroundTag":"unsupported-operation","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"}