Skip to content

fix: [RBAC Migration]Hydrate workspace config at startup#1575

Merged
edwinjosechittilappilly merged 4 commits into
mainfrom
fix-onboarding
May 13, 2026
Merged

fix: [RBAC Migration]Hydrate workspace config at startup#1575
edwinjosechittilappilly merged 4 commits into
mainfrom
fix-onboarding

Conversation

@edwinjosechittilappilly

@edwinjosechittilappilly edwinjosechittilappilly commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Add WorkspaceConfigService.hydrate_on_startup() which calls load_config() to eagerly populate the config manager from the DB during application startup. Call this method from the app lifespan (run_startup) and log errors if hydration fails. This prevents a DB-mode restart from leaving the in-memory config unset and causing the frontend onboarding wizard to reappear; load_config() is mode-aware, so invoking it unconditionally is safe.

Summary by CodeRabbit

  • New Features

    • App now eagerly preloads workspace configuration at startup so stored settings are available immediately after restart.
  • Bug Fixes

    • Prevents unexpected fallback to defaults or onboarding when a DB-backed config exists but wasn't yet loaded.
  • Chores

    • Reduced shutdown log verbosity for background-task cancellation.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a54ed369-5938-49f3-85f5-ebdab98a8d3a

📥 Commits

Reviewing files that changed from the base of the PR and between 8dc9ce5 and 6b556ee.

📒 Files selected for processing (2)
  • src/app/lifespan.py
  • src/services/workspace_config_service.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/app/lifespan.py
  • src/services/workspace_config_service.py

Walkthrough

Adds WorkspaceConfigService.hydrate_on_startup() to eagerly load config into the in-process cache at app startup; integrates that call into run_startup() with error logging; updates several type annotations to PEP 604 union syntax; adjusts DB-mirroring patch closures; simplifies shutdown background-task cancellation logging.

Changes

Configuration Cache Hydration at Startup

Layer / File(s) Summary
Typing imports
src/services/workspace_config_service.py
Remove Optional import to adopt PEP 604 union syntax.
Service Initialization Method
src/services/workspace_config_service.py
New hydrate_on_startup() async method that calls load_config() to populate the in-memory ConfigManager cache.
Public API Type Annotation Updates
src/services/workspace_config_service.py
Update public method annotations to use `X
Internal Helper Annotation Updates
src/services/workspace_config_service.py
Update internal helper parameter annotations to use PEP 604 union types (`OpenRAGConfig
DB-mirroring patch adjustments
src/services/workspace_config_service.py
Patched save/update closures capture original callables into local variables (with type: ignore[attr-defined]).
Startup Wiring
src/app/lifespan.py
run_startup() conditionally calls workspace_config_service.hydrate_on_startup() and logs an error if hydration fails.
Shutdown Logging Simplification
src/app/lifespan.py
Background-task cancellation logging consolidated to a single-line logger.info() call.

Sequence Diagram(s)

sequenceDiagram
  participant ASGIApp
  participant WorkspaceConfigService
  participant ConfigManager
  ASGIApp->>WorkspaceConfigService: call hydrate_on_startup()
  WorkspaceConfigService->>ConfigManager: call load_config()
  ConfigManager-->>WorkspaceConfigService: return loaded config
  WorkspaceConfigService-->>ASGIApp: complete startup hydration (or raise/log error)
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 captures the main change: adding workspace config hydration at startup to fix an RBAC migration issue. It is specific, concise, and clearly summarizes the primary improvement.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-onboarding

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.

@github-actions github-actions Bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. labels May 11, 2026
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels May 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an eager workspace-config hydration step during application startup to prevent DB-mode restarts from leaving the in-memory config unset (which can re-trigger onboarding UI behavior).

Changes:

  • Add WorkspaceConfigService.hydrate_on_startup() to preload configuration via load_config() at startup.
  • Invoke hydration from run_startup() and log failures without crashing startup.
  • Minor formatting change to shutdown logging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/services/workspace_config_service.py Introduces a startup hydration method that eagerly loads workspace config into memory.
src/app/lifespan.py Calls hydration during startup with error logging; minor log formatting adjustment during shutdown.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/lifespan.py
Comment on lines +179 to +184
try:
wcs = services.get("workspace_config_service")
if wcs is not None:
await wcs.hydrate_on_startup()
except Exception as e:
logger.error("Workspace config hydration failed at startup", error=str(e))
Comment on lines +141 to +145
"""Eagerly populate ``config_manager._config`` from the DB at
lifespan startup.

Without this, in `db` mode a restart leaves ``_config = None``
and the synchronous ``get_openrag_config()`` falls back to
@github-actions github-actions Bot added the bug 🔴 Something isn't working. label May 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
src/services/workspace_config_service.py (1)

171-171: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix the type annotation to use PEP 604 union syntax.

The pipeline reports that Optional[Any] should be replaced with Any | None (rule UP045).

🔧 Proposed fix
-    async def get_onboarding_step(self) -> Optional[Any]:
+    async def get_onboarding_step(self) -> Any | None:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/workspace_config_service.py` at line 171, The return type
annotation of get_onboarding_step should use PEP 604 union syntax; change its
signature from "async def get_onboarding_step(self) -> Optional[Any]:" to use
"-> Any | None" and update imports accordingly (remove Optional from typing
imports if no longer used and ensure Any is imported). Also run a quick search
for other Optional[Any] usages in this module to convert them to the new "Any |
None" form for consistency with rule UP045.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/lifespan.py`:
- Around line 179-184: The current try/except around
services.get("workspace_config_service") and await wcs.hydrate_on_startup()
swallows errors and only logs them via logger.error, allowing startup to
continue with missing config; change the handler so hydration failures are
treated as fatal: when hydrate_on_startup() raises (or if wcs is None
unexpectedly), log the detailed error with logger.error including the exception,
then abort startup by re-raising the exception or invoking a clean process exit
(e.g., raise the caught exception or call sys.exit(1)) so the app does not start
with an empty/default workspace config.

---

Outside diff comments:
In `@src/services/workspace_config_service.py`:
- Line 171: The return type annotation of get_onboarding_step should use PEP 604
union syntax; change its signature from "async def get_onboarding_step(self) ->
Optional[Any]:" to use "-> Any | None" and update imports accordingly (remove
Optional from typing imports if no longer used and ensure Any is imported). Also
run a quick search for other Optional[Any] usages in this module to convert them
to the new "Any | None" form for consistency with rule UP045.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c61c2c7c-2aa2-4046-98cf-66ff7bad538d

📥 Commits

Reviewing files that changed from the base of the PR and between 4c31515 and cbe6b24.

📒 Files selected for processing (2)
  • src/app/lifespan.py
  • src/services/workspace_config_service.py

Comment thread src/app/lifespan.py
Comment on lines +179 to +184
try:
wcs = services.get("workspace_config_service")
if wcs is not None:
await wcs.hydrate_on_startup()
except Exception as e:
logger.error("Workspace config hydration failed at startup", error=str(e))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Consider whether hydration failure should halt startup.

The error is logged but startup continues if hydrate_on_startup() fails. This means the app will serve requests with an empty/default config, potentially causing the onboarding wizard to reappear unexpectedly.

Given that the PR objective is to fix exactly this scenario (preventing the wizard from reappearing after restart), should a hydration failure be treated as fatal?

💡 Alternative: Fail fast on hydration error
     try:
         wcs = services.get("workspace_config_service")
         if wcs is not None:
             await wcs.hydrate_on_startup()
     except Exception as e:
         logger.error("Workspace config hydration failed at startup", error=str(e))
+        raise

This would prevent the app from starting with stale/empty config, making the failure obvious rather than allowing degraded behavior.

📝 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
try:
wcs = services.get("workspace_config_service")
if wcs is not None:
await wcs.hydrate_on_startup()
except Exception as e:
logger.error("Workspace config hydration failed at startup", error=str(e))
try:
wcs = services.get("workspace_config_service")
if wcs is not None:
await wcs.hydrate_on_startup()
except Exception as e:
logger.error("Workspace config hydration failed at startup", error=str(e))
raise
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/lifespan.py` around lines 179 - 184, The current try/except around
services.get("workspace_config_service") and await wcs.hydrate_on_startup()
swallows errors and only logs them via logger.error, allowing startup to
continue with missing config; change the handler so hydration failures are
treated as fatal: when hydrate_on_startup() raises (or if wcs is None
unexpectedly), log the detailed error with logger.error including the exception,
then abort startup by re-raising the exception or invoking a clean process exit
(e.g., raise the caught exception or call sys.exit(1)) so the app does not start
with an empty/default workspace config.

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels May 11, 2026
edwinjosechittilappilly and others added 4 commits May 12, 2026 12:40
Add WorkspaceConfigService.hydrate_on_startup() which calls load_config() to eagerly populate the config manager from the DB during application startup. Call this method from the app lifespan (run_startup) and log errors if hydration fails. This prevents a DB-mode restart from leaving the in-memory config unset and causing the frontend onboarding wizard to reappear; load_config() is mode-aware, so invoking it unconditionally is safe.
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels May 12, 2026
@github-actions github-actions Bot added the lgtm label May 13, 2026
@edwinjosechittilappilly
edwinjosechittilappilly merged commit 9f25216 into main May 13, 2026
17 of 19 checks passed
@github-actions
github-actions Bot deleted the fix-onboarding branch May 13, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants