{"record":{"id":"78a6ad5d54ae9c4e","repo":"can1357/oh-my-pi","slug":"assertion-failed","errorCode":null,"errorMessage":"Assertion failed","messagePattern":"Assertion failed","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/cmux/cmux-tab.ts","lineNumber":1443,"sourceCode":"\t\t\t);\n\t\t}\n\t};\n\tif (signal.aborted) onAbort();\n\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\n\ttry {\n\t\tconst runtime = tab.ensureRuntime(opts.snapshot);\n\t\t// setCwd is non-exclusive; setRunScope/run still assert same-realm ownership.\n\t\t// Keep both inside try so a concurrent in-process eval/browser run surfaces as\n\t\t// a rejected promise the supervisor can report, never an unhandled rejection.\n\t\truntime.setCwd(opts.snapshot.cwd);\n\t\tconst runTab = bindRunFacade(tab, signal, rejectionOwner, recordFloatingFailure);\n\t\truntime.setRunScope({\n\t\t\tpage: bindRunFacade(tab.page, signal, rejectionOwner, recordFloatingFailure),\n\t\t\tbrowser: bindRunFacade(tab.browser, signal, rejectionOwner, recordFloatingFailure),\n\t\t\ttab: runTab,\n\t\t\tassert: (cond: unknown, text?: string): void => {\n\t\t\t\tif (!cond) throw new ToolError(text ?? \"Assertion failed\");\n\t\t\t},\n\t\t\twait: (msOrPredicate: number | (() => unknown), waitOpts?: WaitPredicateOptions): Promise<unknown> =>\n\t\t\t\tobserveBrowserRunPromise(\n\t\t\t\t\twaitForRun(\n\t\t\t\t\t\tmsOrPredicate,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttypeof msOrPredicate === \"number\"\n\t\t\t\t\t\t\t? waitOpts\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\ttimeout: resolvePredicateTimeout(opts.timeoutMs, waitOpts?.timeout),\n\t\t\t\t\t\t\t\t\tinterval: waitOpts?.interval,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t).catch(error => {\n\t\t\t\t\t\tthrow markBrowserRunRejection(error, rejectionOwner);\n\t\t\t\t\t}),\n\t\t\t\t\trejectionOwner,\n\t\t\t\t\trecordFloatingFailure,\n\t\t\t\t),","sourceCodeStart":1425,"sourceCodeEnd":1461,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/cmux/cmux-tab.ts#L1425-L1461","documentation":"Inside a cmux browser run, `assert(cond, text?)` is exposed in the run scope; when the condition is falsy it throws a ToolError with the provided text or the default \"Assertion failed\". It lets agent-run scripts encode expectations that abort the run on violation.","triggerScenarios":"Calling assert(...) in run-scope code with a falsy condition and no message: failed DOM checks, unexpected return values from evaluate, missing elements or state before proceeding.","commonSituations":"Assertions written against a page that changed structure; assert used where a wait was needed (element not yet present); truthiness bugs (assert on 0/''/null results from evaluate).","solutions":["Add a descriptive message to every assert call so failures are diagnosable instead of the generic text.","Check the asserted condition against the live page — use waitFor before asserting element existence.","Beware falsy evaluate results (0, '', null): assert on the precise value (`=== expected`) rather than truthiness."],"exampleFix":"// before\nassert(rows.length);\n// after\nassert(rows.length > 0, `expected result rows, got ${rows.length}`);","handlingStrategy":"try-catch","validationCode":"const rows = await tab.evaluate(`document.querySelectorAll('.row').length`);\nif (!(rows > 0)) await tab.waitFor('.row', { timeoutMs: 10000 });","typeGuard":null,"tryCatchPattern":"try {\n  assert(rows.length > 0, `expected rows, got ${rows.length}`);\n} catch (err) {\n  if (err instanceof ToolError && err.message === 'Assertion failed') {\n    // capture diagnostics (screenshot, current URL) before rethrowing\n    await tab.screenshot('assert-failure.png');\n  }\n  throw err;\n}","preventionTips":["Always pass a descriptive message to assert().","Wait for state before asserting it; assertions are not waits.","Assert with strict comparisons to avoid falsy-value surprises (0, '', null)."],"tags":["assertion","browser-automation","run-scope"],"backgroundTag":"assertion-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}