mastra-ai/mastra · error · Error

Noise example queries require a trace signal and snapshot

Error message

Noise example queries require a trace signal and snapshot

What it means

useNoiseExamples builds a React Query for noise examples tied to a trace signal and theme snapshot. Its queryFn re-validates inputs with this error even though the query has enabled: signalName !== undefined && snapshotId !== undefined — the throw is a defensive invariant that should never fire in normal operation, protecting against the query being force-run (e.g., refetch) with undefined inputs.

Source

Thrown at packages/playground-ui/src/ee/signals/hooks/use-noise-examples.ts:33

  filterThemes: ThemeSelection[] = [],
) {
  const { cacheScope, request } = useTraceIntelligence();
  const serializedFilters = serializeThemeFilters(filterThemes);
  return useQuery({
    queryKey: [
      'entity-learning',
      cacheScope,
      entityType,
      entityId,
      'noise-examples',
      signalName,
      snapshotId,
      limit,
      offset,
      serializedFilters,
    ],
    queryFn: () => {
      if (!signalName || !snapshotId) throw new Error('Noise example queries require a trace signal and snapshot');
      return fetchNoiseExamples(request, entityId, entityType, signalName, snapshotId, limit, offset, filterThemes);
    },
    enabled: signalName !== undefined && snapshotId !== undefined,
  });
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure both signalName and snapshotId are defined before triggering the query or any manual refetch.
  2. Keep the query disabled (enabled: signalName !== undefined && snapshotId !== undefined) and avoid overriding it.
  3. Re-select a signal and snapshot after entity/filter changes before refetching.
  4. If refetching imperatively, guard the call: only refetch when both parameters are present.

Example fix

// before
queryClient.refetchQueries({ queryKey: ['noise-examples'] }); // can run with undefined inputs

// after
if (signalName && snapshotId) {
  queryClient.refetchQueries({ queryKey: ['noise-examples', cacheScope, entityType, entityId, signalName, snapshotId] });
}
Defensive patterns

Strategy: validation

Validate before calling

const canFetch = signalName !== undefined && snapshotId !== undefined;
if (canFetch) {
  queryClient.refetchQueries({ queryKey: ['noise-examples', cacheScope, entityType, entityId, signalName, snapshotId] });
}

Type guard

const hasNoiseInputs = (
  s: string | undefined,
  snap: string | undefined
): s is string => s !== undefined && snap !== undefined;

Try / catch

try {
  const data = await queryClient.fetchQuery({ queryKey, queryFn });
} catch (e) {
  if (e instanceof Error && e.message.includes('trace signal and snapshot')) {
    // inputs missing: re-select signal/snapshot instead of retrying
  }
}

Prevention

When it happens

Trigger: Manually calling queryClient refetch/fetchQuery for the 'noise examples' key while signalName or snapshotId is undefined; calling the hook with enabled overridden; a race where signal selection is cleared while a refetch is in flight.

Common situations: Imperative refetch after clearing the selected signal; combining signal filters with snapshot resets; tests invoking the query function directly without fixtures.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/05d816596ac621bb. Report an issue: GitHub.