Sangeetha-Grantha

Metadata Value
Status Completed
Version 1.1.0
Last Updated 2026-07-19
Author Sangeetha Grantha Team

TRACK-131: Worker Config → pydantic-settings + Reproducible Docker Build

Goal: Replace the hand-rolled env parsing in src/config.py with pydantic-settings (typed, validated, self-documenting — and consistent with the worker’s “Pydantic at every boundary” paradigm), resolve the advertised-but-unused concurrency knobs, and make the Docker build reproducible by actually using uv.lock.

Origin: Python best-practices evaluation, 2026-07-19 (items 3 and 6).

Definition of Done

Config

Packaging & hygiene

Inputs

Out of Scope

Steps

  1. Add pydantic-settings to dependencies; port ExtractorConfig field-for-field with identical env names/defaults; add range validators.
  2. Fix extractor_version to instantiation-time; keep the krithi-extract-enrich-worker: prefix format.
  3. Delete (or implement) the concurrency knobs per the decision above; update worker docstring and compose env docs.
  4. Replace the conn auto-reconnect property with explicit ensure_connected(); update call sites.
  5. Rewrite the Dockerfile install stage around uv sync --frozen; verify HEALTHCHECK and entrypoint.
  6. Gitignore cache/; sync the skill doc’s Python version; strip __future__/Optional legacy imports.
  7. Update current-versions.md (new dependency) per version-sync rule.

Deliverables

Verification

Outcome (2026-07-19)

Provenance

The implementation was authored in an earlier session and sat uncommitted in the working tree while this track still read Not Started. It was reviewed rather than rewritten; the four defects below were found in review and three were fixed before commit.

DoD, verified functionally (not by inspection)

Item Evidence
BaseSettings port, same env names/defaults 292 unit + 18 integration pass unchanged
Malformed value fails naming the variable SG_IDENTITY_MIN_SCORE=abcValidationError ... SG_IDENTITY_MIN_SCORE
Range constraints SG_IDENTITY_MIN_SCORE=999 → “less than or equal to 100”
extractor_version at instantiation computed_field over EXTRACTOR_VERSION; container reports krithi-extract-enrich-worker:1.0.0
Concurrency knobs deleted (option b) zero refs in src/ or compose.yaml; worker docstring updated
ensure_connected() explicit, logs on reconnect, called by every public DB method
Dockerfile from lockfile uv sync --frozen --no-dev; image builds; src.worker + health_check import inside it
cache/ ignored git check-ignore exits 0
Skill doc Python version 3.11+3.14+

Review findings

Three fixed before commit:

  1. mypy was failingconfig.py carried # type: ignore[misc] on the computed_field; mypy wanted the narrower [prop-decorator]. This broke the CI gate TRACK-126 had just added. Fixed.
  2. Immutability regression — the previous ExtractorConfig was @dataclass(frozen=True); BaseSettings is mutable by default, so config.database_url = ... silently succeeded at runtime. Restored via SettingsConfigDict(frozen=True), confirmed by an explicit mutation attempt.
  3. Unpinned build toolingCOPY --from=ghcr.io/astral-sh/uv:latest directly undermined this track’s reproducible-build goal. Pinned to uv:0.11.25; image rebuilt and re-verified.

One flagged, not changed — needs a call:

  1. env_file=".env" adds a configuration source the DoD did not ask for (“same env var names, same defaults”). No .env exists in the worker directory today, so nothing is currently affected, and real environment variables still take precedence over the file. But this repo does use .env files elsewhere, so a future stray file would change worker config without any code change. Left in place with an explanatory comment in config.py; remove it if config should read the environment only.

Notes

Verification

ruff check 0, ruff format --check clean (55 files), mypy 0, pytest 292 unit + 18 integration passing, docker build succeeds with the pinned uv image and the entrypoint imports inside it.