Repository navigation
feat(config): add typed PolylogueConfig, consolidate env reads (#829) - #910
Conversation
) Add PolylogueConfig dataclass with typed attribute access for all known config keys. load_polylogue_config() now returns PolylogueConfig instead of a plain dict. Consolidate 7 remaining os.environ.get() calls through the shared config layer. Co-Authored-By: Claude Opus 4.7 <[email protected]>
- Add PolylogueConfig dataclass with typed attribute access - load_polylogue_config() returns PolylogueConfig instead of dict - Consolidate 6 POLYLOGUE_* env reads through shared config - Export PolylogueConfig, load_polylogue_config, format_config_toml Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7185e8fd8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if env_var == "POLYLOGUE_SCHEMA_VALIDATION": | ||
| raw = str(load_polylogue_config().get("schema_validation", default)) | ||
| raw = load_polylogue_config().schema_validation | ||
| else: |
There was a problem hiding this comment.
Respect provided default in schema_validation_mode
For POLYLOGUE_SCHEMA_VALIDATION, this path now reads load_polylogue_config().schema_validation, and the config loader seeds that key to 'advisory'. As a result, callers that pass default=ValidationMode.STRICT (e.g., ValidationService) no longer get strict mode when env/config are unset, silently weakening validation behavior and allowing payloads that should fail strict checks.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed PolylogueConfig layer and updates several components to read configuration via load_polylogue_config() instead of directly reading environment variables.
Changes:
- Add
PolylogueConfigdataclass and changeload_polylogue_config()to return it. - Update multiple call sites (Drive auth, readiness, validation, CLI formatting, logging) to read config through the shared config layer.
- Minor refactors/formatting adjustments in a few modules.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| polylogue/config.py | Adds PolylogueConfig and changes load_polylogue_config() return type; adds schema_validation default. |
| polylogue/sources/drive/auth.py | Switches Drive credential/token path resolution to use load_polylogue_config(). |
| polylogue/readiness/init.py | Uses typed force_plain from config when reporting terminal readiness. |
| polylogue/pipeline/services/validation_flow.py | Reads schema validation mode from typed config. |
| polylogue/cli/shared/formatting.py | Switches plain-mode forcing logic to use load_polylogue_config(). |
| polylogue/logging.py | Adjusts imports around load_polylogue_config() usage for console rendering. |
| polylogue/cli/query_progress.py | Cleans up imports; adds a # noqa: E402 mid-file import. |
| polylogue/daemon/status.py | Refactors detection-warnings count query error handling. |
| polylogue/paths/_roots.py | Documents why XDG/legacy env reads remain for bootstrapping. |
| polylogue/pipeline/services/ingest_worker.py | Formatting-only: wraps long tuple type aliases. |
| polylogue/storage/sqlite/schema_bootstrap.py | Whitespace-only change (extra blank line). |
Comments suppressed due to low confidence (1)
polylogue/readiness/init.py:483
term_detailappendsPOLYLOGUE_FORCE_PLAIN=1based onload_polylogue_config().force_plain, which may be set via TOML/CLI rather than the env var. This makes the readiness report misleading. Consider reporting a source-agnostic flag (e.g.force_plain=1) or only mentioningPOLYLOGUE_FORCE_PLAINwhen the env var is actually present.
force_plain = "1" if load_polylogue_config().force_plain else ""
term_detail = f"TERM={term}, {cols}x{rows}, tty={is_tty}"
if force_plain:
term_detail += ", POLYLOGUE_FORCE_PLAIN=1"
checks.append(ReadinessCheck("terminal", VerifyStatus.OK, summary=term_detail))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| env_path = load_polylogue_config().get("drive_credentials_path") or str(drive_credentials_path()) | ||
| if env_path: | ||
| return Path(env_path).expanduser() | ||
|
|
| env_path = load_polylogue_config().get("drive_token_path") or str(drive_token_path()) | ||
| if env_path: | ||
| return Path(env_path).expanduser() | ||
|
|
| def load_polylogue_config( | ||
| *, | ||
| config_path: Path | None = None, | ||
| cli_overrides: dict[str, object] | None = None, | ||
| ) -> dict[str, object]: | ||
| ) -> PolylogueConfig: | ||
| """Load resolved Polylogue config with four-layer precedence. | ||
|
|
||
| Returns a dict suitable for constructing typed config models. | ||
| The dict always has all known keys with defaults applied. | ||
| Returns a typed ``PolylogueConfig`` with attribute access for | ||
| known keys and ``.get()`` / ``.raw`` for everything else. | ||
| """ |
| @@ -213,6 +289,7 @@ | |||
| "hooks_enabled": False, | |||
| "log_level": "INFO", | |||
| "force_plain": False, | |||
| "schema_validation": "advisory", | |||
| } | |||
| """Return configured schema validation mode.""" | ||
| if env_var == "POLYLOGUE_SCHEMA_VALIDATION": | ||
| raw = str(load_polylogue_config().get("schema_validation", default)) | ||
| raw = load_polylogue_config().schema_validation |
| from polylogue.config import Source, load_polylogue_config | ||
| from polylogue.core.timestamps import format_timestamp |
| from polylogue.config import load_polylogue_config | ||
|
|
| logger = logging.getLogger(__name__) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from polylogue.config import load_polylogue_config | ||
| from polylogue.storage.action_events.artifacts import ActionEventArtifactState | ||
| from polylogue.storage.action_events.artifacts import ActionEventArtifactState # noqa: E402 | ||
|
|
|
|
||
| _DETECTION_WARNINGS_COLUMN_DDL = "ALTER TABLE raw_conversations ADD COLUMN detection_warnings TEXT" | ||
|
|
||
|
|
| try: | ||
| detection_warnings_count = int( | ||
| conn.execute( | ||
| "SELECT COUNT(*) FROM raw_conversations WHERE detection_warnings IS NOT NULL" | ||
| ).fetchone()[0] | ||
| or 0 | ||
| ) | ||
| except sqlite3.OperationalError: | ||
| pass # Column may not exist yet (pre-migration) | ||
| with contextlib.suppress(sqlite3.OperationalError): | ||
| detection_warnings_count = int( | ||
| conn.execute( | ||
| "SELECT COUNT(*) FROM raw_conversations WHERE detection_warnings IS NOT NULL" | ||
| ).fetchone()[0] | ||
| or 0 | ||
| ) | ||
| except Exception: | ||
| pass |
Two acceptance-criteria leftovers. - #839 (semantic artifacts): adds the resilience-fallback section to `polylogue/archive/message/model_runtime.py` documenting when the runtime classifier falls back from stored `message_type` to inline-text inspection — a behavior PR #836 introduced but had not yet documented in code comments. - #829 (config): consolidates four remaining `os.environ.get()` calls in `cli/query_progress.py`, `cli/shared/formatting.py`, `logging.py`, and `pipeline/services/validation_flow.py` through `load_polylogue_config()`, finishing the env-consolidation pass started in PR #910. Refs #829, #839
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered `os.environ.get()` calls, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health all need one config contract. - `polylogue/config.py`: introduces `PolylogueConfig` dataclass with typed fields covering archive root, daemon settings, watch sources, embedding settings, and notification backend. `load_polylogue_config()` returns the typed instance and applies the four-layer precedence (defaults → TOML → env → flags) introduced in PR #889. - Six previously direct `os.environ.get()` reads under `cli/query_progress.py`, `cli/shared/formatting.py`, `daemon/status.py`, `logging.py`, `paths/_roots.py`, `pipeline/services/{ingest_worker,validation_flow}.py` now go through the config object so future env additions land in one place. Refs #829
Two acceptance-criteria leftovers. - #839 (semantic artifacts): adds the resilience-fallback section to `polylogue/archive/message/model_runtime.py` documenting when the runtime classifier falls back from stored `message_type` to inline-text inspection — a behavior PR #836 introduced but had not yet documented in code comments. - #829 (config): consolidates four remaining `os.environ.get()` calls in `cli/query_progress.py`, `cli/shared/formatting.py`, `logging.py`, and `pipeline/services/validation_flow.py` through `load_polylogue_config()`, finishing the env-consolidation pass started in PR #910. Refs #829, #839
Foundation slice for #829. Polylogue mixed hardcoded defaults, scattered `os.environ.get()` calls, CLI flags, and partial dataclasses; after #847 daemon convergence, embeddings, hook install, auth, and health all need one config contract. - `polylogue/config.py`: introduces `PolylogueConfig` dataclass with typed fields covering archive root, daemon settings, watch sources, embedding settings, and notification backend. `load_polylogue_config()` returns the typed instance and applies the four-layer precedence (defaults → TOML → env → flags) introduced in PR #889. - Six previously direct `os.environ.get()` reads under `cli/query_progress.py`, `cli/shared/formatting.py`, `daemon/status.py`, `logging.py`, `paths/_roots.py`, `pipeline/services/{ingest_worker,validation_flow}.py` now go through the config object so future env additions land in one place. Refs #829
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Typed PolylogueConfig dataclass. load_polylogue_config() returns PolylogueConfig. Consolidated 6 env reads through config.