Skip to content

fix(brain_id): mismatch between middleware and route args#38

Merged
ChrisCoder9000 merged 1 commit intomainfrom
development
Mar 14, 2026
Merged

fix(brain_id): mismatch between middleware and route args#38
ChrisCoder9000 merged 1 commit intomainfrom
development

Conversation

@ChrisCoder9000
Copy link
Copy Markdown
Contributor

@ChrisCoder9000 ChrisCoder9000 commented Mar 14, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved error responses by including the invalid brain ID value in error messages for better debugging.
  • Refactor

    • Enhanced internal API infrastructure with improved brain/tenant context handling across endpoints for better consistency and maintainability.

@ChrisCoder9000 ChrisCoder9000 merged commit 68e8abd into main Mar 14, 2026
1 check was pending
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c07ff5d-02a9-4279-af81-151751e3dea2

📥 Commits

Reviewing files that changed from the base of the PR and between 8edf6c1 and 1b8c5ca.

📒 Files selected for processing (7)
  • src/services/api/dependencies.py
  • src/services/api/middlewares/brains.py
  • src/services/api/routes/ingest.py
  • src/services/api/routes/meta.py
  • src/services/api/routes/model.py
  • src/services/api/routes/retrieve.py
  • src/services/api/routes/tasks.py

📝 Walkthrough

Walkthrough

A new dependency injection mechanism for brain_id parameter extraction has been introduced across the API. A new dependencies.py module defines a get_brain_id() function that retrieves the brain identifier from request state. This pattern replaces default parameter values and form-based extraction throughout multiple route handlers. A middleware update adds explicit brain_id value to error responses.

Changes

Cohort / File(s) Summary
Dependency Infrastructure
src/services/api/dependencies.py
New module introducing get_brain_id() function that extracts brain identifier from request.state.brain_id.
Middleware Enhancement
src/services/api/middlewares/brains.py
Updated 400 BAD REQUEST error response to include the brain_id value in the error payload via new "value" field.
Route Handlers - Dependency Injection
src/services/api/routes/ingest.py, src/services/api/routes/meta.py, src/services/api/routes/model.py, src/services/api/routes/retrieve.py, src/services/api/routes/tasks.py
Applied brain_id: str = Depends(get_brain_id) pattern to multiple endpoint signatures, replacing hardcoded defaults ("default") and form-based extraction. Import statements updated to include Depends and get_brain_id. For ingest and model routes, request.brain_id = brain_id assignments added before controller delegation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's delight in tidy dependency flow,
Where brain_id hops through channels, high and low,
No more defaults scattered, no forms in the way,
Injected with grace, the elegant play!
From state to the handler, the pattern rings true,
Organization pure—a rabbit's purr through and through! 🎉

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch development
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (4.0.5)
src/services/api/dependencies.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "dependencies",
"obj": "",
"line": 1,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/services/api/dependencies.py",
"symbol": "missing-module-docstring",
"message": "Missing module docstring",
"message-id": "C0114"
},
{
"type": "error",
"module": "dependencies",
"obj": "",
"line": 1,
"column": 0,
"endLine": 1,
"endColumn": 27,
"path": "src/services/api/dependencies.py",
"symbol": "import-error",
"message": "Unable to import 'fastapi'",
"message-id": "E0401"
},
{
"type": "convention",
"module": "dependencies",
"obj": "get_brain_id",
"line": 4,
"column": 0,
"endLine": 4,
"endColumn": 16,
"path": "src/services/api/dependencies.py",
"symbol": "missing-function-docstring",
"message": "Missing function or method docstring",
"message-id": "C0116"
}
]

src/services/api/routes/meta.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "routes.meta",
"obj": "",
"line": 65,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/services/api/routes/meta.py",
"symbol": "missing-final-newline",
"message": "Final newline missing",
"message-id": "C0304"
},
{
"type": "error",
"module": "routes.meta",
"obj": "",
"line": 11,
"column": 0,
"endLine": 11,
"endColumn": 38,
"path": "src/services/api/routes/meta.py",
"symbol": "import-error",
"message": "Unable to import 'fastapi'",
"message-id": "E0401"
},
{
"type": "error",
"module": "routes.meta",
"obj": "",
"line": 13,
"column": 0,
"endLine": 13,
"endColumn": 54,
"path": "src/services/api/routes/meta.py",
"symbol": "import-error",
"message": "Unable to import 'src.services.api.dependencies'",
"message-id": "E0401"
},
{
"type": "error",
"module": "routes.meta",
"obj": "",
"line": 14,
"column": 0,
"endLine": 18,
"endColumn": 1,
"path": "src/services/api/routes/meta.py",
"symbol": "import-error",
"message": "Unable to import 'src.services.api.controllers.meta'",
"message-id": "E0401"
}
]

src/services/api/routes/model.py

************* Module .pylintrc
.pylintrc:1:0: F0011: error while parsing the configuration: Source contains parsing errors: '.pylintrc'
[line 18]: 'C0103' (config-parse-error)
[
{
"type": "convention",
"module": "routes.model",
"obj": "",
"line": 43,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/services/api/routes/model.py",
"symbol": "trailing-whitespace",
"message": "Trailing whitespace",
"message-id": "C0303"
},
{
"type": "convention",
"module": "routes.model",
"obj": "",
"line": 65,
"column": 0,
"endLine": null,
"endColumn": null,
"path": "src/services/api/routes/model.py",
"symbol": "line-too-long",
"message": "Line too long (105/100)",
"message-id": "C0301"
},
{
"type": "convention",
"module": "routes.model",
"obj": "",
"line": 108,

... [truncated 1246 characters] ...

api.dependencies'",
"message-id": "E0401"
},
{
"type": "error",
"module": "routes.model",
"obj": "",
"line": 14,
"column": 0,
"endLine": 19,
"endColumn": 1,
"path": "src/services/api/routes/model.py",
"symbol": "import-error",
"message": "Unable to import 'src.services.api.constants.requests'",
"message-id": "E0401"
},
{
"type": "error",
"module": "routes.model",
"obj": "",
"line": 20,
"column": 0,
"endLine": 25,
"endColumn": 1,
"path": "src/services/api/routes/model.py",
"symbol": "import-error",
"message": "Unable to import 'src.services.api.controllers.model'",
"message-id": "E0401"
}
]

  • 4 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant