Repository navigation
refactor(services): migrate magic numbers to Settings - #20
Closed
rsanghvi21 wants to merge 2 commits into
Closed
rsanghvi21 wants to merge 2 commits into
rsanghvi21 wants to merge 2 commits into
Conversation
Every tunable across services/ was read ad hoc via os.getenv(...)
with a hardcoded string default, scattered per-module -- no
services/ equivalent of src/understudy/common/config.py's layered
pydantic Settings pattern existed, violating AGENTS.md §5.10 ("no
magic numbers in code... thresholds, weights, timeouts and ceilings
live in config/*.yaml and are named in docs/02-architecture.md").
Add services/_common/settings.py mirroring config.py's shape (layered
load, frozen pydantic BaseModel per section, cached singleton with a
reset hook for tests) as an independent module -- services/ and
src/understudy/ share no imports, and src/understudy/common must stay
psycopg/fastapi-free, so it cannot host these tunables either.
One deliberate divergence: fields keep the exact env var name they
already used before this module existed (e.g.
AUTH_TOKEN_CACHE_MAX_SIZE, FAULT_INJECTION_SEED), rather than a new
UNDERSTUDY_<SECTION>__<FIELD> scheme -- those names are already wired
into deploy/prod/*.yaml's env/configMapKeyRef entries and loadgen's
CLI flag fallbacks, and renaming them would silently break
already-deployed configuration for no benefit.
Adds config/services.yaml (defaults) and config/services.local.yaml
to .gitignore (mirroring config/local.yaml) for local overrides.
Documents every field in docs/02-architecture.md §2.5.1.
This is infrastructure only: no call site reads from Settings yet
(follow-up PR). Implements build-plan step A1.8.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh
Replaces every ad hoc os.getenv(...)-with-hardcoded-default and bare numeric literal identified across services/ with a read from get_services_settings()/load_services_settings() (added in the prior PR): edge_gateway's HTTP_TIMEOUT_SECONDS, auth_service's TOKEN_CACHE_MAX_SIZE, worker's POLL_INTERVAL_SECONDS and its previously-unparameterized `LIMIT 50` job-list query (now bound via %s, matching the file's existing parameterized-query style), all of loadgen's LoadgenConfig defaults and its httpx.Limits/p99 SLA threshold, db.py's connection-pool defaults, faults.py's injection seed default and POOL_EXHAUSTION getconn timeout, and metrics.py's histogram buckets. loadgen reads via the fresh (uncached) load_services_settings() rather than the cached singleton, since both LoadgenConfig's defaults and main.py's argparse defaults are evaluated per CLI invocation / per-test-construction and must reflect an env var set right before that call, not whatever was cached first in the process. Every other service reads the cached get_services_settings() once at module-import time, matching how these values were already evaluated once via os.getenv(...) at import time before this change. Implements build-plan step A1.1/A1.2/A1.3/A1.8 (migration on already-completed services). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh
Harikeshav-R
added a commit
that referenced
this pull request
Sep 11, 2026
Owner
|
Closed as integrated into main via PR #6. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build-Plan Step Implemented
Checkpoint Execution & Output
Excluded above: two pre-existing Windows-local-only items (real
httpx.AsyncClient()construction crashes on this dev machine; not present on CI,
ubuntu-latest) --test_edge_gateway.pyandtest_run_loadgen_with_owned_client_and_zero_rps.ADRs Relied On
Mock Registry Disclosures
Documentation Updates
docs/02-architecture.md§2.5.1 by the prior PR (feat(services): add services-scoped layered Settings #19); this PR only moves call sitesto read from it.
Definition of Done
make checkgreen (see checkpoint output; two pre-existing Windows-local-only items excluded, unrelated)# MOCKED:marker without a row in docs/MOCKS.mdContext
Completes the fix started in #19 (
feat(services): add services-scoped layered Settings): that PR built theServicesSettingsinfrastructure but migrated no callsites, staying one logical change per AGENTS.md §4. This PR is the mechanical
migration -- every magic number/ad hoc
os.getenvidentified in the original/code-reviewfinding now reads fromget_services_settings()(or, forloadgen,the uncached
load_services_settings(), since its config is evaluated perCLI-invocation/per-construction rather than once at module import).
Base branch is
refactor/shared-service-bootstrap(PR #15), since this PR'sworker/app.pyand other service files build on that PR'screate_service_app/db_pool_lifespanrefactor (which itself is stacked on #13'sworker_loopfix) --rebasing onto
feat/policies-and-loadgendirectly would conflict.feat/services-settings(#19)'s commit is cherry-picked onto this branch so the Settings infrastructure is
available; once #19 and #15 merge, this PR's diff will narrow to just this PR's
changes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh