Skip to content

The agent that grows with you

fix(desktop): scope approval-mode reads/writes to the viewed profile (#125969)

PRATHAMESH75ef6039cc7705
diff --git a/apps/desktop/src/store/approval-mode.test.ts b/apps/desktop/src/store/approval-mode.test.ts
index 3ec7a6daede..204bc898765 100644
--- a/apps/desktop/src/store/approval-mode.test.ts
+++ b/apps/desktop/src/store/approval-mode.test.ts
@@ -19,10 +19,34 @@ describe('profile-scoped approval mode cache', () => {
const request = vi.fn(async () => ({ value: 'manual' }))
await syncApprovalModeForProfile(request, 'default')
- expect(request).toHaveBeenCalledWith('config.get', { key: 'approvals.mode' })
+ expect(request).toHaveBeenCalledWith('config.get', { key: 'approvals.mode', profile: 'default' })
expect(approvalModeForProfile('default')).toBe('manual')
})
+ it('scopes reads and writes to the named profile so a non-launch profile is not misrouted', async () => {
+ const readWork = vi.fn(async () => ({ value: 'off' }))
+ await syncApprovalModeForProfile(readWork, 'work')
+ expect(readWork).toHaveBeenCalledWith('config.get', { key: 'approvals.mode', profile: 'work' })
+
+ const writeWork = vi.fn(async () => ({ value: 'manual' }))
+ await setApprovalModeForProfile(writeWork, 'work', 'manual')
+ expect(writeWork).toHaveBeenCalledWith('config.set', {
+ key: 'approvals.mode',
+ value: 'manual',
+ profile: 'work'
+ })
+ })
+
+ it('omits the profile param for a blank profile so the backend keeps its launch scope', async () => {
+ const request = vi.fn(async () => ({ value: 'smart' }))
+ await syncApprovalModeForProfile(request, ' ')
+ expect(request).toHaveBeenCalledWith('config.get', { key: 'approvals.mode' })
+
+ const write = vi.fn(async () => ({ value: 'off' }))
+ await setApprovalModeForProfile(write, '', 'off')
+ expect(write).toHaveBeenCalledWith('config.set', { key: 'approvals.mode', value: 'off' })
+ })
+
it('keeps profile values isolated', async () => {
await syncApprovalModeForProfile(
vi.fn(async () => ({ value: 'manual' })),
diff --git a/apps/desktop/src/store/approval-mode.ts b/apps/desktop/src/store/approval-mode.ts
index f8720aa1acd..abf9c744c26 100644
--- a/apps/desktop/src/store/approval-mode.ts
+++ b/apps/desktop/src/store/approval-mode.ts
@@ -13,6 +13,18 @@ function profileKey(profile: string): string {
return profile.trim() || 'default'
}
+// The gateway's `config.get` / `config.set` are `@_profile_scoped`: a request with no `profile`
+// param resolves to the profile the backend was *launched* with. So an unscoped read/write targets
+// the launch profile no matter which profile the menu is showing — the UI ends up displaying one
+// profile's mode for all of them and a write silently edits the launch profile (#125969). Name the
+// profile the call is for; a blank name IS the launch profile, so omit the param (keeping the
+// backend's os.environ / session precedence) — the same rule `api/client.ts`'s `profileScoped()` uses.
+function scopeToProfile(profile: string, params: Record<string, unknown>): Record<string, unknown> {
+ const name = profile.trim()
+
+ return name ? { ...params, profile: name } : params
+}
+
function nextRevision(profile: string): number {
const revision = (revisions.get(profile) ?? 0) + 1
revisions.set(profile, revision)
@@ -53,7 +65,10 @@ export async function syncApprovalModeForProfile(
): Promise<ApprovalMode> {
const key = profileKey(profile)
const revision = nextRevision(key)
- const result = (await requestGateway('config.get', { key: 'approvals.mode' })) as { value?: string }
+ const result = (await requestGateway(
+ 'config.get',
+ scopeToProfile(profile, { key: 'approvals.mode' })
+ )) as { value?: string }
const mode = normalizeApprovalMode(result?.value)
if (revisions.get(key) === revision) {
@@ -74,10 +89,10 @@ export async function setApprovalModeForProfile(
cacheApprovalMode(key, mode)
try {
- const result = (await requestGateway('config.set', {
- key: 'approvals.mode',
- value: mode
- })) as { value?: string }
+ const result = (await requestGateway(
+ 'config.set',
+ scopeToProfile(profile, { key: 'approvals.mode', value: mode })
+ )) as { value?: string }
const authoritative = normalizeApprovalMode(result?.value)