Skip to content

refactor(config): a settings field is the one declaration, and the option, env and config-show registries become views of it #1000

Closed
3 of 3 issues completed

Description

@dan-petty

Context & Rationale

Six hand-synchronised registries describe each setting, and eight read paths each know part of the resolution order. Checked at 9c879ae.

  • A new option-backed setting edits: a key in config/options.py, an ENV_* constant in config/env.py, an OPTION_TO_ENV_VAR entry, a CONFIG_OPTIONS entry, an EnvVarSpec in the 436-line hand-written get_all_env_var_specs() (env.py:220-655), a Settings field (settings.py:595-624), a DEFAULT_* in defaults.py, a help string, a _row() in commands/config.py (29 hand-written rows) and three __all__ entries in config/__init__.py: 10 to 12 edits across 6 files. The pyroscope item (8271385) spent 3 of its 5 source-file touches here for one URL.
  • Eight ways to read a setting: load_settings() (71 modules), dotted_get (4 command modules), raw os.environ (83 call sites outside config/, 11 of them in commands/devcontainer.py and 9 in telemetry/tracer.py), ENV_* constants (5 modules), raw DEFAULT_* imports (206 modules), the secret getters through security.secrets, opt.* dotted keys (9), and the config facade (13 modules using 11 of its 431 names).
  • 23 DEFAULT_* values are both a Settings field default and imported raw by feature modules (DEFAULT_OLLAMA_URLS, DEFAULT_QDRANT_URL, DEFAULT_OTEL_ENDPOINT, DEFAULT_AI_GATEWAY_URL, ...). A config.yaml override is honoured by one caller and ignored by another. ai/benchmark/{runner,suite,embedding_runner}.py also hard-code http://localhost:11434 as a fallback.
  • Tests patch load_settings 121 times at 15 distinct module paths; 25 test files patch config.settings._keyring_get, CONFIG_PATH or os.environ.get.

Deletion test: delete options.py, the registry in env.py and the config/__init__.py re-exports and nothing reappears; all of it is derivable from Settings field metadata. Delete settings.py and it reappears in 71 callers. That module is the seam.

Scope & Deliverables

Strategic Alignment

Scope added 2026-10-02: checked at 38517a8. Lines moved by about 11: Settings is at config/settings.py:606, _apply_env_overrides at :733-752, dotted_get and dotted_set at :1072 and :1095. get_llm_client (:1062) has 1 caller (ai/harness/workflow.py:498), not 3. The dual-path count needs re-measuring before it is used as evidence. The sampled raw imports read the setting first and fall back to the default only when it is empty, for example config.gateway_url or DEFAULT_AI_GATEWAY_URL (ai/client/openai.py:40, ai/gateway.py:352, ai/rag/embeddings.py:784, ai/pydantic_ai_bridge.py:84). Others are function defaults that callers override (QdrantClient(base_url=DEFAULT_QDRANT_URL), ai/rag/qdrant.py:147). The ignored-override bug exists only where a module uses such a default without reading the setting. The hard-coded http://localhost:11434 fallbacks are not three. 10 modules outside config/ spell it in code: ai/client/ollama.py:186, ai/client/unified.py:292-296, ai/review/runner.py:140-162, ai/review/pipeline.py:200-212, ai/rag/embeddings.py:489, ai/rag/indexer.py:581-582, ai/models/ollama.py:31, ai/benchmark/runner.py:160, ai/benchmark/embedding_runner.py:128 and ai/benchmark/suite.py:507. #950 (v0.2.25, in flight) deletes suite.py, #954 (v0.2.25, in flight) edits embedding_runner.py, and #995 deletes runner's copy. #956 (v0.2.25, in flight) edits how generated docs show defaults. The Constraint line's "(#776 is)" is stale: the AGENTS.md constants rule now belongs to ##1016, which keeps Settings-backed DEFAULT_* values in defaults.py.

Acceptance criteria

  • Each user-settable Settings field declares its environment variable name, its secret flag and its description once, in field metadata. config/options.py and the hand-written get_all_env_var_specs (config/env.py:222) are deleted, and OPTION_TO_ENV_VAR is derived.
  • config show, config set, config env and config audit-keys read the field metadata. The 29 _row() calls in commands/config.py are gone.
  • The resolution order is defined in one place. A table test covers one secret field and one plain field across keyring, Vault, environment, file and default.
  • The set of environment variable names does not change. A test compares the derived list with a snapshot taken at the start of the PR.
  • A field-backed DEFAULT_* is imported only inside config/. An import-boundary test lists the importers outside it and finds none. No code outside config/ falls back to a literal http://localhost:11434; each site above reads the field's default. A test greps src for the literal outside config/, docstrings and user messages, and finds none.
  • The PR names each site where an override was ignored at 38517a8, with a test per site that sets the override and asserts it is used. If there is none, the PR says so.
  • tests/test_config_env_overrides.py, tests/test_config_audit_keys.py and tests/test_config_cmd.py pass. Only the hand-written _row expectations change.
  • docs/ENV_VARS.md and docs/CONFIGURATION.md are regenerated and lose no variable.
  • The tests run offline, with no keyring daemon or Vault server.
  • uv run devops ci passes.
  • (person-run) devops config show and devops config env print the same keys and variables before and after on the devcontainer.

Key questions

Update 2026-10-08: refinement

The registry premise holds. The criterion that each localhost:11434 site reads 'the field's default' conflicts with #1165's rule that service URLs have no code default. Those literal sites (for example ai/client/ollama.py:183, ai/rag/indexer.py:395-397, ai/review/runner.py:150-172) and their guard belong to #1165. The constraint reads: DEFAULT_* values stay in defaults.py, except service URLs, which have none.

Proposed design

Problem statement

The configuration system has six hand-synchronized registries that describe each setting, leading to 10-12 edits across 6 files when adding a new option. The resolution order is scattered across 8 read paths, and there are dual-path overrides where config.yaml values can be ignored by feature modules. There's also a hard-coded fallback for Ollama URLs that should be removed.

Acceptance criteria

  • Criterion 1: Each user-settable Settings field declares its environment variable name, secret flag and description once in field metadata
    Verification: Verify that config/options.py and get_all_env_var_specs() are deleted and OPTION_TO_ENV_VAR is derived from model_fields
  • Criterion 2: config show, config set, config env and config audit-keys read the field metadata
    Verification: Ensure the 29 _row() calls in commands/config.py are gone and these commands use model_fields directly
  • Criterion 3: The resolution order is defined in one place with a table test covering keyring, Vault, environment, file and default precedence
    Verification: Run a test that validates the resolution order across all eight override mechanisms and confirms only one source handles precedence
  • Criterion 4: The set of environment variable names does not change from the current implementation
    Verification: Compare the derived list with a snapshot taken at the start of the PR to ensure no environment variables are lost or added
  • Criterion 5: A field-backed DEFAULT_* is imported only inside config/ and hard-coded localhost:11434 fallbacks are removed
    Verification: Run an import-boundary test that lists importers outside config/ and verify none fall back to literal 'http://localhost:11434'
  • Criterion 6: Each site where an override was ignored is reported with a test per site that sets the override and asserts it is used
    Verification: Run tests for each of the 10 sites that previously ignored overrides, ensuring they now properly use the override
  • Criterion 7: Existing tests continue to pass with only hand-written _row expectations changing
    Verification: Run test_config_env_overrides.py, test_config_audit_keys.py and test_config_cmd.py to confirm all existing functionality works
  • Criterion 8: docs/ENV_VARS.md and docs/CONFIGURATION.md are regenerated without losing any variables
    Verification: Verify that the generated documentation includes all environment variables and configuration options with correct metadata
  • Criterion 9: The tests run offline, with no keyring daemon or Vault server required
    Verification: Execute tests in an environment without keyring daemon or Vault server to ensure they function properly offline

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added
    type/refactor
    scope/config
    priority/p2-medium
    on Oct 2, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Consolidation (2026-10-03): #992 becomes a sub-issue of this item and lands first, as this item's key question proposes. It carries the library-first settings amendment (posted on #992 as an amendment):

    • validate_assignment=True and hide_input_in_errors=True on every section model, and hide_input_in_errors on Settings. Every value from the environment, config.yaml and config set then passes its field type: bool, number, URL and list.
    • Constraints on timeout-like fields (gt=0, finite).

    This item keeps the registry rework.

    Proposed criterion for this item, for a person to accept (medium confidence): extra='forbid' on Settings and every nested config model, with an error that names the unknown key. A test loads a stray key at the top level and inside a section. #1070's refusal for ai and ai.tasks is the first instance. The PR lists the keys this rejects, such as ai.lightllm_url.

    Declared fields that nothing reads stay with their own items:

    Related: #1022 (one helper that reads the config file; no settings error repeats a value).

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #1068 edits ai.tasks.metadata descriptions (config/env.py:377-392) this item turns into field views, and #1121 removes ai.durable (config/settings.py:413, :497), which extra='forbid' would reject. Found by the 2026-10-08 backlog review.

  4. added this to the v0.2.37 milestone on Oct 17, 2026
  5. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  6. modified the milestones: v0.2.37, v0.2.38 on Oct 19, 2026
  7. dan-petty commented on Oct 19, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 0ae4ea4 (see proposed design in issue body).

  8. removed this from the v0.2.38 milestone on Oct 20, 2026
  9. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    This item is larger than one pull request, so it becomes three sub-issues, each with its own change. Measured on origin/main 4226904 (2026-10-28):

    • Six registries describe the settings: config/options.py (100 keys, the secret set, the keyring map), config/env.py (84 variables, the option map, 79 hand-written specs), the credential table in security/secrets.py, the 29 _row lines of config show, the docs generator, and the fields of Settings. They already disagree: 7 options with a variable have no spec, so config env and docs/ENV_VARS.md do not show them.
    • load_settings builds Settings with model_validate, so pydantic-settings reads no source; _apply_env_overrides applies every variable.
    • 26 field-backed DEFAULT_* names are imported in 39 files outside config/.
    • The localhost:11434 criterion is done: fix(config): service clients use only configured urls and never fall back to an unconfigured localhost default #1165 removed the fallbacks, and the literals left are user messages, docstrings and one value that stack_lifecycle.py writes on purpose.

    Parts (sub-issues):

    1. refactor(config): each setting declares its variable and description on its settings field, and the option, variable and secret registries are derived from it #2444: one declaration on the fields, and the registries derived from it (built first).
    2. refactor(config): one source chain declares the resolution order of every setting, through pydantic-settings sources #2445: one resolution order through pydantic-settings sources, with the table test.
    3. refactor(config): a default that backs a settings field is read only through the settings, and an import-boundary test holds it #2447: the import boundary of field-backed defaults, with the report of ignored overrides.

    Decisions on the key questions:

  10. added
    status/ready
    value/medium
    effort/high
    on Oct 28, 2026
  11. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    All three parts of this item are merged:

  12. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/configtype/refactorvalue/medium

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions