Skip to content

config: demote magic-constant keys to module-local constants (closes #442)#467

Merged
lonix merged 2 commits into
mainfrom
claude/demote-magic-constants
May 26, 2026
Merged

config: demote magic-constant keys to module-local constants (closes #442)#467
lonix merged 2 commits into
mainfrom
claude/demote-magic-constants

Conversation

@lonix
Copy link
Copy Markdown
Owner

@lonix lonix commented May 26, 2026

Closes #442.

Demoted

Three config keys existed because the original code reached for getNumber() instead of declaring a constant — not because operators ever tuned them. Each surfaced in the Settings UI, demanded label/description/type metadata, and added noise to the operator surface for zero practical benefit.

Config key (was) Module-local const (now)
quotes.cleanup_interval quote-channel-manager.tsCLEANUP_INTERVAL_MINUTES = 5
notices.cleanup_interval notices-channel-manager.tsCLEANUP_INTERVAL_MINUTES = 5
voicechannels.ownership.grace_period_seconds voice-channel-manager.tsOWNERSHIP_TRANSFER_GRACE_SECONDS = 30

Each const carries a short comment explaining why the value lives in the module and not the schema, citing #442 so the demotion is self-documenting.

Kept

  • quotes.max_length — operators genuinely have preferences about quote length (some communities want short pithy quotes, some allow longer). Not a magic constant.

How removal works

ConfigService.cleanupUnknownSettings() already runs on startup and deletes orphan DB rows for any key not in defaultConfig. Removing the three keys from the schema means existing deployments shed the rows on next start. No extra migration code.

Verification

  • npm test — 744 passed, 1 skipped, 0 failed.
  • npx tsc --noEmit — clean.
  • npm run lint — 0 errors.
  • npm run format:check — clean.
  • grep -rn '<key>' src returns only the demotion-history comments for each removed key.
  • Manual on a deployment that had these rows: on next start, expect log 🧹 Found 3 unknown/old settings in database, removing them... listing the three demoted keys.

Test plan

  • Existing tests still pass; the channel-cleanup loops use the new constants directly, behavior unchanged.
  • Manual: settings page no longer lists the three keys; quote/notices cleanup jobs still fire every 5 min; voice-channel ownership transfer still uses 30 s grace.

Generated by Claude Code

…442)

Three config keys existed because the original code reached for
getNumber() instead of declaring a constant — not because operators
ever tuned them. Each surfaced in the Settings UI, demanded label/
description/type metadata, and added noise to the operator surface
for zero practical benefit.

Demoted (config key → module-local const):

  quotes.cleanup_interval                 → quote-channel-manager.ts
                                            CLEANUP_INTERVAL_MINUTES = 5
  notices.cleanup_interval                → notices-channel-manager.ts
                                            CLEANUP_INTERVAL_MINUTES = 5
  voicechannels.ownership.grace_period_seconds
                                          → voice-channel-manager.ts
                                            OWNERSHIP_TRANSFER_GRACE_SECONDS = 30

Each module-local const carries a short comment explaining why the
value is here and not in the schema, citing #442 so the demotion is
self-documenting.

Kept: quotes.max_length. Operators genuinely have preferences about
quote length — some communities want short pithy quotes, some allow
longer. Not a magic constant.

Schema: removed the three keys from ConfigSchema, defaultConfig, and
settingsMetadata. ConfigService.cleanupUnknownSettings() already runs
on startup and deletes orphan DB rows for any key not in defaultConfig,
so existing deployments shed the rows on next start with no extra
migration code.

All 744 tests pass.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Demotes three never-tuned config keys to module-local constants to shrink the operator-facing settings surface area, leaving runtime behavior unchanged. Orphan DB rows for the removed keys are cleaned up automatically by the existing ConfigService.cleanupUnknownSettings() path on next startup.

Changes:

  • Remove voicechannels.ownership.grace_period_seconds, quotes.cleanup_interval, and notices.cleanup_interval from ConfigSchema, defaultConfig, and settingsMetadata.
  • Replace the corresponding configService.getNumber(...) lookups with module-local consts carrying a comment that cites #442 as the demotion rationale.
  • Update log messages and cron-expression assembly to read from the new constants.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/services/config-schema.ts Drops the three demoted keys from the schema interface, defaults map, and metadata table.
src/services/voice-channel-manager.ts Adds OWNERSHIP_TRANSFER_GRACE_SECONDS = 30 constant and replaces the previous config lookup in the ownership-handoff path.
src/services/quote-channel-manager.ts Adds CLEANUP_INTERVAL_MINUTES = 5 and uses it directly when building the cleanup cron expression and log message.
src/services/notices-channel-manager.ts Same demotion pattern as the quote manager for the notices cleanup loop.

@@ -37,7 +36,6 @@ export interface ConfigSchema {
"quotes.delete_roles": string; // Comma-separated role IDs
"quotes.max_length": number; // Maximum quote length
"quotes.cooldown": number; // Cooldown in seconds between quote additions
Copilot review caught that SETTINGS.md still documented the three keys
this PR demoted. Anyone consulting the doc would be told to configure
keys that no longer exist in defaultConfig — cleanupUnknownSettings()
silently deletes them on startup, and the YAML import path now rejects
them as "unknown key".

Removed from SETTINGS.md:

- The quotes settings table row and follow-up note for
  quotes.cleanup_interval.
- The notices settings table row for notices.cleanup_interval.
- The voicechannels.ownership.grace_period_seconds table row plus the
  entire "Ownership grace period" subsection with its "Recommended
  values" guidance.
- The four Quick-reference entries for the same three keys.

The constants now live in the relevant service modules; tuning them is
a code change, not a config change.
@lonix lonix merged commit 8d1f9aa into main May 26, 2026
9 checks passed
@lonix lonix deleted the claude/demote-magic-constants branch May 26, 2026 12:32
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.

Config: demote magic-constant config keys to module-local constants

3 participants