Repository navigation
fix(config): route direct-env config bypasses through the layered resolver - #3243
Conversation
…olver Problem: polylogue-9gh1's uu8r-class finding -- ~20 files read genuinely POLYLOGUE_*-namespaced, TOML-backed settings straight from os.environ instead of load_polylogue_config(), so site/user TOML precedence was silently dead for those call sites even though every one of the settings was already fully inventoried in polylogue/config.py. What changed: migrated 17 files' direct os.environ.get(...) bypasses for already-inventoried settings (daemon_url, no_daemon, daemon_client_mode, voyage_api_key, theme, backup_verify_tmpdir, antigravity_language_server, drive_credentials_path, drive_token_path, live_full_ingest_workers, schema_validation, ingest_commit_batch_messages) to read through load_polylogue_config() (or an already-resolved Config/IndexConfig object first, falling back to the layered resolver). load_polylogue_config is the sole five-layer resolver per the fd2s/testsuite-diet contract; no second resolution path was introduced. Two provenance subtleties surfaced and were handled explicitly rather than papered over: - Several inventoried settings (daemon_url, drive_credentials_path, drive_token_path) have a non-empty *default-layer* value, so a bare "is it set" check on the resolved value can't distinguish "explicitly configured" from "using the same-shaped built-in default". Call sites that need that distinction (status.py's daemon-port discovery skip, drive/auth.py's config -> env -> XDG-default -> prompt chain) now check `PolylogueConfig.layer_of(key) != "default"` instead of truthiness. - An empty-string POLYLOGUE_DAEMON_URL is a valid (if unusual) env layer value under _apply_env_overrides, but existing call sites treated an empty override as "unset, use the built-in URL" (see tests/unit/cli/commands/test_status.py::test_empty_env_var_returns_builtin). Preserved that behavior with an explicit `or <builtin>` at each site rather than changing the empty-string-env semantics globally. Also fixed a latent AttributeError in pipeline/run_stages.py::execute_embed_stage (config.index_config assumed a real Config; some callers pass a lighter-weight stand-in) by using getattr with a None fallback. Not in scope (deferred, see PR body): ~7-8 files reading POLYLOGUE_* settings that are not yet in the config.py inventory at all (dev-loop run id/log dir, hook provider override, revision-parse dispatch/pool byte thresholds, raw-authority commit batch size, daemon parse-stage worker/inflight/cache/timeout knobs, coordination session-ref lookup) -- these need new ConfigInventoryEntry rows (+ render regen) before a caller migration is meaningful, which is a separate unit of work from routing already-inventoried settings through the existing resolver. Verification: ruff check/format --check, mypy --strict on all touched files (0 errors); devtools test across the touched surface's existing test files (853 passed, 5 pre-existing/unrelated failures reproduced identically on the pre-change tree: test_status.py's route-catalog drift, test_dashboard_command's RuntimeServices ConfigError, and three test_import.py demo-fixture-world convergence failures -- none reference daemon_url/voyage_api_key/backup_verify_tmpdir/antigravity_language_server/ theme/no_daemon). Ref polylogue-9gh1, polylogue-uu8r Co-Authored-By: Claude <[email protected]>
…bug shapes Problem: polylogue-9gh1's design explicitly requires "a regression test fixture [that] exercises all three shapes so a new instance of any of them fails CI rather than needing rediscovery by a future dogfooding pass" -- no such test existed before this commit, even though two of the three bug classes (fd2s split-system delegation, cxlk nested-table full-replace) were already fixed on master (PR #3079) without regression coverage. What changed: tests/unit/core/test_config_resolution_regression.py adds three test classes, one per bug shape, each pinned against a real runtime consumer (not a synthetic replica): - TestNestedTableDeepMergePreservesSiblings (cxlk-class): a two-layer TOML fixture (site sets default_warning + default_error + two family overrides; user overrides only default_error) asserts both the raw merged dict and daemon.convergence_debt_alert.load_thresholds_from_config / daemon.cursor_lag_alert.load_thresholds_from_config retain the site layer's siblings alongside the user layer's override. - TestDelegatedSettingsReachRealConsumers (fd2s-class): TOML-only archive.root reaches resolve_runtime_config().paths.archive_root (the flagship setting), and TOML-only embedding.voyage_api_key (no env var) reaches storage.search_providers.create_vector_provider's actual SqliteVecProvider construction. - TestDirectEnvBypassCallersRouteThroughResolver (uu8r-class): TOML-only maintenance.backup_verify_tmpdir reaches daemon.backup._backup_verification_scratch_parent, and TOML-only sources.antigravity.language_server reaches sources.parsers.antigravity.discover_language_server -- both call sites migrated in the prior commit. Each class's docstring states the exact reverted mutation that makes the test fail (verified manually, not merely asserted): reverting _deep_merge_table to a shallow update, or restoring any of the three os.environ.get(...) call sites this PR migrated. Verification: devtools test tests/unit/core/test_config_resolution_regression.py (6 passed); manually reverted each of the three fixes in turn and re-ran the corresponding test class to confirm failure (deep-merge: KeyError on the dropped sibling key; voyage_api_key: provider construction returns None; backup_verify_tmpdir/antigravity_language_server: resolved path falls back to the hardcoded default instead of the fixture path) -- all three witnesses reproduced, then reverted back. ruff check/format --check, mypy --strict clean. Ref polylogue-9gh1 Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (18)
✨ 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 |
|
Coordinator stand-in review (CodeRabbit rate-limited): read the full 756-line diff. Mechanical read-path substitution behind existing inventory entries, with the two provenance subtleties handled correctly (layer_of gating for non-empty defaults; empty-string env daemon_url treated as unset per pre-existing test contract). The already-fixed-by-#3079 finding for fd2s/cxlk plus adding the missing regression coverage is the right shape. Deferred un-inventoried settings correctly named under uu8r. Merging. |
….py (#3248) ## Summary Lands the residual polylogue-uu8r-class scope PR #3243 explicitly deferred: 8 genuinely `POLYLOGUE_*`-namespaced settings that had **no config-inventory entry at all** (distinct from an already-inventoried key whose caller merely bypassed the resolver — that class was closed by #3243). Re-derived the file list live against master with `rg 'os\.environ.*POLYLOGUE_' polylogue/` rather than trusting the bead's stale 31-file/7-8-file counts, which had drifted after #3243 and #3079 landed. ## Problem `investigations/config-resolution.md`'s dogfood-2 round-2 config investigation found `config.py` documents a 5-layer TOML/env precedence system, but several settings bypassed it entirely because they were never inventoried in the first place — so TOML could never reach them regardless of caller migration: - `POLYLOGUE_HOOK_PROVIDER` (hook-harness detection override) - `POLYLOGUE_RAW_AUTHORITY_COMMIT_BATCH_SIZE` (raw-materialization repair batching) - 4 daemon parse-stage prefetch knobs: `POLYLOGUE_DAEMON_PARSE_STAGE_{WORKERS,MAX_INFLIGHT_BYTES,MAX_CACHED_TREE_BYTES,WARM_TIMEOUT_SECONDS}` - 2 revision-parse dispatch thresholds: `POLYLOGUE_REVISION_PARSE_{DISPATCH_MAX_BYTES,POOL_MIN_BYTES}` ## Solution - Added 8 `ConfigInventoryEntry` rows to `polylogue/config.py` plus matching `PolylogueConfig` properties, `_default_config_values` defaults, and `_INT_CONFIG_KEYS`/`_FLOAT_CONFIG_KEYS` coercion entries, following existing `owner_class`/`reload_behavior` conventions (mirrors the `ingest_commit_batch_messages`/`daemon_parse_stage_split` siblings). - Migrated each call site's `os.environ.get(...)` read to `load_polylogue_config().<key>`, preserving each function's existing "explicit override wins, invalid/absent falls back to the module default" semantics exactly — no behavior change for unconfigured deployments. - Documented all 8 new keys in `docs/configuration.md` (TOML-key table + env-var quick-reference table). ### Per-setting judgment table | Setting | Decision | Rationale | | --- | --- | --- | | `hook_provider` | **Inventoried** (`sources.hook_provider`) | Operator-settable harness-detection override, same shape as the `theme` reference pattern (env wins, falls to TOML otherwise). | | `raw_authority_commit_batch_size` | **Inventoried** (`pipeline.raw_authority.commit_batch_size`) | Genuine perf tunable, direct sibling of `ingest_commit_batch_messages`. | | `daemon_parse_stage_workers` / `max_inflight_bytes` / `max_cached_tree_bytes` / `warm_timeout_seconds` | **Inventoried** (`daemon.raw_materialization.parse_stage_*`) | Daemon-owned resource-policy knobs, direct siblings of `daemon_parse_stage_split`; read from `DaemonParseStage.__init__` in-process (ThreadPoolExecutor, never a spawned worker) — no multiprocessing-spawn hazard. | | `revision_parse_dispatch_max_bytes` / `pool_min_bytes` | **Inventoried** (`pipeline.revision_parse.*`) | Perf-tuning thresholds with measured rationale in their docstrings; read in dispatcher/orchestration code before `ProcessPoolExecutor` creation, never inside a worker — no spawn hazard. | | `POLYLOGUE_DEV_LOOP_RUN_ID` / `POLYLOGUE_DEV_LOOP_LOG_DIR` | **Intentional env-only exemption** | Launcher-injected correlation metadata for one process invocation, structurally identical to `CODEX_SESSION_ID`/`CLAUDE_SESSION_ID` (already out of the config domain), not an operator TOML preference. Documented at each call site + `docs/configuration.md`. | | `POLYLOGUE_SESSION_REF` | **Intentional env-only exemption** | Same class as above — grouped with `CODEX_THREAD_ID`/`CODEX_SESSION_ID`/`CLAUDE_SESSION_ID` in `coordination/envelope.py`. | | `POLYLOGUE_CONFIG` | **Intentional bootstrap-only exemption** | Selects *which* user TOML file the layered resolver loads, so it cannot itself be resolved through that resolver — mirrors `config.py`'s own `_user_config_path`/`_site_config_path` bootstrap reads. | | `POLYLOGUE_ARCHIVE_ROOT` in `daemon/http.py::_dev_loop_payload` | **Left raw (diagnostic probe)** | `archive_root` itself IS inventoried, but this endpoint reports whether the daemon's *own environment* has the var set (launcher diagnosis), not a config value; routing through the resolver would mask an unset env var behind the TOML/default fallback and defeat the probe's purpose. | ## Verification - `devtools test tests/unit/core/test_config_resolution_regression.py`: 16 passed (6 pre-existing fd2s/cxlk/uu8r-class + 10 new — one regression class per newly-inventoried setting family, against its real consumer, each with a revert-witness docstring). Live-verified the raw-authority witness by reverting that call site to `os.environ.get` and confirming the test fails (`20 != 4242`) before restoring the fix. - Touched-consumer files, run individually: `test_config.py` (95), `test_config_inventory.py` (60), `test_hooks.py` (8), `test_repair.py` (55), `test_revision_backfill.py` (44), `test_parse_prefetch.py` (12), `test_envelope.py` (26), `test_embed.py` (18), `test_backup.py` (23) — all passed. - `devtools verify --quick`: ruff format/check, mypy --strict, `render all --check` (grepped for "out of sync": none), topology/layering/closure-matrix, docs-coverage, and the rest of the quick gate all green (`exit_code: 0`), both standalone and via the pre-push hook. ## AC matrix (polylogue-uu8r) | AC | Status | | --- | --- | | Every direct `os.environ` POLYLOGUE_* read outside `config.py` is classified | Satisfied — re-derived via `rg`, 7 files / 8 settings genuinely un-inventoried; 4 settings classified as intentional env-only/bootstrap exemptions with rationale documented at call sites + docs. | | All class-(a) (genuine TOML-backed) sites route through `config.py` | Satisfied — 8 settings, 7 files. | | Config diagnostics output includes the migrated settings | Satisfied — driven automatically from `_CONFIG_INVENTORY` (`config_inventory_payload`, `_toml_section_layout`, `_ENV_CONFIG_KEY_MAP` all derive from the inventory list). | | `devtools test` on affected files + `config.py` passes | Satisfied — see Verification above. | Ref polylogue-uu8r; last open child of polylogue-9gh1. --------- Co-authored-by: Claude <[email protected]>
Summary
Lands the uu8r-class piece of the polylogue-9gh1 epic (config.py's documented 5-layer precedence vs actual runtime behavior) plus the fixture-driven regression test the epic's design requires across all three named bug shapes. The other two pieces (fd2s split-system delegation, cxlk nested-table deep-merge) were already fixed on master via PR #3079 before this branch was cut; this PR adds the regression coverage that was still missing for them and lands new fixes for the remaining env-bypass class.
Problem
investigations/config-resolution.md(dogfood-2 round-2) found config.py's documented 5-layer precedence (defaults -> site TOML -> user TOML -> POLYLOGUE_* env -> CLI) silently does not hold for the whole inventoried surface, in three structurally distinct ways:resolve_runtime_config/ResolvedRuntimeConfig)._deep_merge_tableinpolylogue/config.py:1749).os.environbypass) -- ~20 files read genuinely POLYLOGUE_*-namespaced, TOML-backed settings straight fromos.environinstead ofload_polylogue_config(), so TOML/site/user layering never reached those call sites even though every one of the settings involved was already fully inventoried inconfig.py.None of the three bug shapes had regression coverage:
grepfor_deep_merge_table/health_convergence_debt/ResolvedRuntimeConfigacrosstests/unit/core/test_config.pybefore this PR turns up construction/precedence tests for flat scalar keys only, nothing that would fail if the nested-merge or delegation fixes were reverted.Solution
Commit 1 (
fix(config): ...) migrates 17 files' directos.environ.get(...)reads for already-inventoried settings toload_polylogue_config()(or an already-resolvedConfig/IndexConfigobject first, falling back to the layered resolver where one is in scope):daemon_url(6 call sites:cli/commands/{dashboard,import_command,status,tutorial}.py,daemon/cli.py),no_daemon/daemon_client_mode(cli/archive_query.py,cli/commands/facets.py),voyage_api_key(3 residual call sites:cli/commands/embed.py,pipeline/run_stages.py,storage/search_providers/__init__.py),theme(ui/theme.py),backup_verify_tmpdir(daemon/backup.py),antigravity_language_server(sources/parsers/antigravity.py),drive_credentials_path/drive_token_path(sources/drive/auth.py),live_full_ingest_workers(sources/live/batch_support.py),schema_validation/ingest_commit_batch_messages(pipeline/services/ingest_batch/_core.py,pipeline/services/archive_ingest.py).load_polylogue_configremains the sole five-layer resolver per the fd2s/testsuite-diet contract -- no second resolution path was introduced.Two non-obvious subtleties, handled explicitly:
daemon_url,drive_credentials_path,drive_token_path) have a non-empty default-layer value, so a bare truthiness check on the resolved value can't distinguish "explicitly configured" from "using the built-in default shape". Call sites that need that distinction (status.py's daemon-port discovery skip,drive/auth.py's config -> env -> XDG-default -> prompt chain) now checkPolylogueConfig.layer_of(key) != "default"instead.POLYLOGUE_DAEMON_URLis a valid env-layer value under_apply_env_overrides, but existing call sites treated an empty override as "unset, use the built-in URL" (tests/unit/cli/commands/test_status.py::test_empty_env_var_returns_builtin). Preserved that per-call-site behavior with an explicitor <builtin>rather than changing empty-string-env semantics globally.Also fixed a latent
AttributeErrorinpipeline/run_stages.py::execute_embed_stage(assumedconfig.index_configalways exists; some test/lightweight callers pass a stand-in without it) viagetattr(config, "index_config", None).Commit 2 (
test(config): ...) addstests/unit/core/test_config_resolution_regression.py: three test classes, one per bug shape, each exercising a real runtime consumer (not a synthetic replica):TestNestedTableDeepMergePreservesSiblings(cxlk-class): a two-layer TOML fixture (site setsdefault_warning+default_error+two family overrides; user overrides onlydefault_error) asserts both the raw merged dict anddaemon.convergence_debt_alert.load_thresholds_from_config/daemon.cursor_lag_alert.load_thresholds_from_configretain the site layer's siblings.TestDelegatedSettingsReachRealConsumers(fd2s-class): TOML-onlyarchive.rootreachesresolve_runtime_config().paths.archive_root; TOML-onlyembedding.voyage_api_key(no env var) reachescreate_vector_provider's actualSqliteVecProviderconstruction.TestDirectEnvBypassCallersRouteThroughResolver(uu8r-class): TOML-onlymaintenance.backup_verify_tmpdirreachesdaemon.backup._backup_verification_scratch_parent; TOML-onlysources.antigravity.language_serverreachessources.parsers.antigravity.discover_language_server.Each class's docstring states the exact reverted mutation that makes its test(s) fail; all were manually verified (reverted, re-ran, confirmed failure, restored).
Verification
ruff check/ruff format --checkon all 18 touched files: clean.mypy --stricton all 18 touched files:Success: no issues found in 18 source files.devtools test tests/unit/core/test_config_resolution_regression.py: 6 passed._deep_merge_tableto a shallow{**existing, **incoming}fails both nested-table tests withKeyErroron the dropped sibling key; reverting any of the three env-bypass fixes (search_providers,backup.py,antigravity.py) fails the corresponding delegated/env-bypass test; revertingresolve_runtime_config'sarchive_rootwiring fails the archive-root delegation test.devtools testacross the touched surface's existing test files (tests/unit/cli/test_{archive_query,dashboard_command,embed,embed_activation,embed_status_fast,import,status,tutorial}.py,tests/unit/cli/commands/test_status.py,tests/unit/cli/test_status_diagnostics.py,tests/unit/archive/test_facets.py,tests/unit/daemon/{test_backup,test_daemon_cli}.py,tests/unit/cli/test_backup_command.py,tests/unit/pipeline/{test_run_stages_runtime,test_archive_ingest_commit_batching}.py,tests/unit/core/{test_health_core,test_config,test_config_resolution_regression}.py,tests/unit/cli/test_auth.py,tests/unit/sources/{test_drive_auth,test_live_batch_support,test_antigravity_language_server}.py,tests/unit/sources/parsers/test_antigravity.py,tests/unit/storage/test_vec.py,tests/unit/cli/test_theme_aliases_help_markdown.py): 853 passed, 5 failures -- all 5 reproduced identically with the diff reverted (git stash), confirming they are pre-existing/unrelated:test_status.py::test_archive_facade_route_catalog_covers_public_async_facade(unrelated route-catalog drift),test_dashboard_command.py::test_dashboard_default_prints_evidence_before_launching_tui(ConfigError('RuntimeServices has no config projection'), unrelated to daemon_url), and threetest_import.pydemo-fixture-world convergence failures.devtools verify --quickran automatically via the pre-push hook: exit 0.devtools verify --seed-testmon --skip-slowin the background; it did not finish within a 590s budget and showed widespread failures across modules this PR does not touch, consistent with concurrent-session resource contention on this shared checkout (multiple other agent worktrees were running tests in parallel at the time) rather than this diff -- not chased further per the repo's testmon-inner-loop verification policy (targeted-file selection over blanket full-suite runs).AC matrix (epic polylogue-9gh1)
toml_pathrespects site/user TOML precedence for its real runtime consumer (fd2s-class)VOYAGE_API_KEYbypass call sites the earlier PR didn't reach and adds regression coverage_deep_merge_table); this PR adds the regression test that was missingtests/unit/core/test_config_resolution_regression.py, one class per shape, real-consumer assertions, reverted-mutation witnesses documented and manually verifiedDeferred-with-reason (uu8r remaining scope): ~7-8 files read POLYLOGUE_*-namespaced settings that are not yet in the config.py inventory at all --
POLYLOGUE_DEV_LOOP_RUN_ID/POLYLOGUE_DEV_LOOP_LOG_DIR(daemon/cli.py,daemon/http.py),POLYLOGUE_HOOK_PROVIDER(hooks/__init__.py),POLYLOGUE_RAW_AUTHORITY_COMMIT_BATCH_SIZE(storage/repair.py),POLYLOGUE_DAEMON_PARSE_STAGE_{WORKERS,MAX_INFLIGHT_BYTES,MAX_CACHED_TREE_BYTES,WARM_TIMEOUT_SECONDS}(daemon/parse_prefetch.py),POLYLOGUE_SESSION_REF(coordination/envelope.py),POLYLOGUE_REVISION_PARSE_{DISPATCH_MAX_BYTES,POOL_MIN_BYTES}(sources/revision_backfill.py). These need newConfigInventoryEntryrows plus arenderregen (docs/openapi/cli-output-schemas) before a caller migration is meaningful -- a distinct, larger unit of work from routing the ~15 settings that were already inventoried but bypassed, which this PR completes. Recommend claiming the remainder directly under polylogue-uu8r.Ref polylogue-9gh1, polylogue-uu8r
Co-Authored-By: Claude [email protected]