{"record":{"id":"4a32cc289eef5421","repo":"moeru-ai/airi","slug":"expectation-failed-expectnear-requires-target-a","errorCode":null,"errorMessage":"Expectation failed: expectNear() requires target argument or last action distanceToTargetAfter telemetry","messagePattern":"Expectation failed: expectNear\\(\\) requires target argument or last action distanceToTargetAfter telemetry","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"integrations/minecraft/src/cognitive/conscious/js-planner.ts","lineNumber":1293,"sourceCode":"\n  let distance = null\n  if (target) {\n    const endPos = globalThis.lastAction?.result?.endPos\n    if (!endPos || typeof endPos.x !== 'number' || typeof endPos.y !== 'number' || typeof endPos.z !== 'number') {\n      throw new Error('Expectation failed: expectNear(target) requires last action result with endPos telemetry')\n    }\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)","sourceCodeStart":1275,"sourceCodeEnd":1311,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/integrations/minecraft/src/cognitive/conscious/js-planner.ts#L1275-L1311","documentation":"globalThis.expectNear() with no target coordinate argument falls back to reading globalThis.lastAction.result.distanceToTargetAfter. If that telemetry number is also absent (no target supplied AND no fallback distance), the helper has nothing to compare against maxDist and throws. This is the no-argument / distance-only overload's precondition failure.","triggerScenarios":"Calling expectNear() or expectNear(2) with no target object and the last action result lacks distanceToTargetAfter; calling expectNear before any action ran; the preceding action does not report distanceToTargetAfter (only some movement actions do).","commonSituations":"Expecting the helper to auto-target the last moveTo destination but the action did not populate distanceToTargetAfter; first call in a turn with globalThis.lastAction null; result schema change dropped the field.","solutions":["Pass an explicit target {x,y,z} to expectNear so it does not depend on distanceToTargetAfter.","Call a movement action that reports distanceToTargetAfter before the no-target expectNear.","Log globalThis.lastAction.result to confirm which telemetry fields the action actually provides."],"exampleFix":"// before\n//   expectNear(2)  // throws: no target and no distanceToTargetAfter\n//\n// after\n//   expectNear({ x: 10, y: 64, z: -5 }, 2)","handlingStrategy":"validation","validationCode":"// Before the no-target expectNear, confirm fallback telemetry:\n// if (typeof globalThis.lastAction?.result?.distanceToTargetAfter === 'number') {\n//   expectNear(maxDist)\n// } else {\n//   expectNear(explicitTarget, maxDist)  // pass a target instead\n// }","typeGuard":"function hasDistanceAfter(r: unknown): r is { distanceToTargetAfter: number } {\n  return !!r && typeof r === 'object' && typeof (r as any).distanceToTargetAfter === 'number'\n}","tryCatchPattern":null,"preventionTips":["Pass an explicit target {x,y,z} when you cannot rely on distanceToTargetAfter.","Confirm the preceding action actually reports distanceToTargetAfter.","Log lastAction.result before the assertion to verify telemetry shape."],"tags":["llm-planner","sandbox","assertion","expectnear","telemetry"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}