can1357/oh-my-pi · error · ToolError
Assertion failed
Error message
Assertion failed
What it means
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.
Source
Thrown at packages/coding-agent/src/tools/computer/worker.ts:522
signal,
readOnly: message.session.readOnly,
snapshot: message.session,
output,
screenshots,
};
let returnValue: unknown;
let failure: { error: unknown } | undefined;
let completed = false;
try {
throwIfAborted(signal);
const session = this.#ensureSession(message.session);
const runtime = this.#ensureRuntime(message.session);
runtime.setCwd(message.session.cwd);
const desktop = this.#createDesktopScope(session);
runtime.setRunScope({
desktop: bindRunFacade(desktop, signal),
assert: (condition: unknown, text?: string): void => {
if (!condition) throw new ToolError(text ?? "Assertion failed");
},
wait: (msOrPredicate: number | (() => unknown), options?: WaitPredicateOptions): Promise<unknown> => {
const resolved =
typeof msOrPredicate === "number"
? undefined
: {
timeout: resolvePredicateTimeout(message.timeoutMs, options?.timeout),
interval: options?.interval,
};
return markHandled(waitForRun(msOrPredicate, signal, resolved));
},
});
const { promise: cancelRejection, reject: rejectCancel } = Promise.withResolvers<never>();
const onCancel = (): void => {
const abortError =
signal.reason instanceof ToolAbortError
? signal.reason
: new ToolAbortError(undefined, { cause: signal.reason });View on GitHub (pinned to 9690622007)
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.
Example fix
// inside computer run code
// before
assert(win, "Assertion failed");
// after
const win = await desktop.win({ app: "Notes" });
assert(win, `Notes window not found (visible: ${JSON.stringify(await desktop.windows())})`); Defensive patterns
Strategy: try-catch
Validate before calling
// inside computer run code: check the precondition before asserting
const win = await desktop.win({ app: "Notes" });
if (!win) throw new Error("Notes window missing — open it before asserting"); Try / catch
// inside computer run code
try {
assert(condition, "descriptive failure text");
} catch (e) {
await desktop.screenshot(); // capture state for diagnosis
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Assertion failed
- Computer session tool bridge is unavailable
- Computer session is closed
- ${error.message} (rethrown as ToolError from StructuredSubag
- pr://${repo}/${parsed.number}/diff/${index} resolved to a mi
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/ef0818009224d289.
Report an issue: GitHub.