{"record":{"id":"ef0818009224d289","repo":"can1357/oh-my-pi","slug":"assertion-failed-ef0818","errorCode":null,"errorMessage":"Assertion failed","messagePattern":"Assertion failed","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/computer/worker.ts","lineNumber":522,"sourceCode":"\t\t\tsignal,\n\t\t\treadOnly: message.session.readOnly,\n\t\t\tsnapshot: message.session,\n\t\t\toutput,\n\t\t\tscreenshots,\n\t\t};\n\t\tlet returnValue: unknown;\n\t\tlet failure: { error: unknown } | undefined;\n\t\tlet completed = false;\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst session = this.#ensureSession(message.session);\n\t\t\tconst runtime = this.#ensureRuntime(message.session);\n\t\t\truntime.setCwd(message.session.cwd);\n\t\t\tconst desktop = this.#createDesktopScope(session);\n\t\t\truntime.setRunScope({\n\t\t\t\tdesktop: bindRunFacade(desktop, signal),\n\t\t\t\tassert: (condition: unknown, text?: string): void => {\n\t\t\t\t\tif (!condition) throw new ToolError(text ?? \"Assertion failed\");\n\t\t\t\t},\n\t\t\t\twait: (msOrPredicate: number | (() => unknown), options?: WaitPredicateOptions): Promise<unknown> => {\n\t\t\t\t\tconst resolved =\n\t\t\t\t\t\ttypeof msOrPredicate === \"number\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\ttimeout: resolvePredicateTimeout(message.timeoutMs, options?.timeout),\n\t\t\t\t\t\t\t\t\tinterval: options?.interval,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\treturn markHandled(waitForRun(msOrPredicate, signal, resolved));\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst { promise: cancelRejection, reject: rejectCancel } = Promise.withResolvers<never>();\n\t\t\tconst onCancel = (): void => {\n\t\t\t\tconst abortError =\n\t\t\t\t\tsignal.reason instanceof ToolAbortError\n\t\t\t\t\t\t? signal.reason\n\t\t\t\t\t\t: new ToolAbortError(undefined, { cause: signal.reason });","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/computer/worker.ts#L504-L540","documentation":"The computer-run sandbox exposes an assert(condition, text?) helper to agent scripts; when the condition is falsy it throws ToolError with the provided text or the default 'Assertion failed'. This is an in-script assertion mechanism — the script's own check failed, surfacing as a tool error with the run's context.","triggerScenarios":"Computer-run code calls assert(someCondition) and the condition evaluates falsy (e.g. a window lookup returned nothing, a value didn't change, a UI state wasn't reached).","commonSituations":"Scripts verify a window exists before interacting (assert(win)) but the app isn't open/titled as expected; polling predicates time out and a later assert trips; agents use assert as a guard and pass undefined when lookups fail.","solutions":["Inspect the run's surrounding context to see which assertion tripped; pass a descriptive text argument to assert for diagnosability.","Verify the precondition (app running, window title, expected value) before asserting; use wait(predicate) to await UI state instead of asserting immediately.","Wrap assertions in try/catch inside the script if failure should degrade gracefully rather than fail the run."],"exampleFix":"// inside computer run code\n// before\nassert(win, \"Assertion failed\");\n\n// after\nconst win = await desktop.win({ app: \"Notes\" });\nassert(win, `Notes window not found (visible: ${JSON.stringify(await desktop.windows())})`);","handlingStrategy":"try-catch","validationCode":"// inside computer run code: check the precondition before asserting\nconst win = await desktop.win({ app: \"Notes\" });\nif (!win) throw new Error(\"Notes window missing — open it before asserting\");","typeGuard":null,"tryCatchPattern":"// inside computer run code\ntry {\n  assert(condition, \"descriptive failure text\");\n} catch (e) {\n  await desktop.screenshot(); // capture state for diagnosis\n  throw e;\n}","preventionTips":["Always pass a descriptive second argument to assert() so failures are diagnosable.","Use wait(predicate, options) to await UI state instead of asserting immediately after an action.","Verify apps/windows exist before asserting on their properties."],"tags":["assertion","script","computer-tool","tool-error"],"backgroundTag":"assertion-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}