Skip to content

Wire up six dead config settings - #542

Open
amirfz wants to merge 1 commit into
mainfrom
fix/wire-dead-config-settings
Open

Wire up six dead config settings#542
amirfz wants to merge 1 commit into
mainfrom
fix/wire-dead-config-settings

Conversation

@amirfz

@amirfz amirfz commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #517. Six settings in sherpa_ai/config/__init__.py were defined and documented but never read anywhere.

  • MODEL_PRICING_CONFIG_PATHPricingManager.__init__ now falls back to it when no explicit config_path is given.
  • ENABLE_COST_TRACKINGUsageLogger.log_usage now gates cost accumulation and threshold alerting behind it, so it can actually be turned off (usage-file logging is unaffected).
  • FILE_SIZE_LIMIT — enforced in QuestionWithFileHandler.download_file right after the response comes back, alongside the existing FILE_TOKEN_LIMIT check.
  • DAILY_LIMIT_REACHED_MESSAGE — returned from UserUsageTracker.check_usage when the daily limit is hit, instead of a hardcoded string.
  • AWS_ACCESS_KEY / AWS_SECRET_KEY — deleted per the issue's suggestion. backup.py's boto3.client("s3") never read them; boto3 uses its own standard credential chain, and these names weren't even the standard ones boto3 looks for.

A bigger bug found along the way

Wiring DAILY_LIMIT_REACHED_MESSAGE surfaced something worse: UserUsageTracker had two check_usage method definitions. Python silently uses the second (later) one everywhere — the first, richer implementation (with message, whitelist handling, time_left) was completely unreachable dead code, even though it matches the class's own documented example in database/__init__.py. The live (second) definition dropped all of that.

Removed the dead duplicate and kept the richer implementation, but had to reconcile a real semantic disagreement between the two: they computed token-left differently (remaining before vs after the pending request). Kept the "before" semantics since that's what the existing integration test already asserted.

Verification

Each of the 5 fixes has a dedicated test. Each was verified by mutating the fix back out and confirming the corresponding test fails, then reverting:

  • MODEL_PRICING_CONFIG_PATH fallback removed → test_config_path_falls_back_to_env_setting fails
  • ENABLE_COST_TRACKING gate removed → test_disabled_cost_tracking_suppresses_alerts fails
  • FILE_SIZE_LIMIT check removed → test_download_file_rejects_oversized_file fails
  • DAILY_LIMIT_REACHED_MESSAGE reverted to hardcoded string → test_check_usage_limits_remaining_tokens's new assertion fails

Test plan

  • Full suite — 388 passed, 2 skipped
  • 4 mutation tests, one per fix, each caught and reverted
  • CI on this PR

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

Six settings in sherpa_ai/config/__init__.py were defined and
documented but never read anywhere:

- MODEL_PRICING_CONFIG_PATH: PricingManager.__init__ now falls back to
  it when no explicit config_path is given.
- ENABLE_COST_TRACKING: UsageLogger.log_usage now gates cost
  accumulation and threshold alerting behind it, so it can actually be
  turned off (usage-file logging is unaffected).
- FILE_SIZE_LIMIT: enforced in QuestionWithFileHandler.download_file
  right after the response comes back, alongside the existing
  FILE_TOKEN_LIMIT check.
- DAILY_LIMIT_REACHED_MESSAGE: returned from UserUsageTracker.check_usage
  when the daily limit is hit, instead of a hardcoded string.
- AWS_ACCESS_KEY / AWS_SECRET_KEY: deleted. backup.py's boto3.client("s3")
  never read them (boto3 uses its own standard credential chain via
  AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, ~/.aws/credentials, or IAM
  role), and the names weren't even boto3's standard ones, so they did
  nothing under either interpretation.

Wiring DAILY_LIMIT_REACHED_MESSAGE surfaced a bigger issue: two
check_usage methods were defined on UserUsageTracker, and Python
silently used the second (later) one everywhere. That second
definition dropped the message/whitelist/time_left fields entirely,
contradicting the class's own documented example in database/__init__.py.
Removed the dead duplicate and kept the richer implementation, adjusting
its token-left calculation to match the "remaining before this request"
semantics the existing integration test already relied on (the two
definitions disagreed on this).

Each fix has a dedicated test, and each was verified by mutating the
fix back out and confirming the corresponding test fails, then
reverting. Full suite: 388 passed, 2 skipped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@amirfz
amirfz force-pushed the fix/wire-dead-config-settings branch from ea8fb0a to 23e2186 Compare August 1, 2026 15:09
"""Initialize the pricing manager."""
self.pricing_data = {}
self._load_pricing_config(config_path)
self._load_pricing_config(config_path or cfg.MODEL_PRICING_CONFIG_PATH)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this env var? MODEL_PRICING_CONFIG_PATH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Six config settings are defined but never read

2 participants