{"record":{"id":"66d365ae2d288be0","repo":"ruvnet/RuView","slug":"brain-corpus-exceeds-1000-records","errorCode":null,"errorMessage":"brain corpus exceeds 1000 records","messagePattern":"brain corpus exceeds 1000 records","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/homecore/src/brain.js","lineNumber":88,"sourceCode":"\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) {\n      throw new Error(`brain line ${index + 1}: exceeds 16 KiB`);\n    }\n    let record;\n    try {\n      record = JSON.parse(line);\n    } catch (error) {\n      throw new Error(`brain line ${index + 1}: ${error.message}`);\n    }\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":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/homecore/src/brain.js#L70-L106","documentation":"Raised at auth.py:258 when 'scheme, token = authorization.split()' raises ValueError, which happens whenever the header does not split into exactly two whitespace-separated parts: only a scheme with no token ('Bearer'), or extra segments ('Bearer  a b', 'Bearer token extra').","triggerScenarios":"Sending 'Authorization: Bearer' with no JWT; a token containing embedded whitespace (from copy-paste line wrapping); clients appending a trailing parameter like 'Bearer abc, charset=UTF-8'; multiple spaces are fine for split() but three tokens are not.","commonSituations":"Copy-pasting a JWT that has been wrapped across lines in a terminal/chat; hand-built header string concatenation bugs; scripts echoing tokens with appended newline handled elsewhere but trailing junk here; OAuth-style 'Bearer token, extra' syntax.","solutions":["Ensure the header is exactly two parts: one scheme word, one whitespace-free JWT: 'Authorization: Bearer <token>'","Re-copy the JWT without line breaks and verify it has no internal spaces/newlines","Strip the token value before building the header: f\"Bearer {token.strip()}\""],"exampleFix":"# before\nheaders = {\"Authorization\": f\"Bearer {token} extra\"}\n# after\nheaders = {\"Authorization\": f\"Bearer {token.strip()}\"}","handlingStrategy":"validation","validationCode":"def wellformed_header(token: str) -> str:\n    \"\"\"Build a header the split()-based parser accepts: exactly two parts.\"\"\"\n    token = token.strip()\n    assert token and \" \" not in token and \"\\n\" not in token, \"token contains whitespace\"\n    return f\"Bearer {token}\"","typeGuard":"def parses_as_bearer_pair(header_value: str) -> bool:\n    try:\n        scheme, token = header_value.split()\n    except ValueError:\n        return False\n    return bool(scheme) and bool(token)","tryCatchPattern":"try:\n    await middleware._authenticate_request(request)\nexcept AuthenticationError as e:\n    if str(e) == \"Invalid authorization header format\":\n        return json_response({\"error\": \"header must be 'Bearer <token>'\"}, 401)\n    raise","preventionTips":["Never hand-concatenate headers; use f\"Bearer {token.strip()}\"","Store JWTs without line wrapping (base64url only)","Unit-test the header builder against the two-part split"],"tags":["auth","http-headers","validation"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}