{"record":{"id":"5d71dcedbf91a27b","repo":"ruvnet/RuView","slug":"brain-corpus-exceeds-1000-records-5d71dc","errorCode":null,"errorMessage":"brain corpus exceeds 1000 records","messagePattern":"brain corpus exceeds 1000 records","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/ruview/src/brain.js","lineNumber":54,"sourceCode":"  if (canonical && record.reviewed !== true) errors.push('canonical records must be reviewed');\n  const combined = `${record.title || ''}\\n${record.content || ''}`;\n  if (SECRET.test(combined)) errors.push('record appears to contain a secret');\n  if (INJECTION.test(combined)) errors.push('record contains instruction-like prompt injection');\n  return errors;\n}\n\nexport function loadBrain(path = CORPUS_PATH) {\n  const raw = readFileSync(path, 'utf8').replace(/\\r\\n/g, '\\n');\n  if (Buffer.byteLength(raw) > 1_048_576) throw new Error('brain corpus exceeds 1 MiB');\n  const records = raw.split('\\n').filter(Boolean).map((line, index) => {\n    if (Buffer.byteLength(line) > 16_384) throw new Error(`brain line ${index + 1}: exceeds 16 KiB`);\n    let record;\n    try { record = JSON.parse(line); } catch (error) { throw new Error(`brain line ${index + 1}: ${error.message}`); }\n    const errors = validateBrainRecord(record, { canonical: true });\n    if (errors.length) throw new Error(`brain line ${index + 1}: ${errors.join('; ')}`);\n    return Object.freeze(record);\n  });\n  if (records.length > 1000) throw new Error('brain corpus exceeds 1000 records');\n  const ids = new Set();\n  for (const record of records) {\n    if (ids.has(record.id)) throw new Error(`duplicate brain id: ${record.id}`);\n    ids.add(record.id);\n  }\n  return { records, digest: sha256(raw), bytes: Buffer.byteLength(raw) };\n}\n\nfunction terms(value) {\n  return new Set(String(value).toLowerCase().match(/[a-z0-9][a-z0-9_-]{1,}/g) || []);\n}\n\nexport function searchBrain(query, { limit = 8, path = CORPUS_PATH } = {}) {\n  const wanted = terms(query);\n  if (!wanted.size) return [];\n  const { records, digest } = loadBrain(path);\n  return records.map((record) => {\n    const title = terms(record.title);","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/ruview/src/brain.js#L36-L72","documentation":"The canonical brain corpus is limited to 1000 records so the reviewed knowledge base stays reviewable. loadBrain counts parsed records and throws when the count exceeds 1000. Short records can hit this limit even when the 1 MiB byte cap has not been reached yet.","triggerScenarios":"core.jsonl accumulating more than 1000 valid JSONL records, e.g. bulk imports or long-term automated harvesting of lessons.","commonSituations":"Record-per-lesson automation, importing issue digests, long-lived repositories with many contributors.","solutions":["Retire or consolidate stale records to stay under 1000","Merge near-duplicate lessons into single records with shared tags","Monitor the count: wc -l harness/ruview/brain/corpus/core.jsonl"],"exampleFix":"# before: 1043 records, loadBrain() throws\n\n# after: consolidate duplicates and retire stale records\n$ wc -l harness/ruview/brain/corpus/core.jsonl\n998 harness/ruview/brain/corpus/core.jsonl","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction recordCount(path) {\n  return readFileSync(path, 'utf8').split('\\n').filter((l) => l.trim()).length;\n}\n// use: if (recordCount(path) > 1000) failFast('prune the corpus before loading');","typeGuard":null,"tryCatchPattern":"try {\n  const brain = loadBrain(path);\n} catch (error) {\n  if (error.message.includes('exceeds 1000 records')) {\n    console.error('corpus record cap reached — retire or consolidate records');\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Track wc -l on core.jsonl in CI to see the 1000-record ceiling approaching","Consolidate overlapping lessons into one record with richer tags instead of many narrow ones","Archive removed lessons outside the canonical corpus rather than commenting them out"],"tags":["validation","data-limits","brain","ruview"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}