Skip to content

fix(app): restore saved model & permission picks in new session#1391

Open
jlixfeld wants to merge 1 commit into
slopus:mainfrom
jlixfeld:fix/new-session-restore-model-permission
Open

fix(app): restore saved model & permission picks in new session#1391
jlixfeld wants to merge 1 commit into
slopus:mainfrom
jlixfeld:fix/new-session-restore-model-permission

Conversation

@jlixfeld

Copy link
Copy Markdown

Problem

The new-session screen persists the user's model and permission picks to the draft (MMKV) — useNewSessionDraft even documents that it restores them — but it never reads them back. The mount effect always reseeds the picker indices from the agent defaults, so a selection silently resets to the default on every remount. This is most visible on iOS, where navigation remounts the screen, so users report "iOS doesn't save model settings." Machine / path / agent restore correctly; model and permission don't.

Root cause

new/index.tsx reset effect:

const defaultModelIdx = modelModes.findIndex(m => m.key === effectiveAgentDefaults.modelMode);
setModelIndex(defaultModelIdx >= 0 ? defaultModelIdx : 0);

draft.modelMode / draft.permissionMode are written on pick but never consulted here. The draft's initial 'default' value also collides with the literal 'default' model/permission key, so "never picked" couldn't be told apart from an explicit "default" pick.

Fix

  • Make the draft's modelMode / permissionMode nullable (null = unset), so an explicit "default" pick is distinct from never having picked.
  • Add a pure, tested resolveModeIndex(modes, draftKey, fallbackKey) helper: prefer the saved pick when still available for the current agent, else the agent default, else index 0.
  • Use it in the reset effect (model + permission), with the draft values added to the dependency list.

Selecting a different agent still falls back to that agent's default (a pick from another agent won't be in its mode list). Setting a global default in Settings → Agent Defaults still applies for users who never picked in the new-session screen.

Tests

resolveModeIndex.test.ts covers: restore saved pick, explicit-default vs unset, fallback to agent default, cross-agent fallback, and the index-0 floor. Full suite green; pnpm typecheck clean.

🤖 Generated with Claude Code

The new-session screen persisted the user's model and permission picks to
the draft (MMKV) but never read them back: the mount effect always reseeded
the picker indices from the agent defaults, so a selection silently reset to
the default on every remount (most visible on iOS, where navigation remounts
the screen). Machine/path/agent restored fine; model and permission did not.

Distinguish "never picked" from an explicit "default" pick by making the
draft's modelMode/permissionMode nullable (null = unset). Add a pure
resolveModeIndex helper that prefers the saved pick when still available for
the current agent, else the agent default, else index 0, and use it in the
reset effect. Covered by resolveModeIndex.test.ts.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
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.

1 participant