{"record":{"id":"5b354a915ede2e5e","repo":"can1357/oh-my-pi","slug":"unknown-recall-tier-json-stringify-tier-valid","errorCode":null,"errorMessage":"unknown recall tier ${JSON.stringify(tier)}; valid tiers: ${JSON.stringify(RECALL_TIERS)}","messagePattern":"unknown recall tier (.+?); valid tiers: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/recall-diagnostics.ts","lineNumber":63,"sourceCode":"\tprivate tierStats: Record<RecallTier, TierStats>;\n\tprivate totalCalls: number;\n\tprivate callsUsingWmFallback: number;\n\tprivate callsUsingEmFallback: number;\n\tprivate callsTrulyEmpty: number;\n\tprivate createdAt: string;\n\n\tconstructor() {\n\t\tthis.tierStats = newTierStats();\n\t\tthis.totalCalls = 0;\n\t\tthis.callsUsingWmFallback = 0;\n\t\tthis.callsUsingEmFallback = 0;\n\t\tthis.callsTrulyEmpty = 0;\n\t\tthis.createdAt = new Date().toISOString();\n\t}\n\n\tprivate static validateTier(tier: string): asserts tier is RecallTier {\n\t\tif (!isRecallTier(tier)) {\n\t\t\tthrow new Error(`unknown recall tier ${JSON.stringify(tier)}; valid tiers: ${JSON.stringify(RECALL_TIERS)}`);\n\t\t}\n\t}\n\n\trecordTierHits(tier: RecallTier | string, hitCount: number): void {\n\t\tRecallDiagnostics.validateTier(tier);\n\t\tif (hitCount < 0) throw new Error(`hit_count must be >= 0, got ${hitCount}`);\n\t\tconst stats = this.tierStats[tier];\n\t\tif (hitCount > 0) stats.callsWithHits++;\n\t\tstats.totalHits += hitCount;\n\t}\n\trecordFallbackUsed(options: { readonly wm?: boolean; readonly em?: boolean } = {}): void {\n\t\tif (options.wm === true) this.callsUsingWmFallback++;\n\t\tif (options.em === true) this.callsUsingEmFallback++;\n\t}\n\trecordCall(options: { readonly trulyEmpty?: boolean; readonly truly_empty?: boolean } = {}): void {\n\t\tthis.totalCalls++;\n\t\tif (options.trulyEmpty === true || options.truly_empty === true) this.callsTrulyEmpty++;\n\t}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/recall-diagnostics.ts#L45-L81","documentation":"RecallDiagnostics.recordTierHits accepts tier as a loose string but validates it against the known RECALL_TIERS set before recording; an unrecognized string throws a plain Error listing all valid tiers. This keeps tier statistics buckets consistent.","triggerScenarios":"Calling recordTierHits(\"vector\", 3) or any string outside RECALL_TIERS; passing a tier name from another system's taxonomy; passing a raw DB value that has drifted from the enum.","commonSituations":"Typo in a tier constant; refactoring renamed a tier in one place but not in callers logging diagnostics; interop with external pipelines emitting different tier labels.","solutions":["Use the exported RecallTier constants instead of raw strings","Inspect the error message's list of valid tiers and correct the tier value","Validate/normalize the tier at the boundary (e.g. isRecallTier) before recording"],"exampleFix":"// before\ndiag.recordTierHits(\"vector\", 2); // unknown tier\n// after\nimport { isRecallTier } from \"...\";\nconst tier = \"semantic\"; // one of RECALL_TIERS\nif (isRecallTier(tier)) diag.recordTierHits(tier, 2);","handlingStrategy":"type-guard","validationCode":"import { isRecallTier, RECALL_TIERS } from \"...\";\nif (isRecallTier(tier)) diag.recordTierHits(tier, hits);","typeGuard":"function isRecallTier(value: string): value is RecallTier {\n  return (RECALL_TIERS as readonly string[]).includes(value);\n}","tryCatchPattern":"try {\n  diag.recordTierHits(tier, hits);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"unknown recall tier\")) {\n    logger.warn(\"dropping diagnostics for unknown tier\", { tier });\n    return;\n  }\n  throw err;\n}","preventionTips":["Use RecallTier constants instead of raw strings","Validate tiers at system boundaries with isRecallTier","Keep tier naming in sync when refactoring across systems"],"tags":["validation","enum","diagnostics"],"backgroundTag":"invalid-enum-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}