{"record":{"id":"bce2ca2c6cd3850f","repo":"mastra-ai/mastra","slug":"noise-queries-require-a-trace-signal-and-snapshot","errorCode":null,"errorMessage":"Noise queries require a trace signal and snapshot","messagePattern":"Noise queries require a trace signal and snapshot","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playground-ui/src/ee/signals/hooks/use-noise.ts","lineNumber":17,"sourceCode":"import { useQuery } from '@tanstack/react-query';\n\nimport { fetchNoise } from '../entity-learning-api';\nimport type { TraceSignalName } from '../types';\nimport { useTraceIntelligence } from '../use-trace-intelligence';\n\nexport function useNoise(\n  entityId: string,\n  entityType: string,\n  signalName: TraceSignalName | undefined,\n  snapshotId: string | undefined,\n) {\n  const { cacheScope, request } = useTraceIntelligence();\n  return useQuery({\n    queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId],\n    queryFn: () => {\n      if (!signalName || !snapshotId) throw new Error('Noise queries require a trace signal and snapshot');\n      return fetchNoise(request, entityId, entityType, signalName, snapshotId);\n    },\n    enabled: signalName !== undefined && snapshotId !== undefined,\n  });\n}\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/playground-ui/src/ee/signals/hooks/use-noise.ts#L1-L23","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nqueryClient.invalidateQueries({ queryKey: ['entity-learning'] }); // matches disabled/incomplete queries too\n\n// after\nif (signalName && snapshotId) {\n  queryClient.invalidateQueries({ queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId] });\n}","handlingStrategy":"validation","validationCode":"const ready = signalName !== undefined && snapshotId !== undefined;\nif (ready) {\n  queryClient.invalidateQueries({ queryKey: ['entity-learning', cacheScope, entityType, entityId, 'noise', signalName, snapshotId] });\n}","typeGuard":"function hasSignalAndSnapshot(\n  s: string | undefined,\n  snap: string | undefined\n): s is string {\n  return typeof s === 'string' && s.length > 0 && typeof snap === 'string' && snap.length > 0;\n}","tryCatchPattern":"try {\n  await queryClient.refetchQueries({ queryKey: noiseKey });\n} catch (e) {\n  if (e instanceof Error && /signal and snapshot/.test(e.message)) {\n    // missing inputs: restore selection before retrying\n  }\n}","preventionTips":["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."],"tags":["validation","react-query","signals","defensive-check"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}