{"record":{"id":"c7d938b57e368d90","repo":"moeru-ai/airi","slug":"expectation-failed-expected-distance-maxdist","errorCode":null,"errorMessage":"Expectation failed: Expected distance <= ${maxDist}, got ${distance}","messagePattern":"Expectation failed: Expected distance <= (.+?), got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"integrations/minecraft/src/cognitive/conscious/js-planner.ts","lineNumber":1299,"sourceCode":"    }\n\n    const dx = endPos.x - target.x\n    const dy = endPos.y - target.y\n    const dz = endPos.z - target.z\n    distance = Math.sqrt(dx * dx + dy * dy + dz * dz)\n  }\n  else if (typeof globalThis.lastAction?.result?.distanceToTargetAfter === 'number') {\n    distance = globalThis.lastAction.result.distanceToTargetAfter\n  }\n\n  if (distance === null) {\n    throw new Error('Expectation failed: expectNear() requires target argument or last action distanceToTargetAfter telemetry')\n  }\n\n  if (distance <= maxDist)\n    return true\n\n  throw new Error(\n    'Expectation failed: ' + __plannerExpectationDetail(message, 'Expected distance <= ' + maxDist + ', got ' + distance),\n  )\n}\n\nglobalThis.use = (toolName, params = {}) => {\n  if (typeof toolName !== 'string' || toolName.length === 0)\n    throw new Error('use(toolName, params) requires a non-empty string toolName')\n\n  const invocationArgs = params && typeof params === 'object' && !Array.isArray(params) ? [params] : [{}]\n  const runtimeResult = __plannerCallBridge('tool', [toolName, invocationArgs])\n  globalThis.lastAction = runtimeResult\n  globalThis.lastRun.actions.push(runtimeResult)\n  return runtimeResult\n}\n\nglobalThis.skip = () => globalThis.use('skip', {})\n\nfor (const toolName of __plannerActionNames) {","sourceCodeStart":1281,"sourceCodeEnd":1317,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/integrations/minecraft/src/cognitive/conscious/js-planner.ts#L1281-L1317","documentation":"The final failing branch of globalThis.expectNear: a distance WAS computed (either from endPos vs target, or from distanceToTargetAfter) but it exceeds maxDist (default 2). The throw message reports both the threshold and the measured distance. This is the genuine proximity-failure case, distinct from the missing-telemetry cases.","triggerScenarios":"A movement action completed but the bot ended farther than maxDist from the target; pathfinder stopped short due to an obstacle; the bot was pushed/knocked back after arriving; maxDist set too tight for the action's stopping radius; goal rangeGoal larger than the expectNear tolerance.","commonSituations":"pathfinder GoalNear range larger than expectNear maxDist; terrain/liquid blocking the last block; bot attacked and knocked away; target is itself moving; coordinates stale relative to the live world.","solutions":["Increase maxDist to match the movement action's realistic stopping radius.","Issue a follow-up moveTo to close the remaining gap before asserting.","Use a movement action whose goal radius is tighter than the expectNear tolerance.","Re-read the target position immediately before moving in case it moved."],"exampleFix":"// before\n//   await use('moveTo', { x: 10, y: 64, z: -5 })\n//   expectNear({ x: 10, y: 64, z: -5 }, 1)  // throws: got 1.8\n//\n// after\n//   await use('moveTo', { x: 10, y: 64, z: -5 })\n//   expectNear({ x: 10, y: 64, z: -5 }, 2.5)","handlingStrategy":"validation","validationCode":"// Before asserting, check the computed distance against your tolerance:\n// const end = globalThis.lastAction?.result?.endPos\n// if (end) {\n//   const d = Math.hypot(end.x - target.x, end.y - target.y, end.z - target.z)\n//   if (d > maxDist) await use('moveTo', target)  // close the gap first\n// }\n// expectNear(target, maxDist)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set maxDist at least as large as the movement action's goal radius.","Issue a follow-up moveTo to close residual distance before expectNear.","Re-read the target coordinates immediately before moving (it may have moved).","Account for knockback/obstacles by tolerating a larger radius."],"tags":["llm-planner","sandbox","assertion","expectnear","proximity"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}