moeru-ai/airi · warning · Error
Expectation failed: Condition evaluated to false
Error message
Expectation failed: Condition evaluated to false
What it means
globalThis.expect(condition, message) is a sandbox-side assertion helper injected into the planner worker isolate. It is the planner script's own invariant check: if the boolean condition is falsy it throws 'Expectation failed: <detail>'. The detail defaults to 'Condition evaluated to false' when no message is supplied, via __plannerExpectationDetail. Unlike an internal planner error, this is the model's own script signalling that a postcondition it assumed did not hold, so the run aborts and the expectation text is returned to the model for self-correction.
Source
Thrown at integrations/minecraft/src/cognitive/conscious/js-planner.ts:1227
globalThis.patterns = __plannerPatternsAvailable
? {
get: id => __plannerCallBridge('patterns.get', [id]),
find: (query, limit = 10) => __plannerCallBridge('patterns.find', [query, limit]),
ids: () => __plannerCallBridge('patterns.ids', []),
list: (limit = 10) => __plannerCallBridge('patterns.list', [limit]),
}
: null
globalThis.log = (...args) => {
const rendered = __plannerLogRef(...args)
globalThis.lastRun.logs.push(rendered)
return rendered
}
globalThis.expect = (condition, message) => {
if (condition)
return true
throw new Error(
'Expectation failed: ' + __plannerExpectationDetail(message, 'Condition evaluated to false'),
)
}
globalThis.expectMoved = (minBlocks, message) => {
const threshold = typeof minBlocks === 'number' ? minBlocks : 0.5
const actionName = globalThis.lastAction?.action?.tool
const nonMovingActions = [
'chat', 'giveUp', 'skip', 'stop', 'followPlayer', 'clearFollowTarget',
'givePlayer', 'consume', 'equip', 'putInChest', 'takeFromChest', 'discard',
'collectBlocks', 'mineBlockAt', 'craftRecipe', 'smeltItem', 'clearFurnace',
'placeHere', 'attack', 'attackPlayer', 'activate', 'recipePlan',
]
if (!globalThis.lastAction || (typeof actionName === 'string' && nonMovingActions.includes(actionName)))
return true
const movedDistance = typeof globalThis.lastAction?.result?.movedDistance === 'number'View on GitHub (pinned to 27111382b4)
Solutions
- Inspect the expectation message in the returned run error and adjust the precondition or the preceding action.
- Log the relevant value with log() immediately before expect() so the run logs show why it was falsy.
- Guard with a truthful check or supply a descriptive message so the model gets actionable detail: expect(ok, 'moveTo succeeded').
- Ensure the asserted value is awaited and not a Promise object.
Example fix
// before
// const r = await use('moveTo', { x: 10, y: 64, z: -5 })
// expect(r.ok) // throws with opaque 'Condition evaluated to false'
//
// after
// const r = await use('moveTo', { x: 10, y: 64, z: -5 })
// log('moveTo result', JSON.stringify(r))
// expect(r.ok, `moveTo to (10,64,-5) succeeded, got: ${JSON.stringify(r)}`) Defensive patterns
Strategy: try-catch
Try / catch
// Inside the sandbox script, wrap expect() so a failure is observable instead of fatal:
// function tryExpect(cond, msg) {
// try { expect(cond, msg); return true }
// catch (e) { log('expect failed:', String(e)); return false }
// } Prevention
- Log the asserted value with log() right before expect() so the run logs explain the failure.
- Always pass a descriptive message to expect() for actionable model feedback.
- Await any async value before asserting on it; a Promise is truthy and will pass falsely.
- Prefer the targeted helpers (expectMoved, expectNear) over generic expect for movement invariants.
When it happens
Trigger: A planner script calls expect(someBoolean) where someBoolean resolves to false, 0, '', null, undefined, or NaN. Common: expect(nearTarget) after a moveTo where nearTarget was computed from stale telemetry; expect(inventory.has('diamond_pickaxe')) when the item is absent; expect(result.ok) on a failed action result.
Common situations: Model writes optimistic assertions without checking telemetry shape first; stale globalThis.lastAction from a previous turn; querying inventory/movement state before the action result is populated; using expect on a Promise (truthy object) instead of awaiting it.
Related errors
- Expectation failed: Expected movedDistance >= ${threshold},
- Expectation failed: expectNear(target) requires last action
- Expectation failed: expectNear() requires target argument or
- Expectation failed: Expected distance <= ${maxDist}, got ${d
- Your last reply was natural language, not JavaScript, so not
AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12).
Data as JSON: /api/errors/25ae4d5b242257a7.
Report an issue: GitHub.