Repository navigation
feat: aggressive model loading (bigger models load, with Load-Anyway override) + no-model loading feedback #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d9decc
feat(memory): policy-aware memory budget (balanced | aggressive)
alichherawalla e591ee0
feat(residency): load policy + "Load Anyway" override in makeRoomFor
alichherawalla 6924587
feat(load): OverridableMemoryError + thread override through activeMo…
alichherawalla 59fd47a
feat(settings): aggressiveModelLoading setting + single projection to…
alichherawalla 6f0cd2f
feat(settings-ui): Aggressive Loading toggle in llama + LiteRT advanc…
alichherawalla 8a906ea
fix(chat): "Load Anyway" now overrides the residency gate, not just t…
alichherawalla d613ac6
fix(chat): show a loading indicator on the no-model screen while a mo…
alichherawalla 77f2745
docs: dead-code recon register (GAPS_BACKLOG)
alichherawalla 428e87e
chore(dead-code): remove verified-dead code (duplicate type + unwired…
alichherawalla a4ce701
fix(review): address Qodo findings on the aggressive-load PR
alichherawalla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /** | ||
| * NoModelScreen — the empty state shown before a model is active. | ||
| * | ||
| * Regression: selecting a model kicks off a background load, but activeModelId | ||
| * stays null until the native load finishes, so this screen stayed visible with | ||
| * NO feedback and the user thought nothing happened. It must show a loading | ||
| * indicator while isModelLoading is true instead of the "Select Model" prompt. | ||
| */ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react-native'; | ||
|
|
||
| jest.mock('../../../src/components', () => ({ | ||
| ModelSelectorModal: () => null, | ||
| })); | ||
| jest.mock('../../../src/services', () => ({ | ||
| llmService: { getLoadedModelPath: () => null }, | ||
| })); | ||
|
|
||
| import { NoModelScreen } from '../../../src/screens/ChatScreen/ChatScreenComponents'; | ||
| import { createStyles } from '../../../src/screens/ChatScreen/styles'; | ||
| import { getTheme } from '../../../src/theme'; | ||
|
|
||
| const theme = getTheme('light'); | ||
| const colors = theme.colors; | ||
| const styles = createStyles(colors, theme.shadows); | ||
|
|
||
| function renderScreen(overrides: Partial<React.ComponentProps<typeof NoModelScreen>> = {}) { | ||
| return render( | ||
| <NoModelScreen | ||
| styles={styles} | ||
| colors={colors} | ||
| navigation={{ goBack: jest.fn() }} | ||
| hasAvailableModels | ||
| showModelSelector={false} | ||
| setShowModelSelector={jest.fn()} | ||
| onSelectModel={jest.fn()} | ||
| onUnloadModel={jest.fn()} | ||
| isModelLoading={false} | ||
| {...overrides} | ||
| />, | ||
| ); | ||
| } | ||
|
|
||
| describe('NoModelScreen', () => { | ||
| it('shows the "Select Model" prompt when idle (not loading)', () => { | ||
| const { getByText, queryByTestId } = renderScreen({ isModelLoading: false }); | ||
| expect(getByText('No Model Selected')).toBeTruthy(); | ||
| expect(getByText('Select Model')).toBeTruthy(); | ||
| expect(queryByTestId('no-model-loading-indicator')).toBeNull(); | ||
| }); | ||
|
|
||
| it('shows a loading indicator (not the prompt) while a model loads in the background', () => { | ||
| const { getByText, getByTestId, queryByText } = renderScreen({ isModelLoading: true }); | ||
| expect(getByTestId('no-model-loading-indicator')).toBeTruthy(); | ||
| expect(getByText('Loading Model')).toBeTruthy(); | ||
| // The idle prompt + Select button must be hidden so the user isn't told to | ||
| // re-select a model that is already loading. | ||
| expect(queryByText('No Model Selected')).toBeNull(); | ||
| expect(queryByText('Select Model')).toBeNull(); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * loadPolicySync — the single projection of the persisted "aggressive model | ||
| * loading" setting onto the residency manager's runtime policy. | ||
| * | ||
| * Drives the REAL appStore and the REAL modelResidencyManager (the thing under | ||
| * test is not mocked) so a green test means the projection actually works end to | ||
| * end: flip the setting → the manager's policy changes. | ||
| */ | ||
| import { loadPolicyFromSettings, startLoadPolicySync } from '../../../src/services/loadPolicySync'; | ||
| import { modelResidencyManager } from '../../../src/services/modelResidency'; | ||
| import { useAppStore } from '../../../src/stores'; | ||
|
|
||
| describe('loadPolicyFromSettings (the one boolean→policy mapping)', () => { | ||
| it('maps the flag to a policy', () => { | ||
| expect(loadPolicyFromSettings({ aggressiveModelLoading: true })).toBe('aggressive'); | ||
| expect(loadPolicyFromSettings({ aggressiveModelLoading: false })).toBe('balanced'); | ||
| expect(loadPolicyFromSettings({})).toBe('balanced'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('startLoadPolicySync', () => { | ||
| let unsubscribe: (() => void) | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: false }); | ||
| modelResidencyManager.setLoadPolicy('balanced'); | ||
| }); | ||
| afterEach(() => { | ||
| unsubscribe?.(); | ||
| unsubscribe = undefined; | ||
| modelResidencyManager.setLoadPolicy('balanced'); | ||
| }); | ||
|
|
||
| it('seeds the manager from the current (hydrated) setting on start', () => { | ||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: true }); | ||
| modelResidencyManager.setLoadPolicy('balanced'); // simulate a fresh manager | ||
| unsubscribe = startLoadPolicySync(); | ||
| expect(modelResidencyManager.getLoadPolicy()).toBe('aggressive'); | ||
| }); | ||
|
|
||
| it('projects a later toggle onto the manager (View dispatches intent, service owns state)', () => { | ||
| unsubscribe = startLoadPolicySync(); | ||
| expect(modelResidencyManager.getLoadPolicy()).toBe('balanced'); | ||
|
|
||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: true }); | ||
| expect(modelResidencyManager.getLoadPolicy()).toBe('aggressive'); | ||
|
|
||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: false }); | ||
| expect(modelResidencyManager.getLoadPolicy()).toBe('balanced'); | ||
| }); | ||
|
|
||
| it('stops projecting after unsubscribe', () => { | ||
| unsubscribe = startLoadPolicySync(); | ||
| unsubscribe(); | ||
| unsubscribe = undefined; | ||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: true }); | ||
| // No longer synced → manager keeps its last value. | ||
| expect(modelResidencyManager.getLoadPolicy()).toBe('balanced'); | ||
| }); | ||
|
|
||
| it('is a singleton — calling twice does NOT stack subscriptions (leak guard)', () => { | ||
| const first = startLoadPolicySync(); | ||
| const second = startLoadPolicySync(); | ||
| expect(second).toBe(first); // same live unsubscribe returned, not a new subscription | ||
| unsubscribe = first; | ||
|
|
||
| const spy = jest.spyOn(modelResidencyManager, 'setLoadPolicy'); | ||
| // One flag flip → setLoadPolicy fires exactly once, not once-per-start. | ||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: true }); | ||
| expect(spy).toHaveBeenCalledTimes(1); | ||
| spy.mockRestore(); | ||
| }); | ||
|
|
||
| it('does not fire setLoadPolicy for unrelated setting changes (only on flag flip)', () => { | ||
| unsubscribe = startLoadPolicySync(); | ||
| const spy = jest.spyOn(modelResidencyManager, 'setLoadPolicy'); | ||
| // Change an unrelated setting several times. | ||
| useAppStore.getState().updateSettings({ temperature: 0.5 }); | ||
| useAppStore.getState().updateSettings({ maxTokens: 2048 }); | ||
| expect(spy).not.toHaveBeenCalled(); | ||
| // Flipping the flag DOES fire it. | ||
| useAppStore.getState().updateSettings({ aggressiveModelLoading: true }); | ||
| expect(spy).toHaveBeenCalledWith('aggressive'); | ||
| spy.mockRestore(); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { OverridableMemoryError, isOverridableMemoryError } from '../../../src/services/modelLoadErrors'; | ||
|
|
||
| describe('OverridableMemoryError', () => { | ||
| it('is a real Error subclass carrying the overridable discriminant', () => { | ||
| const err = new OverridableMemoryError('no room'); | ||
| expect(err).toBeInstanceOf(Error); | ||
| expect(err).toBeInstanceOf(OverridableMemoryError); | ||
| expect(err.message).toBe('no room'); | ||
| expect(err.name).toBe('OverridableMemoryError'); | ||
| expect(err.overridable).toBe(true); | ||
| }); | ||
|
|
||
| it('isOverridableMemoryError recognises the class', () => { | ||
| expect(isOverridableMemoryError(new OverridableMemoryError('x'))).toBe(true); | ||
| }); | ||
|
|
||
| it('isOverridableMemoryError recognises a duck-typed object (survives async/serialisation boundaries)', () => { | ||
| expect(isOverridableMemoryError({ overridable: true, message: 'x' })).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects plain errors and non-errors', () => { | ||
| expect(isOverridableMemoryError(new Error('generic'))).toBe(false); | ||
| expect(isOverridableMemoryError('memory')).toBe(false); | ||
| expect(isOverridableMemoryError(null)).toBe(false); | ||
| expect(isOverridableMemoryError(undefined)).toBe(false); | ||
| expect(isOverridableMemoryError({ overridable: false })).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.