Skip to content

Conversation

@matdev83
Copy link
Owner

@matdev83 matdev83 commented Oct 12, 2025

Summary

  • ensure ConfigManager respects the STRICT_PERSISTENCE_ERRORS environment flag when deciding whether to raise DI failures
  • add a regression test covering the strict persistence error path for default backend resolution

Testing

  • python -m pytest -o addopts='' tests/unit/test_config_persistence.py::test_apply_default_backend_strict_errors_env
  • python -m pytest -o addopts=''

https://chatgpt.com/codex/tasks/task_e_68ec25e4aee08333a1a09066d47a3acf

Summary by CodeRabbit

  • New Features
    • Added an environment variable to control strict persistence error handling. Setting STRICT_PERSISTENCE_ERRORS to a truthy value (e.g., true, 1, yes) enables strict mode, overriding configuration. Default remains disabled.
  • Tests
    • Added unit tests to verify strict mode behavior and error surfacing when persistence backends are misconfigured.

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds environment-variable override for strict persistence error handling by reading STRICT_PERSISTENCE_ERRORS in src/core/persistence.py and updating the decision logic. Includes corresponding unit test that sets the environment variable, triggers a failing provider, asserts ServiceResolutionError is raised, and cleans up the environment.

Changes

Cohort / File(s) Summary
Persistence strict-error override
src/core/persistence.py
Reads STRICT_PERSISTENCE_ERRORS from environment (truthy: true/1/yes) to force strict error behavior; retains config-based fallback; adds os import.
Unit tests for strict errors
tests/unit/test_config_persistence.py
Adds test enabling STRICT_PERSISTENCE_ERRORS, uses failing provider to assert ServiceResolutionError on _apply_default_backend("openai"); cleans env var; updates imports.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test as Unit Test
  participant Env as Environment
  participant Persist as Persistence
  participant Provider as DI Provider

  Test->>Env: Set STRICT_PERSISTENCE_ERRORS=true
  Test->>Persist: _apply_default_backend("openai")
  Persist->>Env: Read STRICT_PERSISTENCE_ERRORS
  alt strict enabled
    Persist->>Persist: _should_raise_strict_errors = True
    Persist->>Provider: Resolve backend provider
    Provider-->>Persist: ServiceResolutionError
    Persist-->>Test: Raise ServiceResolutionError
  else strict disabled
    Persist->>Persist: Use config-based logic
    Persist-->>Test: Proceed per existing behavior
  end
  Test->>Env: Unset STRICT_PERSISTENCE_ERRORS
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I toggled a flag with a twitch of my ear,
"Strict!" squeaked the code—now errors are clear.
Env winds whisper true/yes/one,
Tests hop in, the failing run.
Carrots compiled, persistence tight—
A rabbit approves this stricter bite.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly reflects the main change by indicating that the code now respects the STRICT_PERSISTENCE_ERRORS environment variable when handling persistence dependency injection errors, matching the PR’s objective to update error handling behavior.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-one-bug-in-error-handling-7a2294

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

Copy link

@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

🧹 Nitpick comments (1)
tests/unit/test_config_persistence.py (1)

234-260: Test correctly validates the strict error behavior.

The test properly:

  • Sets the STRICT_PERSISTENCE_ERRORS environment variable.
  • Uses a failing provider that raises ServiceResolutionError.
  • Verifies that the exception propagates when strict mode is enabled.
  • Cleans up the environment variable.

Optional: Simplify _StrictAppState class.

The _StrictAppState class only overrides set_backend_type with the same implementation as its parent _DummyAppState. Consider using _DummyAppState directly:

-    class _StrictAppState(_DummyAppState):
-        def set_backend_type(self, backend_type: str | None) -> None:  # type: ignore[override]
-            self.backend_type = backend_type
-
     class _FailingProvider:
         def get_required_service(self, _service_type):  # type: ignore[no-untyped-def]
             raise ServiceResolutionError("boom")
 
     monkeypatch.setenv("STRICT_PERSISTENCE_ERRORS", "true")
 
     manager = ConfigManager(
         FastAPI(),
         path=str(tmp_path / "config.json"),
         service_provider=_FailingProvider(),
-        app_state=_StrictAppState(),
+        app_state=_DummyAppState(),
     )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 326702b and 1947058.

📒 Files selected for processing (2)
  • src/core/persistence.py (2 hunks)
  • tests/unit/test_config_persistence.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting

Files:

  • src/core/persistence.py
  • tests/unit/test_config_persistence.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions

Files:

  • src/core/persistence.py
🧬 Code graph analysis (1)
tests/unit/test_config_persistence.py (3)
src/core/common/exceptions.py (2)
  • ConfigurationError (96-105)
  • ServiceResolutionError (141-150)
tests/unit/core/app/controllers/test_models_controller.py (2)
  • get_required_service (24-32)
  • get_required_service (77-80)
src/core/persistence.py (2)
  • ConfigManager (25-532)
  • _apply_default_backend (94-175)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (3.10)
🔇 Additional comments (3)
src/core/persistence.py (2)

3-3: LGTM!

The os import is correctly placed with other standard library imports, following PEP 8 import ordering conventions.


40-48: LGTM!

The environment variable check is well-implemented:

  • Gives environment variable precedence over config, which aligns with the PR objectives.
  • Uses sensible truthy values ("true", "1", "yes").
  • Maintains backward compatibility by falling back to config-based logic.
tests/unit/test_config_persistence.py (1)

15-19: LGTM!

The import of ServiceResolutionError is correctly added and follows PEP 8 import ordering (standard library, third-party, then local imports).

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/persistence.py 75.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@matdev83
Copy link
Owner Author

Fast-Track Processing Result: ❌ REJECTED

Reason: Cherry-pick conflicts detected

Eligibility Check ✅

  • ✅ Commits: 1 (≤5)
  • ✅ Files: 2 (≤10)
  • ✅ Line changes: 38 total (≤200)
  • ✅ Target branch: dev
  • ✅ Author: Not a bot

Processing Attempt ❌

  • ❌ Cherry-pick failed with merge conflicts in:
    • src/core/persistence.py
    • tests/unit/test_config_persistence.py

Next Steps

This PR requires manual review and merge due to conflicts with current dev branch. Please use standard PR review process.

🤖 Generated with Claude Code

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.

2 participants