{"record":{"id":"8f6cb516e2a69007","repo":"ruvnet/RuView","slug":"brain-line-index-1-errors-join","errorCode":null,"errorMessage":"brain line ${index + 1}: ${errors.join('; ')}","messagePattern":"brain line (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/homecore/src/brain.js","lineNumber":85,"sourceCode":"  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) {\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 [];","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/homecore/src/brain.js#L67-L103","documentation":"Raised at auth.py:256 when the Authorization header splits into exactly two parts but the scheme (case-insensitive) is not 'bearer'. The parser only accepts the Bearer scheme even though HTTPBearer from fastapi.security is imported for OpenAPI documentation.","triggerScenarios":"Sending 'Authorization: Basic dXNlcjpwYXNz' (HTTP Basic); 'Authorization: Token abc123' or 'ApiKey abc' (Django/GraphQL conventions); a proxy or SDK rewriting the scheme; 'Authorization: bearer' variants are fine but 'BearerToken x' is not.","commonSituations":"Porting a client from another framework whose auth scheme differs; Postman collection with scheme set to Basic/No Auth; API gateways injecting their own scheme; copy-pasting a curl from a service that uses Token instead of Bearer.","solutions":["Use exactly: Authorization: Bearer <jwt> (any case of 'bearer' works, the JWT must follow)","In Postman/clients, set the auth type to Bearer Token rather than Basic or API Key","Check any intermediary that may rewrite the scheme"],"exampleFix":"# before\nAuthorization: Basic dXNlcjpwYXNz\n# after\nAuthorization: Bearer eyJhbGciOiJIUzI1NiIs...","handlingStrategy":"validation","validationCode":"def valid_scheme(header_value: str) -> bool:\n    \"\"\"The middleware only accepts the Bearer scheme (case-insensitive).\"\"\"\n    parts = header_value.strip().split()\n    return len(parts) == 2 and parts[0].lower() == \"bearer\"","typeGuard":"def is_bearer(value: str) -> bool:\n    return isinstance(value, str) and value.strip().lower().startswith(\"bearer \")","tryCatchPattern":"try:\n    await middleware._authenticate_request(request)\nexcept AuthenticationError as e:\n    if str(e) == \"Invalid authentication scheme\":\n        return json_response({\"error\": \"use Authorization: Bearer <jwt>\"}, 401)\n    raise","preventionTips":["Standardize on Bearer in all clients from day one","Set Postman/collection auth type to Bearer Token","Assert the scheme in a client-side helper before sending"],"tags":["auth","http-headers"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}