The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(tokenjuice): disable compression switches when settings load fails\n\nWhen getTokenjuiceSettings() rejects on mount, settings stays null and\nall seven switches render as unchecked — indistinguishable from\n"compression is genuinely off". A user could click a switch and write a\nvalue against the incorrect displayed state.\n\nFix: pass disabled={settings === null} to all seven SettingsSwitch\ninstances and the SettingsNumberField. The existing SettingsStatusLine\nerror message already tells the user what went wrong; the disabled\ncontrols now match that error state rather than contradicting it.\n\nCloses #5899\n
shanu91aa5eef0d8d
diff --git a/app/src/components/settings/panels/TokenUsagePanel.tsx b/app/src/components/settings/panels/TokenUsagePanel.tsxindex f043107321..142e08c5cb 100644--- a/app/src/components/settings/panels/TokenUsagePanel.tsx+++ b/app/src/components/settings/panels/TokenUsagePanel.tsx@@ -214,6 +214,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-router-enabled"checked={settings?.router_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ router_enabled: v })}aria-label={t('settings.tokenUsage.routerEnabled')}/>@@ -226,6 +227,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-search-enabled"checked={settings?.search_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ search_enabled: v })}aria-label={t('settings.tokenUsage.search')}/>@@ -238,6 +240,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-code-enabled"checked={settings?.code_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ code_enabled: v })}aria-label={t('settings.tokenUsage.code')}/>@@ -250,6 +253,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-html-enabled"checked={settings?.html_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ html_enabled: v })}aria-label={t('settings.tokenUsage.html')}/>@@ -262,6 +266,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-ml-enabled"checked={settings?.ml_compression_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ ml_compression_enabled: v })}aria-label={t('settings.tokenUsage.ml')}/>@@ -282,6 +287,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-ccr-enabled"checked={settings?.ccr_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ ccr_enabled: v })}aria-label={t('settings.tokenUsage.ccrEnabled')}/>@@ -300,6 +306,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {min={0}max={1000000}unit={t('settings.tokenUsage.tokensUnit')}+ disabled={settings === null}aria-label={t('settings.tokenUsage.ccrMinTokens')}/>}@@ -311,6 +318,7 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {<SettingsSwitchid="tj-ccr-disk"checked={settings?.ccr_disk_enabled ?? false}+ disabled={settings === null}onCheckedChange={v => void patch({ ccr_disk_enabled: v })}aria-label={t('settings.tokenUsage.ccrDisk')}/>diff --git a/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx b/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsxnew file mode 100644index 0000000000..d9c5136ec0--- /dev/null+++ b/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx@@ -0,0 +1,138 @@+import { render, screen, waitFor } from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import * as tokenjuice from '../../../../utils/tauriCommands/tokenjuice';+import TokenUsagePanel from '../TokenUsagePanel';++vi.mock('../../../../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (k: string) => k }) }));++vi.mock('../../../../utils/tauriCommands/tokenjuice', async () => {+ const actual =+ await vi.importActual<typeof import('../../../../utils/tauriCommands/tokenjuice')>(+ '../../../../utils/tauriCommands/tokenjuice'+ );+ return {+ ...actual,+ getTokenjuiceSettings: vi.fn(),+ getTokenjuiceSavings: vi.fn(),+ updateTokenjuiceSettings: vi.fn(),+ resetTokenjuiceSavings: vi.fn(),+ };+});++const mockGetSettings = vi.mocked(tokenjuice.getTokenjuiceSettings);+const mockGetSavings = vi.mocked(tokenjuice.getTokenjuiceSavings);+const mockUpdate = vi.mocked(tokenjuice.updateTokenjuiceSettings);++const stubSettings: tokenjuice.TokenjuiceSettings = {+ router_enabled: true,+ ccr_enabled: false,+ ccr_disk_enabled: true,+ max_cache_entries: 100,+ max_cache_bytes: 1024,+ ccr_ttl_secs: null,+ min_bytes_to_compress: 512,+ ccr_min_tokens: 1000,+ search_enabled: true,+ code_enabled: false,+ html_enabled: true,+ ml_compression_enabled: false,+ ml_model_id: 'model',+ ml_target_ratio: 0.5,+ ml_sidecar_idle_timeout_secs: 30,+ ml_max_input_chars: 4096,+ ml_device: 'cpu',+};++const stubSavings: tokenjuice.SavingsStats = {+ attributionModel: 'gpt-4',+ total: { events: 0, originalTokens: 0, compactedTokens: 0, tokensSaved: 0, costSavedUsd: 0 },+ byModel: {},+ byCompressor: {},+ cache: { entries: 0, bytes: 0 },+};++describe('TokenUsagePanel', () => {+ beforeEach(() => {+ mockGetSettings.mockReset();+ mockGetSavings.mockReset();+ mockUpdate.mockReset();+ mockGetSavings.mockResolvedValue(stubSavings);+ });++ describe('when settings load succeeds', () => {+ beforeEach(() => {+ mockGetSettings.mockResolvedValue(stubSettings);+ });++ it('enables all switches once settings load', async () => {+ render(<TokenUsagePanel embedded />);++ // Wait for the async load to complete — all 7 switches must be enabled.+ await waitFor(() => {+ const switches = screen.getAllByRole('switch');+ expect(switches).toHaveLength(7);+ for (const sw of switches) expect(sw).not.toBeDisabled();+ });+ });++ it('reflects the loaded toggle values', async () => {+ render(<TokenUsagePanel embedded />);++ // router_enabled=true, search_enabled=true, code_enabled=false in stubSettings.+ await waitFor(() =>+ expect(+ screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' })+ ).toBeChecked()+ );+ expect(+ screen.getByRole('switch', { name: 'settings.tokenUsage.search' })+ ).toBeChecked();+ expect(+ screen.getByRole('switch', { name: 'settings.tokenUsage.code' })+ ).not.toBeChecked();+ });++ it('calls patch when a switch is toggled', async () => {+ const user = userEvent.setup();+ mockUpdate.mockResolvedValue({ ...stubSettings, router_enabled: false });+ render(<TokenUsagePanel embedded />);++ const sw = await screen.findByRole('switch', {+ name: 'settings.tokenUsage.routerEnabled',+ });+ await user.click(sw);+ expect(mockUpdate).toHaveBeenCalledWith({ router_enabled: false });+ });+ });++ describe('when settings load fails', () => {+ beforeEach(() => {+ mockGetSettings.mockRejectedValue(new Error('rpc down'));+ });++ it('disables all switches while settings are unavailable', async () => {+ render(<TokenUsagePanel embedded />);++ // After the rejection settles, settings stays null — every switch must be disabled.+ await waitFor(() => expect(mockGetSettings).toHaveBeenCalled());++ const switches = screen.getAllByRole('switch');+ expect(switches).toHaveLength(7);+ for (const sw of switches) expect(sw).toBeDisabled();+ });++ it('does not call patch when a disabled switch is clicked', async () => {+ const user = userEvent.setup();+ render(<TokenUsagePanel embedded />);++ await waitFor(() => expect(mockGetSettings).toHaveBeenCalled());++ const sw = screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' });+ expect(sw).toBeDisabled();+ await user.click(sw);+ expect(mockUpdate).not.toHaveBeenCalled();+ });+ });+});