{"record":{"id":"c2ea190827507f77","repo":"can1357/oh-my-pi","slug":"assertion-failed-c2ea19","errorCode":null,"errorMessage":"Assertion failed","messagePattern":"Assertion failed","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/tab-worker.ts","lineNumber":1293,"sourceCode":"\t\tthis.#active = active;\n\t\tlet completed = false;\n\t\tlet returnValue: unknown;\n\t\tlet failure: { error: unknown } | undefined;\n\t\tlet runPage: RunPageScope | undefined;\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\trunPage = createRunPageScope(this.#requirePage());\n\t\t\tconst browser = this.#requireBrowser();\n\t\t\tconst tabApi = this.#createTabApi(msg.name, msg.timeoutMs, signal, msg.session, output, screenshots, active);\n\t\t\tconst runtime = this.#ensureRuntime(msg.session);\n\t\t\truntime.setCwd(msg.session.cwd);\n\t\t\tconst onFloatingRejection = (reason: unknown): void => this.#recordFloatingRejection(active, reason);\n\t\t\truntime.setRunScope({\n\t\t\t\tpage: bindRunFacade(runPage.page, signal, active.rejectionOwner, onFloatingRejection),\n\t\t\t\tbrowser: bindRunFacade(browser, signal, active.rejectionOwner, onFloatingRejection),\n\t\t\t\ttab: bindRunFacade(tabApi, signal, active.rejectionOwner, onFloatingRejection),\n\t\t\t\tassert: (cond: unknown, text?: string): void => {\n\t\t\t\t\tif (!cond) throw new ToolError(text ?? \"Assertion failed\");\n\t\t\t\t},\n\t\t\t\t// Both wait forms register in the in-flight map so a cell that dies while\n\t\t\t\t// sleeping/polling names the culprit instead of a bare whole-cell timeout.\n\t\t\t\twait: (msOrPredicate: number | (() => unknown), opts?: WaitPredicateOptions): Promise<unknown> => {\n\t\t\t\t\tconst label = typeof msOrPredicate === \"number\" ? `wait(${msOrPredicate}ms)` : \"wait(predicate)\";\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: { timeout: resolvePredicateTimeout(msg.timeoutMs, opts?.timeout), interval: opts?.interval };\n\t\t\t\t\treturn observeBrowserRunPromise(\n\t\t\t\t\t\tthis.#runOp(active, label, signal, Number.POSITIVE_INFINITY, sig =>\n\t\t\t\t\t\t\twaitForRun(msOrPredicate, sig, resolved),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tactive.rejectionOwner,\n\t\t\t\t\t\tonFloatingRejection,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t});","sourceCodeStart":1275,"sourceCodeEnd":1311,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/tab-worker.ts#L1275-L1311","documentation":"The browser-run sandbox exposes an `assert(cond, text?)` helper to user scripts; when the condition is falsy it throws this ToolError so the run cell fails with an explicit assertion message. It exists so in-page invariant checks surface as tool errors naming the failed assertion rather than silent bad state downstream.","triggerScenarios":"User automation code inside a browser-run cell calls `assert(...)` with a condition that evaluated false — e.g. asserting a selector matched, an element's text equals an expectation, or a URL/state check after navigation.","commonSituations":"Page rendered differently than the script assumed (A/B variant, locale, login wall); element not yet present at assert time (missing wait); wrong selector; flaky async content.","solutions":["Read the supplied assertion text (or the default 'Assertion failed') and fix the violated condition in the run script","Wait for the element/state before asserting (use the runtime's wait/predicate helpers)","Pass a descriptive message to assert() so failures are diagnosable: `assert(el, 'login button present')`","Re-run with snapshot/ariaSnapshot to inspect actual page state when the assertion is unexpected"],"exampleFix":"// before\nassert(page.$('.price'), 'Assertion failed');\n// after\nawait wait(() => page.$('.price'), { timeout: 5000 });\nassert(page.$('.price'), 'price element should appear after load');","handlingStrategy":"try-catch","validationCode":"// precondition check inside the run script before asserting\nconst el = page.$('.price');\nif (!el) throw new Error('price element missing — check selector/page state before assert');","typeGuard":null,"tryCatchPattern":"try {\n  await runCell(code);\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes('Assertion failed')) {\n    const snap = await tab.ariaSnapshot(); // inspect actual page state\n    logger.warn('run assertion failed', { snap });\n  } else throw err;\n}","preventionTips":["Always pass a descriptive message to assert()","Wait for elements/states before asserting on them","Keep assertions on stable, locale-independent page properties","Capture an ariaSnapshot in the failure path to debug unexpected assertions"],"tags":["assertion","browser-automation","user-code","tool-error"],"backgroundTag":"assertion-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}