moeru-ai/airi · warning · Error

Expectation failed: expectNear(target) requires last action

Error message

Expectation failed: expectNear(target) requires last action result with endPos telemetry

What it means

Inside globalThis.expectNear(target, ...), when a target coordinate object {x,y,z} is supplied, the helper computes Euclidean distance from globalThis.lastAction.result.endPos to the target. If endPos is absent or not a full numeric {x,y,z}, it cannot compute distance and throws this message. The expectation is that movement actions report an endPos telemetry field; without it the proximity check is impossible.

Source

Thrown at integrations/minecraft/src/cognitive/conscious/js-planner.ts:1280

  if (targetOrMaxDist && typeof targetOrMaxDist === 'object' && typeof targetOrMaxDist.x === 'number' && typeof targetOrMaxDist.y === 'number' && typeof targetOrMaxDist.z === 'number') {
    target = { x: targetOrMaxDist.x, y: targetOrMaxDist.y, z: targetOrMaxDist.z }
    if (typeof maxDistOrMessage === 'number')
      maxDist = maxDistOrMessage
    if (typeof maybeMessage === 'string')
      message = maybeMessage
  }
  else {
    if (typeof targetOrMaxDist === 'number')
      maxDist = targetOrMaxDist
    if (typeof maxDistOrMessage === 'string')
      message = maxDistOrMessage
  }

  let distance = null
  if (target) {
    const endPos = globalThis.lastAction?.result?.endPos
    if (!endPos || typeof endPos.x !== 'number' || typeof endPos.y !== 'number' || typeof endPos.z !== 'number') {
      throw new Error('Expectation failed: expectNear(target) requires last action result with endPos telemetry')
    }

    const dx = endPos.x - target.x
    const dy = endPos.y - target.y
    const dz = endPos.z - target.z
    distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
  }
  else if (typeof globalThis.lastAction?.result?.distanceToTargetAfter === 'number') {
    distance = globalThis.lastAction.result.distanceToTargetAfter
  }

  if (distance === null) {
    throw new Error('Expectation failed: expectNear() requires target argument or last action distanceToTargetAfter telemetry')
  }

  if (distance <= maxDist)
    return true

View on GitHub (pinned to 27111382b4)

Solutions

  1. Call a movement action that reports endPos before expectNear(target).
  2. Verify via log() that globalThis.lastAction.result has the expected endPos shape.
  3. If you only need proximity to a known target, prefer the no-target overload that uses distanceToTargetAfter telemetry if available.
  4. Ensure the movement action's result schema includes numeric endPos {x,y,z}.

Example fix

// before
//   await chat({ message: 'hi' })
//   expectNear({ x: 10, y: 64, z: -5 })  // throws: no endPos from chat
//
// after
//   await use('moveTo', { x: 10, y: 64, z: -5 })
//   expectNear({ x: 10, y: 64, z: -5 }, 2)
Defensive patterns

Strategy: validation

Validate before calling

// Before expectNear(target), confirm endPos telemetry exists:
// const end = globalThis.lastAction?.result?.endPos
// if (end && typeof end.x === 'number' && typeof end.y === 'number' && typeof end.z === 'number') {
//   expectNear(target, maxDist)
// } else {
//   log('expectNear skipped: no endPos telemetry')
// }

Type guard

function hasEndPos(r: unknown): r is { endPos: { x: number, y: number, z: number } } {
  const e = (r as any)?.endPos
  return !!e && typeof e.x === 'number' && typeof e.y === 'number' && typeof e.z === 'number'
}

Prevention

When it happens

Trigger: Calling expectNear({x,y,z}) after an action whose result does not include endPos (e.g. after chat, craft, or a movement action that did not populate endPos); calling expectNear with a target before any action has run this turn (lastAction is null); the action result schema dropped the endPos field after a refactor.

Common situations: First assertion in a script with no preceding movement action; using expectNear against a non-movement action; telemetry field renamed from endPos to something else; the action returns a partial result on early failure without endPos.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/3fc91bb101f8e35a. Report an issue: GitHub.