agalwood/Motrix · error · RangeError

accuracy is not legal

Error message

accuracy is not legal

What it means

`input.accuracy` must be one of `TaskHistoryAccuracy.Exact` (`'exact'`) or `TaskHistoryAccuracy.Recovered` (`'recovered'`). It distinguishes events recorded live from those reconstructed after a coverage gap. Throws this `RangeError` on any other value.

Source

Thrown at src/core/inspector-activity/validators.ts:174

  }
}

export function validateHistoryEventInput(input: TaskHistoryEventInput): void {
  assertTaskId(input.taskId)
  assertPositiveSafeInteger(input.eventOrdinal, 'eventOrdinal')
  assertBoundedText(input.eventKey, 'eventKey', MAX_EVENT_KEY_LENGTH)
  assertBoundedText(
    input.runtimeGeneration,
    'runtimeGeneration',
    MAX_EVENT_KEY_LENGTH
  )
  assertPositiveSafeInteger(input.occurredAt, 'occurredAt')
  assertNonNegativeSafeInteger(input.occurredMonotonicMs, 'occurredMonotonicMs')
  if (!EVENT_KIND_VALUES.has(input.kind)) {
    throw new RangeError('kind is not a legal history event kind')
  }
  if (!ACCURACY_VALUES.has(input.accuracy)) {
    throw new RangeError('accuracy is not legal')
  }
  if (!DELIVERY_VALUES.has(input.delivery)) {
    throw new RangeError('delivery is not legal')
  }
  assertStatus(input.fromStatus, 'fromStatus')
  assertStatus(input.toStatus, 'toStatus')
  if (input.toStatus === null) {
    throw new RangeError('toStatus is required')
  }
  assertBoundedText(input.errorCode, 'errorCode', MAX_ERROR_CODE_LENGTH)
  assertBoundedText(
    input.errorMessage,
    'errorMessage',
    MAX_ERROR_MESSAGE_LENGTH
  )
  assertBoundedText(
    input.errorDetailKey,
    'errorDetailKey',

View on GitHub (pinned to 1a708ee577)

Solutions

  1. Default to `TaskHistoryAccuracy.Exact` at the producer for live events, `Recovered` for reconstructed ones.
  2. Reference the enum, not the string.
  3. If unsure, treat the event as recovered and let the consumer downgrade trust.

Example fix

// before
input.accuracy = recordedLive ? 'live' : 'guess'
// after
input.accuracy = recordedLive ? TaskHistoryAccuracy.Exact : TaskHistoryAccuracy.Recovered
Defensive patterns

Strategy: type-guard

Validate before calling

import { TaskHistoryAccuracy } from '@shared/types/task-inspector-activity'
function coerceAccuracy(v: unknown): TaskHistoryAccuracy {
  return v === TaskHistoryAccuracy.Recovered
    ? TaskHistoryAccuracy.Recovered
    : TaskHistoryAccuracy.Exact
}

Type guard

import { TaskHistoryAccuracy } from '@shared/types/task-inspector-activity'
const ACC = new Set(Object.values(TaskHistoryAccuracy))
function isAccuracy(v: unknown): v is TaskHistoryAccuracy {
  return typeof v === 'string' && ACC.has(v)
}

Prevention

When it happens

Trigger: An event submitted with `accuracy` set to `undefined`, an empty string, or a foreign value (`'approximate'`). Common when a producer omits the field and a defaulting layer fills it incorrectly, or when serializing from a schema that pre-dates the accuracy flag.

Common situations: New producers forgetting to set accuracy; replaying events from a schema predating the accuracy flag; tests that leave it unset.

Related errors


AI-assisted analysis of agalwood/Motrix@1a708ee577 (2026-08-12). Data as JSON: /api/errors/1c921d796485f94f. Report an issue: GitHub.