Skip to content

Improve keep-alive server (health endpoint & host binding) and update deployment docs#22

Merged
Rajrooter merged 1 commit into
mainfrom
codex/resolve-24/7-bot-deployment-issues
Feb 3, 2026
Merged

Improve keep-alive server (health endpoint & host binding) and update deployment docs#22
Rajrooter merged 1 commit into
mainfrom
codex/resolve-24/7-bot-deployment-issues

Conversation

@Rajrooter
Copy link
Copy Markdown
Owner

@Rajrooter Rajrooter commented Feb 3, 2026

User description

Motivation

  • Ensure platform hosts (e.g. Render) can reliably detect the bot process by exposing a stable health endpoint and binding predictably to the provided PORT and host.
  • Provide clear deployment guidance for always-on hosting (Render and Oracle Cloud) so users can run the bot 24×7 with auto-restart and update workflows.

Description

  • Initialize Flask with Flask(__name__) and add a /healthz endpoint that returns a simple status JSON for platform health checks.
  • Make the keep-alive server bind to PORT and a configurable WEB_HOST and disable the Flask reloader by calling app.run(host=host, port=port, use_reloader=False) so hosts detect the listening port reliably.
  • Update README.md with a Render Web Service section documenting start command, env vars, and the /healthz health-check path and clarifying that HTTPS is terminated by Render.
  • Add an Oracle Cloud Always Free (24×7) deployment guide including a sample systemd unit and update/restart instructions to keep the bot running continuously.

Testing

  • No automated tests were run for these documentation and configuration changes.

Codex Task


PR Type

Enhancement, Documentation


Description

  • Add /healthz health-check endpoint for platform detection

  • Make keep-alive server bind to configurable WEB_HOST and PORT

  • Disable Flask reloader for reliable port detection

  • Add Render Web Service deployment guide with health-check setup

  • Add Oracle Cloud Always Free 24×7 deployment guide with systemd


Diagram Walkthrough

flowchart LR
  A["Flask App"] -->|"Initialize with __name__"| B["Health Endpoint"]
  A -->|"Bind to WEB_HOST:PORT"| C["Keep-Alive Server"]
  C -->|"Disable reloader"| D["Reliable Detection"]
  D -->|"Render Web Service"| E["Deployment Guide 1"]
  D -->|"Oracle Cloud 24×7"| F["Deployment Guide 2"]
Loading

File Walkthrough

Relevant files
Enhancement
main.py
Add health endpoint and configurable host binding               

main.py

  • Initialize Flask with Flask(__name__) instead of empty string
  • Add /healthz endpoint returning {"status": "ok"} JSON
  • Make server bind to configurable WEB_HOST environment variable
  • Disable Flask reloader with use_reloader=False parameter
  • Update logging to show host and port binding information
+8/-3     
Documentation
README.md
Add Render and Oracle Cloud deployment documentation         

README.md

  • Add Render Web Service deployment section with start command and env
    vars
  • Document /healthz health-check path for Render platform detection
  • Clarify that Render terminates HTTPS at load balancer
  • Add comprehensive Oracle Cloud Always Free 24×7 deployment guide
  • Include systemd service file template for auto-restart functionality
  • Document bot update and restart procedures for always-on deployments
+116/-0 

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
discord-link-bot Ready Ready Preview, Comment Feb 3, 2026 1:56pm
discord-link-bot-wfz6 Ready Ready Preview, Comment Feb 3, 2026 1:56pm

@qodo-code-review
Copy link
Copy Markdown

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Unhandled env parsing: The new port = int(os.environ.get("PORT", "8080")) can raise
ValueError for an invalid PORT value and there is no fallback or explicit error
handling/logging for this edge case.

Referred Code
port = int(os.environ.get("PORT", "8080"))
host = os.environ.get("WEB_HOST", "0.0.0.0")
logger.info(f"Keep-alive server starting on {host}:{port}")
app.run(host=host, port=port, use_reloader=False)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Missing input validation: The new WEB_HOST and PORT environment inputs are used directly (including int() conversion
for PORT) without validation/sanitization, relying on deployment configuration
correctness.

Referred Code
port = int(os.environ.get("PORT", "8080"))
host = os.environ.get("WEB_HOST", "0.0.0.0")
logger.info(f"Keep-alive server starting on {host}:{port}")
app.run(host=host, port=port, use_reloader=False)

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@Rajrooter Rajrooter merged commit c6daa7c into main Feb 3, 2026
6 checks passed
@qodo-code-review
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Improve health check to verify bot

Enhance the /healthz endpoint to check the Discord bot's connection status
(bot.is_ready()) and return a 503 error if the bot is not ready, ensuring the
health check reflects the true application state.

main.py [919-921]

+from flask import jsonify
+
 @app.route('/healthz')
 def health_check():
-    return {"status": "ok"}
+    if bot and bot.is_ready():
+        return jsonify({"status": "ok"})
+    else:
+        return jsonify({"status": "unhealthy", "reason": "Bot is not connected or ready"}), 503
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: This is a high-impact suggestion that significantly improves the utility of the new health check feature by tying its status to the bot's actual readiness, making automated monitoring and restarts far more effective.

Medium
Catch and log server startup errors

Add a try...except block around the app.run call to catch and log any exceptions
that occur during server startup, preventing silent failures.

main.py [926-927]

 logger.info(f"Keep-alive server starting on {host}:{port}")
-app.run(host=host, port=port, use_reloader=False)
+try:
+    app.run(host=host, port=port, use_reloader=False)
+except Exception as e:
+    logger.error(f"Keep-alive server failed: {e}", exc_info=True)
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: This is a good suggestion for improving robustness by adding error handling around the web server startup, which helps in diagnosing deployment issues like port conflicts.

Low
General
Use a production-grade WSGI server

Replace the Flask development server (app.run) with a production-grade WSGI
server like waitress for improved stability and performance in production
environments.

main.py [923-927]

 def run():
     port = int(os.environ.get("PORT", "8080"))
     host = os.environ.get("WEB_HOST", "0.0.0.0")
+    # Use a production-grade WSGI server instead of Flask's development server
+    from waitress import serve
     logger.info(f"Keep-alive server starting on {host}:{port}")
-    app.run(host=host, port=port, use_reloader=False)
+    serve(app, host=host, port=port)
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that the Flask development server is not for production and recommends a production-grade alternative, which aligns with the PR's goal of creating a robust, deployable bot.

Medium
  • More

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant