{"record":{"id":"c03239bea847afd7","repo":"ruvnet/RuView","slug":"brain-corpus-exceeds-1-mib-c03239","errorCode":null,"errorMessage":"brain corpus exceeds 1 MiB","messagePattern":"brain corpus exceeds 1 MiB","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/ruview/src/brain.js","lineNumber":45,"sourceCode":"  if (!EVIDENCE.has(record.evidence)) errors.push(`unsupported evidence: ${record.evidence}`);\n  if (!record.source || typeof record.source.path !== 'string' || !Number.isInteger(record.source.line) || record.source.line < 1) {\n    errors.push('source.path and positive source.line are required');\n  } else if (isAbsolute(record.source.path) || record.source.path.split(/[\\\\/]/).includes('..') || /^[A-Za-z]:/.test(record.source.path)) {\n    errors.push('source.path must be repository-relative without traversal');\n  }\n  if (!Array.isArray(record.tags) || record.tags.some((tag) => typeof tag !== 'string')) errors.push('tags must be strings');\n  if ((record.content || '').length > 8192) errors.push('content exceeds 8192 characters');\n  if ((record.title || '').length > 200) errors.push('title exceeds 200 characters');\n  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) {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/ruview/src/brain.js#L27-L63","documentation":"loadBrain enforces a hard 1 MiB (1_048_576 byte) cap on the canonical brain corpus (core.jsonl), measured after CRLF-to-LF normalization, keeping the committed JSONL small enough to review and load. A larger file throws immediately, before any line is parsed.","triggerScenarios":"harness/ruview/brain/corpus/core.jsonl grows past 1 MiB after merging records — the check is on the whole file, so one large merge or long-term accumulation trips it.","commonSituations":"Bulk-importing records through PRs, appending verbose content, pointing loadBrain at an aggregated corpus during local experiments.","solutions":["Prune stale or superseded records from core.jsonl","Shorten record content (each record allows at most 8192 characters; keep far below)","Check size before committing: wc -c harness/ruview/brain/corpus/core.jsonl"],"exampleFix":"# before: corpus is 1.1 MiB and loadBrain() throws\n\n# after: prune superseded records until below the cap\n$ wc -c harness/ruview/brain/corpus/core.jsonl\n1040000 harness/ruview/brain/corpus/core.jsonl","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs';\nfunction corpusWithinBudget(path) {\n  const bytes = statSync(path).size;\n  return { ok: bytes <= 1_048_576, bytes };\n}","typeGuard":null,"tryCatchPattern":"try {\n  const brain = loadBrain(path);\n} catch (error) {\n  if (error.message.startsWith('brain corpus exceeds')) {\n    console.error(`corpus too large: ${error.message} — prune superseded records`);\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Run wc -c on core.jsonl in CI so growth is caught before loadBrain runs","Prefer fewer, denser records; link to sources instead of pasting long excerpts","Retire superseded lessons in the same PR that adds new ones"],"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"}