diff --git a/backend/internal/server/api_contract_test.go b/backend/internal/server/api_contract_test.go index 243e8b241..f76d55ee4 100644 --- a/backend/internal/server/api_contract_test.go +++ b/backend/internal/server/api_contract_test.go @@ -977,7 +977,7 @@ func TestAPIContracts(t *testing.T) { "account_quota_notify_emails": [], "channel_monitor_enabled": true, "channel_monitor_mode": "v2", - "channel_monitor_hide_throughput": false, + "channel_monitor_hide_throughput": true, "channel_monitor_default_interval_seconds": 60, "available_channels_enabled": false, "model_plaza_enabled": false, @@ -1282,7 +1282,7 @@ func TestAPIContracts(t *testing.T) { "account_quota_notify_emails": [], "channel_monitor_enabled": true, "channel_monitor_mode": "v2", - "channel_monitor_hide_throughput": false, + "channel_monitor_hide_throughput": true, "channel_monitor_default_interval_seconds": 60, "available_channels_enabled": false, "model_plaza_enabled": false, diff --git a/backend/internal/service/setting_public.go b/backend/internal/service/setting_public.go index f3c86a884..a42c33def 100644 --- a/backend/internal/service/setting_public.go +++ b/backend/internal/service/setting_public.go @@ -352,7 +352,7 @@ func (s *SettingService) GetPublicSettings(ctx context.Context) (*PublicSettings ChannelMonitorEnabled: !isFalseSettingValue(settings[SettingKeyChannelMonitorEnabled]), ChannelMonitorMode: normalizeChannelMonitorMode(settings[SettingKeyChannelMonitorMode]), ChannelMonitorDefaultIntervalSeconds: parseChannelMonitorInterval(settings[SettingKeyChannelMonitorDefaultIntervalSeconds]), - ChannelMonitorHideThroughput: settings[SettingKeyChannelMonitorHideThroughput] == "true", + ChannelMonitorHideThroughput: !isFalseSettingValue(settings[SettingKeyChannelMonitorHideThroughput]), AvailableChannelsEnabled: settings[SettingKeyAvailableChannelsEnabled] == "true", @@ -461,7 +461,7 @@ func (s *SettingService) GetChannelMonitorRuntime(ctx context.Context) ChannelMo Enabled: !isFalseSettingValue(vals[SettingKeyChannelMonitorEnabled]), Mode: normalizeChannelMonitorMode(vals[SettingKeyChannelMonitorMode]), DefaultIntervalSeconds: parseChannelMonitorInterval(vals[SettingKeyChannelMonitorDefaultIntervalSeconds]), - HideThroughput: vals[SettingKeyChannelMonitorHideThroughput] != "false", + HideThroughput: !isFalseSettingValue(vals[SettingKeyChannelMonitorHideThroughput]), } } diff --git a/backend/internal/service/setting_service_public_test.go b/backend/internal/service/setting_service_public_test.go index 1b63d412f..67bab243c 100644 --- a/backend/internal/service/setting_service_public_test.go +++ b/backend/internal/service/setting_service_public_test.go @@ -101,6 +101,21 @@ func TestSettingService_GetPublicSettings_ExposesCompactHomeEnabled(t *testing.T require.False(t, missingSettings.CompactHomeEnabled) } +func TestSettingService_ChannelMonitorHideThroughputDefaultsToPrivate(t *testing.T) { + missing := NewSettingService(&settingPublicRepoStub{values: map[string]string{}}, &config.Config{}).GetChannelMonitorRuntime(context.Background()) + require.True(t, missing.HideThroughput) + public, err := NewSettingService(&settingPublicRepoStub{values: map[string]string{}}, &config.Config{}).GetPublicSettings(context.Background()) + require.NoError(t, err) + require.True(t, public.ChannelMonitorHideThroughput) + + for _, value := range []string{"false", "0", "off", "disabled"} { + runtime := NewSettingService(&settingPublicRepoStub{values: map[string]string{ + SettingKeyChannelMonitorHideThroughput: value, + }}, &config.Config{}).GetChannelMonitorRuntime(context.Background()) + require.False(t, runtime.HideThroughput, "value=%q", value) + } +} + func TestSettingService_GetPublicSettings_ExposesForceEmailOnThirdPartySignup(t *testing.T) { repo := &settingPublicRepoStub{ values: map[string]string{ diff --git a/backend/migrations/203_channel_monitor_v2_default_ignore_and_cache.sql b/backend/migrations/203_channel_monitor_v2_default_ignore_and_cache.sql index 48a80d5d3..4a03f0054 100644 --- a/backend/migrations/203_channel_monitor_v2_default_ignore_and_cache.sql +++ b/backend/migrations/203_channel_monitor_v2_default_ignore_and_cache.sql @@ -1,9 +1,7 @@ -- Factory presets for Channel Monitor V2 config: -- 1) ignored_error_categories: non-ops client/policy failures that should not -- dominate health error_rate by default (still shown greyed in breakdown). --- 2) health_thresholds cache floors are intentionally left at the tolerant --- zero/zero defaults from migration 198. Platforms without prompt caching --- must not be marked unhealthy by factory configuration. +-- 2) health_thresholds cache floors: 85% watch / 60% critical (higher is better). -- -- Only apply when the row still looks like factory empty ignore list and/or -- zero cache thresholds (operator customizations are left alone). @@ -21,3 +19,13 @@ SET ignored_error_categories = ARRAY[ ]::text[] WHERE id = 1 AND COALESCE(cardinality(ignored_error_categories), 0) = 0; + +UPDATE channel_monitor_v2_config +SET health_thresholds = health_thresholds + || jsonb_build_object( + 'warning_cache_rate', 0.85, + 'critical_cache_rate', 0.60 + ) +WHERE id = 1 + AND COALESCE((health_thresholds->>'warning_cache_rate')::float8, 0) = 0 + AND COALESCE((health_thresholds->>'critical_cache_rate')::float8, 0) = 0; diff --git a/backend/migrations/204_channel_monitor_hide_throughput.sql b/backend/migrations/204_channel_monitor_hide_throughput.sql index 1c706bb2a..194eb7ce6 100644 --- a/backend/migrations/204_channel_monitor_hide_throughput.sql +++ b/backend/migrations/204_channel_monitor_hide_throughput.sql @@ -1,5 +1,5 @@ -- Soft switch: hide RPM/TPM throughput rates on user-facing Channel Monitor V2. --- Default true (rates hidden). Admins always see full metrics. +-- Default false (rates visible). Admins always see full metrics. INSERT INTO settings (key, value) -VALUES ('channel_monitor_hide_throughput', 'true') +VALUES ('channel_monitor_hide_throughput', 'false') ON CONFLICT (key) DO NOTHING; diff --git a/backend/migrations/206_channel_monitor_v2_privacy_defaults.sql b/backend/migrations/206_channel_monitor_v2_privacy_defaults.sql new file mode 100644 index 000000000..278e90b49 --- /dev/null +++ b/backend/migrations/206_channel_monitor_v2_privacy_defaults.sql @@ -0,0 +1,8 @@ +-- Correct factory defaults introduced by migrations 203 and 204 without +-- mutating those already-applied migration files (which are checksum-locked). +-- The setting was factory-created as false by migration 204. Existing +-- installations need the same privacy-preserving default as new installs. +UPDATE settings +SET value = 'true', updated_at = NOW() +WHERE key = 'channel_monitor_hide_throughput' + AND LOWER(TRIM(value)) IN ('false', '0', 'off', 'disabled');