Skip to content

Conversation

@sharma-sugurthi
Copy link

@sharma-sugurthi sharma-sugurthi commented Dec 14, 2025

Description

This PR addresses the following issues:

  • Adds missing chromadb dependency to requirements.txt
  • Implements a /health endpoint to check server status
  • Updates documentation with new endpoint information

Changes

  • Added chromadb to Backend/requirements.txt
  • Added /health endpoint to Backend/app.py
  • Updated Setup.md with new endpoint documentation

Testing

  • Verified server starts with SKIP_AGENT_INIT=1
  • Confirmed /health endpoint returns expected response
  • Verified chromadb dependency installs correctly

Fixes #100

Summary by CodeRabbit

  • New Features

    • Added a health-check endpoint that returns service status for monitoring.
  • Documentation

    • Expanded setup and Quick Start instructions for frontend and backend.
    • Added prerequisites and step-by-step backend installation and run workflow (venv, Python 3.12+).
    • Documented local server details and how to verify health, and noted use of offline vector-search tooling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 14, 2025

📝 Walkthrough

Walkthrough

Added a new /health HTTP endpoint to the Flask backend that returns JSON with status and agent_initialized; changed app run to debug=False; expanded backend setup and quick-start documentation with step-by-step venv and run instructions pointing to http://127.0.0.1:5000.

Changes

Cohort / File(s) Summary
Health Check & App Entry
Backend/app.py
Added health() route at /health returning JSON { "status": "ok", "agent_initialized": <bool> }; changed app run to debug=False.
Backend Setup docs
Setup.md
Rewrote backend setup: prerequisites (Python 3.12+, venv), venv creation/activation, pip install -r requirements.txt, explicit run workflow and server URL, and guidance to verify /health; mentions offline ChromaDB usage.
Project Quick Start
README.md
Added Quick Start section linking to Setup.md and describing frontend + backend setup steps (venv, install, run).

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

"I hopped in code with whiskers bright,
A tiny endpoint sprung to light.
/health says 'ok' with a jaunty cheer,
Agent asleep or standing near —
Rabbit hops on, the server's right! 🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding chromadb dependency and implementing a health endpoint, both of which are core objectives from issue #100.
Linked Issues check ✅ Passed The PR addresses the primary coding objectives from issue #100: adding chromadb to requirements.txt, implementing a /health endpoint, and updating documentation for the new endpoint.
Out of Scope Changes check ✅ Passed All changes (chromadb dependency, health endpoint, documentation updates, and debug mode change) are directly related to issue #100's objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
Backend/app.py (2)

39-42: Critical: Missing SKIP_AGENT_INIT implementation - agent initialization still blocks startup.

The PR objectives from issue #100 require adding a SKIP_AGENT_INIT environment variable to make agent initialization non-blocking, allowing Flask to start promptly for API development. However, the agent is unconditionally initialized at module level, which will still cause the blocking behavior described in the linked issue.

Wrap agent initialization in a conditional check:

 # Initialize agent with database path
 db_path = os.path.join(os.path.dirname(__file__), "db", "database.db")
 first_time_setup() # This needs to be called before initializing the agent
 
-agent = get_agent(db_path)
+# Skip agent initialization in dev mode if requested
+agent = None
+if os.environ.get('SKIP_AGENT_INIT') != '1':
+    agent = get_agent(db_path)
+else:
+    print("⚠️  Agent initialization skipped (SKIP_AGENT_INIT=1)")

44-62: Add defensive checks for agent-dependent endpoints.

Once SKIP_AGENT_INIT is implemented, agent-dependent endpoints like /agent will fail with AttributeError when the agent is None. Add guard clauses to return appropriate errors.

 @app.route("/agent", methods=["POST"])
 def run_agent():
+    if agent is None:
+        return jsonify({"error": "Agent not initialized. Start without SKIP_AGENT_INIT=1"}), 503
+    
     if not request.is_json:
         return jsonify({"error": "Invalid JSON format"}), 400

Apply similar checks to all agent-dependent endpoints: /agent/cache/status (line 66), /agent/context (line 90), /agent/tasks/recommendations (line 116), /agent/cache/stats (line 147), and /agent/cache/cleanup (line 170).

Setup.md (1)

9-9: Contradictory Python version requirements for Flask backend.

Line 9 specifies Python 3.8+, but line 97 specifies Python 3.12+ for the backend. Additionally, line 194 reverts to 3.8+. Clarify the actual minimum Python version required for the Flask backend and update all references consistently.

🧹 Nitpick comments (1)
Setup.md (1)

102-102: Add language specifiers to code blocks.

Static analysis identified code blocks without language specifiers, which reduces syntax highlighting and readability.

Apply language specifiers to the code blocks:

-   ```
+   ```bash
    cd Backend
    ```
-   ```
+   ```bash
    python -m venv .venv
    source .venv/bin/activate
    ```
-   ```
+   ```bash
    pip install -r requirements.txt
    ```
-```
+```bash
 python app.py


Also applies to: 106-106, 111-111, 117-117

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: CodeRabbit UI

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between a76d240fae2788a78479266ee26390d989f7bdfd and fac61d98aefad0a7dee95779e8719d7c76d29705.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `Backend/app.py` (1 hunks)
* `Setup.md` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

<details>
<summary>Setup.md</summary>

102-102: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

106-106: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

111-111: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

117-117: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

120-120: Bare URL used

(MD034, no-bare-urls)

</details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Backend/app.py Outdated
Comment on lines 31 to 36
@app.route('/health')
def health():
return jsonify({
'status': 'ok',
'agent_initialized': True # Since agent is always initialized in this version
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Health endpoint doesn't reflect actual agent initialization status.

The PR objectives require the health endpoint to indicate whether the agent is initialized, supporting a response like {"agent_initialized": false, "status": "ok"} when running with SKIP_AGENT_INIT=1. However, this endpoint hardcodes agent_initialized: True, which will be incorrect if the SKIP_AGENT_INIT feature is implemented.

The endpoint should check whether the agent was actually initialized:

+# Global agent variable
+agent = None
+
 @app.route('/health')
 def health():
     return jsonify({
         'status': 'ok',
-        'agent_initialized': True  # Since agent is always initialized in this version
+        'agent_initialized': agent is not None
     })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@app.route('/health')
def health():
return jsonify({
'status': 'ok',
'agent_initialized': True # Since agent is always initialized in this version
})
# Global agent variable
agent = None
@app.route('/health')
def health():
return jsonify({
'status': 'ok',
'agent_initialized': agent is not None
})
🤖 Prompt for AI Agents
In Backend/app.py around lines 31-36, the health endpoint currently hardcodes
"agent_initialized: True" which must instead reflect runtime state; change the
route to read a module-level boolean (e.g., AGENT_INITIALIZED) that your startup
code sets when the agent is initialized and fall back to checking
os.environ.get('SKIP_AGENT_INIT') == '1' (negated) if the flag is missing;
return that boolean in the JSON response and ensure the variable is properly
declared/updated during app initialization so the endpoint always reports the
real agent initialization status.

Comment on lines 93 to 152
## Backend Setup (Offline Flask API)
BabyNest includes an offline backend using Flask.

### 1. Install Python Dependencies
sh
pip install flask flask-cors chromadb


### 2. Run the Backend Locally
sh
cd Backend
BabyNest includes an offline backend using Flask with ChromaDB for vector search.

### Prerequisites
- Python 3.12+
- Virtual environment (venv)

### Installation
1. Navigate to the Backend directory:
```
cd Backend
```
2. Create and activate a virtual environment:
```
python -m venv .venv
source .venv/bin/activate
```
3. Install dependencies:
```
pip install -r requirements.txt
```

### Running the Backend
Start the server with:
```
python app.py


This will start the API locally.
```
The server will run on http://127.0.0.1:5000. Check /health for status.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Document the SKIP_AGENT_INIT environment variable for fast dev mode.

The PR objectives require documenting "Full Mode" vs. "Fast Dev Mode" with instructions for using SKIP_AGENT_INIT=1, but this section only shows basic startup. Developers need to know how to skip agent initialization during development.

Add documentation for the development mode:

 ### Running the Backend
-Start the server with:
+Start the server:
+
+**Full Mode (with Agent):**

python app.py

-The server will run on http://127.0.0.1:5000. Check /health for status.
+
+**Fast Dev Mode (skip Agent initialization):**
+```
+SKIP_AGENT_INIT=1 python app.py
+```
+
+The server will run on <http://127.0.0.1:5000>. Check `/health` for status.

This also resolves the bare URL warning by using angle brackets.

🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

102-102: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


106-106: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


111-111: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


117-117: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


120-120: Bare URL used

(MD034, no-bare-urls)

@bhavik-mangla
Copy link
Contributor

@sharma-sugurthi there are merge conflicts in setup.md

@sharma-sugurthi
Copy link
Author

@bhavik-mangla I will solve those.

@sharma-sugurthi
Copy link
Author

@bhavik-mangla please review it.

@bhavik-mangla
Copy link
Contributor

missing cd Backend in readme

- Add chromadb==0.5.23 to requirements.txt
- Implement /health endpoint in app.py
- Update Setup.md with backend setup instructions
- Add Quick Start in README.md with cd Backend

Fixes AOSSIE-Org#100
@sharma-sugurthi sharma-sugurthi force-pushed the fix/agent-initialization-issues branch from b6a3d82 to a5674a1 Compare December 28, 2025 16:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Backend/app.py (2)

31-35: Critical: Missing SKIP_AGENT_INIT implementation required by PR objectives.

The PR objectives and linked issue #100 explicitly require implementing SKIP_AGENT_INIT to skip heavy vector-store setup during development ("Fast Dev Mode"). However, the agent is always initialized unconditionally here—there's no check for the environment variable. This means:

  1. The server will still hang during startup due to blocking ChromaDB initialization
  2. The /health endpoint will always report agent_initialized: true
  3. The "Fast Dev Mode" workflow documented in the PR objectives cannot function
🔎 Implement conditional agent initialization
 # Initialize agent with database path
 db_path = os.path.join(os.path.dirname(__file__), "db", "database.db")
 first_time_setup() # This needs to be called before initializing the agent
 
-agent = get_agent(db_path)
+# Support skipping agent initialization for fast dev startup
+if os.environ.get('SKIP_AGENT_INIT') == '1':
+    agent = None
+    print("⚠️  Agent initialization skipped (SKIP_AGENT_INIT=1). /agent endpoints will not work.")
+else:
+    agent = get_agent(db_path)

37-56: Add guard for agent endpoints when agent is uninitialized.

When SKIP_AGENT_INIT=1 is used, agent will be None and calling agent.run() will raise AttributeError. Protect the endpoint to return a clear error.

🔎 Add agent initialization check
 @app.route("/agent", methods=["POST"])
 def run_agent():
+    if agent is None:
+        return jsonify({"error": "Agent not initialized. Start without SKIP_AGENT_INIT=1 to enable agent features."}), 503
+    
     if not request.is_json:
         return jsonify({"error": "Invalid JSON format"}), 400

Apply similar guards to other agent-dependent endpoints (lines 59-175).

♻️ Duplicate comments (1)
Setup.md (1)

143-151: Document SKIP_AGENT_INIT environment variable per PR objectives.

The PR objectives explicitly require documenting "Full Mode" vs. "Fast Dev Mode" with instructions for using SKIP_AGENT_INIT=1 to skip agent initialization. This allows developers to start the server quickly without waiting for ChromaDB setup. The current documentation only shows basic startup.

🔎 Add Fast Dev Mode documentation
 ### Running the Backend
-Start the server with:
+Start the server:
+
+**Full Mode (with Agent):**
+```bash
+python app.py
+```
+
+**Fast Dev Mode (skip Agent initialization):**
+```bash
+SKIP_AGENT_INIT=1 python app.py
+```
+
+The server will run on <http://127.0.0.1:5000>. Check `/health` for status.
+```

-```
-python app.py
-```
-
-This will start the API locally.
-
-The server will run on http://127.0.0.1:5000. Check `/health` for status.

This also addresses markdown linting warnings by adding language specifiers and using angle brackets for the bare URL.

🧹 Nitpick comments (2)
Setup.md (1)

130-141: Add language specifiers to code blocks.

Markdown linting tools recommend specifying languages for fenced code blocks to enable proper syntax highlighting.

🔎 Add language identifiers
 1. Navigate to the Backend directory:
-   ```
+   ```bash
    cd Backend
    ```
 2. Create and activate a virtual environment:
-   ```
+   ```bash
    python -m venv .venv
    source .venv/bin/activate
    ```
 3. Install dependencies:
-   ```
+   ```bash
    pip install -r requirements.txt
    ```

Based on static analysis hints.

README.md (1)

33-37: Optional: Vary sentence structure for readability.

Three consecutive sentences start with "For". Consider rewording line 37 to improve flow, e.g., "See Setup.md for detailed setup instructions."

Based on static analysis hints.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6a3d82 and a5674a1.

📒 Files selected for processing (4)
  • Backend/app.py
  • Backend/requirements.txt
  • README.md
  • Setup.md
🧰 Additional context used
🪛 LanguageTool
README.md

[style] ~36-~36: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...-r requirements.txt && python app.py`. For detailed setup instructions, see [Setup...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 markdownlint-cli2 (0.18.1)
Setup.md

130-130: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


134-134: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


139-139: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


145-145: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


151-151: Bare URL used

(MD034, no-bare-urls)

🪛 Ruff (0.14.10)
Backend/app.py

193-193: Possible binding to all interfaces

(S104)

🔇 Additional comments (3)
Backend/app.py (2)

185-190: Health endpoint implementation looks good.

The endpoint correctly checks agent is not None, which will properly report agent_initialized: false once the SKIP_AGENT_INIT feature (flagged above) is implemented.


193-193: Verify intended binding and debug setting.

Two changes here:

  1. debug=False — reasonable for production-like behavior, but confirm this is intentional (development typically uses debug=True for auto-reload and better error pages)
  2. host='0.0.0.0' — binds to all network interfaces. If this backend is only for local development, consider host='127.0.0.1' to reduce exposure.

Based on static analysis hints.

README.md (1)

31-37: Quick Start section is clear and helpful.

The backend setup command on line 35 includes cd Backend, addressing the concern raised by bhavik-mangla. The reference to Setup.md provides a good path for users who need more detailed instructions.

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.

Fix Backend Startup Issues: Agent Blocking, Missing Dependencies, and Setup Docs

2 participants