{"record":{"id":"25ae4d5b242257a7","repo":"moeru-ai/airi","slug":"expectation-failed-condition-evaluated-to-false","errorCode":null,"errorMessage":"Expectation failed: Condition evaluated to false","messagePattern":"Expectation failed: Condition evaluated to false","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"integrations/minecraft/src/cognitive/conscious/js-planner.ts","lineNumber":1227,"sourceCode":"globalThis.patterns = __plannerPatternsAvailable\n  ? {\n      get: id => __plannerCallBridge('patterns.get', [id]),\n      find: (query, limit = 10) => __plannerCallBridge('patterns.find', [query, limit]),\n      ids: () => __plannerCallBridge('patterns.ids', []),\n      list: (limit = 10) => __plannerCallBridge('patterns.list', [limit]),\n    }\n  : null\n\nglobalThis.log = (...args) => {\n  const rendered = __plannerLogRef(...args)\n  globalThis.lastRun.logs.push(rendered)\n  return rendered\n}\n\nglobalThis.expect = (condition, message) => {\n  if (condition)\n    return true\n  throw new Error(\n    'Expectation failed: ' + __plannerExpectationDetail(message, 'Condition evaluated to false'),\n  )\n}\n\nglobalThis.expectMoved = (minBlocks, message) => {\n  const threshold = typeof minBlocks === 'number' ? minBlocks : 0.5\n  const actionName = globalThis.lastAction?.action?.tool\n  const nonMovingActions = [\n    'chat', 'giveUp', 'skip', 'stop', 'followPlayer', 'clearFollowTarget',\n    'givePlayer', 'consume', 'equip', 'putInChest', 'takeFromChest', 'discard',\n    'collectBlocks', 'mineBlockAt', 'craftRecipe', 'smeltItem', 'clearFurnace',\n    'placeHere', 'attack', 'attackPlayer', 'activate', 'recipePlan',\n  ]\n\n  if (!globalThis.lastAction || (typeof actionName === 'string' && nonMovingActions.includes(actionName)))\n    return true\n\n  const movedDistance = typeof globalThis.lastAction?.result?.movedDistance === 'number'","sourceCodeStart":1209,"sourceCodeEnd":1245,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/integrations/minecraft/src/cognitive/conscious/js-planner.ts#L1209-L1245","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n//   const r = await use('moveTo', { x: 10, y: 64, z: -5 })\n//   expect(r.ok)  // throws with opaque 'Condition evaluated to false'\n//\n// after\n//   const r = await use('moveTo', { x: 10, y: 64, z: -5 })\n//   log('moveTo result', JSON.stringify(r))\n//   expect(r.ok, `moveTo to (10,64,-5) succeeded, got: ${JSON.stringify(r)}`)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Inside the sandbox script, wrap expect() so a failure is observable instead of fatal:\n// function tryExpect(cond, msg) {\n//   try { expect(cond, msg); return true }\n//   catch (e) { log('expect failed:', String(e)); return false }\n// }","preventionTips":["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."],"tags":["llm-planner","sandbox","assertion","expect"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}