mastra-ai/mastra · error · Error
Noise queries require a trace signal and snapshot
Error message
Noise queries require a trace signal and snapshot
What it means
useNoise fetches noise classifications for an entity/trace signal and snapshot. Its queryFn throws this error if signalName or snapshotId is undefined, even though the query is enabled only when both are defined — it is a defensive invariant guarding imperative refetches or misuse against calling fetchNoise with incomplete parameters.
Source
Thrown at packages/playground-ui/src/ee/signals/hooks/use-noise.ts:17
import { useQuery } from '@tanstack/react-query';
import { fetchNoise } from '../entity-learning-api';
import type { TraceSignalName } from '../types';
import { useTraceIntelligence } from '../use-trace-intelligence';
export function useNoise(
entityId: string,
entityType: string,
signalName: TraceSignalName | undefined,
snapshotId: string | undefined,
) {
const { cacheScope, request } = useTraceIntelligence();
return useQuery({
queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId],
queryFn: () => {
if (!signalName || !snapshotId) throw new Error('Noise queries require a trace signal and snapshot');
return fetchNoise(request, entityId, entityType, signalName, snapshotId);
},
enabled: signalName !== undefined && snapshotId !== undefined,
});
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Provide both a signalName and snapshotId before invoking or refetching the noise query.
- Do not override the hook's enabled gate; keep it dependent on both values being defined.
- Scope query invalidation to keys that include the concrete signalName and snapshotId.
- Guard manual refetch calls with a check that both parameters are non-null.
Example fix
// before
queryClient.invalidateQueries({ queryKey: ['entity-learning'] }); // matches disabled/incomplete queries too
// after
if (signalName && snapshotId) {
queryClient.invalidateQueries({ queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId] });
} Defensive patterns
Strategy: validation
Validate before calling
const ready = signalName !== undefined && snapshotId !== undefined;
if (ready) {
queryClient.invalidateQueries({ queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId] });
} Type guard
function hasSignalAndSnapshot(
s: string | undefined,
snap: string | undefined
): s is string {
return typeof s === 'string' && s.length > 0 && typeof snap === 'string' && snap.length > 0;
} Try / catch
try {
await queryClient.refetchQueries({ queryKey: noiseKey });
} catch (e) {
if (e instanceof Error && /signal and snapshot/.test(e.message)) {
// missing inputs: restore selection before retrying
}
} Prevention
- Keep the query disabled until both signalName and snapshotId exist.
- Scope invalidation keys to the exact signal/snapshot combination.
- Avoid clearing the selected signal while refetches are pending; cancel first.
- Verify test fixtures always supply both parameters when calling queryFn.
When it happens
Trigger: Force-refetching the 'entity-learning noise' query key while signalName or snapshotId is undefined; running the queryFn directly in tests without both values; clearing the selected signal while a background refetch triggers.
Common situations: Signal dropdown cleared by the user then a refetch fires; snapshot reset on theme change concurrent with refetch; incorrect queryKey invalidation matching queries that lack parameters.
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
- Noise example queries require a trace signal and snapshot
- A theme snapshot is required
- A numeric theme id is required
- A theme snapshot is required
- Factory project is required
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/bce2ca2c6cd3850f.
Report an issue: GitHub.