Skip to content

Add startup readiness checks and authenticated tenant readiness endpoint#434

Open
AJaySi wants to merge 1 commit intomainfrom
codex/improve-startup-health-checks-and-readiness-signals
Open

Add startup readiness checks and authenticated tenant readiness endpoint#434
AJaySi wants to merge 1 commit intomainfrom
codex/improve-startup-health-checks-and-readiness-signals

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 12, 2026

Motivation

  • Replace using init_database() as the sole readiness signal so startup validates filesystem and tenant DBs in multi-tenant mode.
  • Make startup failures explicit and optionally fail-fast in production to avoid running in an unknowingly degraded state.
  • Provide operators a per-tenant readiness check (under auth context) distinct from platform startup health.

Description

  • Added a shared startup health module backend/services/startup_health.py that verifies the workspace root exists and is writable, validates DB open/create for single-tenant or a tenant (or synthetic) path in multi-tenant, and performs required schema/table+column compatibility checks for baseline migrations using _REQUIRED_SCHEMA (e.g., onboarding_sessions, daily_workflow_plans).
  • Replaced init_database() as the primary readiness signal in both backend/main.py and backend/app.py by calling run_startup_health_routine() during application startup and logging errors explicitly, and re-raising to enable fail-fast behavior when configured.
  • Added an authenticated readiness endpoint GET /health/readiness (in both entrypoints) that returns the latest startup report via get_startup_status() and a per-tenant auth-context check via readiness_under_auth_context() which resolves the tenant DB path and attempts a session/query.
  • Added operator documentation docs/STARTUP_READINESS_BEHAVIOR.md describing single-tenant vs multi-tenant expectations, warning vs failure conditions, and the ALWRITY_FAIL_FAST_STARTUP / production default semantics.

Testing

  • Compiled the modified modules with python -m py_compile backend/services/startup_health.py backend/main.py backend/app.py which succeeded.
  • Executed the startup routine interactively via run_startup_health_routine() which exercised DB initialization paths and reported a failed status in this environment due to the workspace root not existing (this is environment-dependent and expected in a clean test container); the routine logged errors and warnings as designed.
  • No unit tests were added; behaviour validated via static compile and a runtime invocation of run_startup_health_routine().

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant