The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
Revoke unknown Remote snapshots on frontend recovery
Davidbacf92523d40
diff --git a/e2e/remote-memory-proof.ts b/e2e/remote-memory-proof.tsindex ccde9845..6bc2dc85 100644--- a/e2e/remote-memory-proof.ts+++ b/e2e/remote-memory-proof.ts@@ -3,11 +3,16 @@ import { createRoot } from 'react-dom/client'import { MemorySettings } from '../src/components/settings/MemorySettings'import { useMemoryStore, __setMemoryEmbedFn } from '../src/stores/memoryStore'import { useRemoteStore } from '../src/stores/remoteStore'+import { useRemoteRecovery } from '../src/hooks/useRemoteRecovery'import '../src/index.css'await useMemoryStore.persist.rehydrate()__setMemoryEmbedFn(async () => [])-createRoot(document.getElementById('root')!).render(createElement(MemorySettings))+function RemoteRecoveryProof() {+ useRemoteRecovery()+ return createElement(MemorySettings)+}+createRoot(document.getElementById('root')!).render(createElement(RemoteRecoveryProof))useRemoteStore.subscribe(state => {document.getElementById('remote-state')!.textContent = JSON.stringify({ enabled: state.enabled, qrVisible: state.qrVisible })})diff --git a/e2e/remote-memory.spec.ts b/e2e/remote-memory.spec.tsindex a870fa6e..379bb1f0 100644--- a/e2e/remote-memory.spec.ts+++ b/e2e/remote-memory.spec.ts@@ -1,5 +1,34 @@import { expect, test } from '@playwright/test'+test('reload revokes a native session that outlived the frontend', async ({ page }) => {+ // This mock lives outside the page, so a real reload discards Zustand but+ // intentionally retains the native-side session state and invocation log.+ let running = false+ const calls: string[] = []+ await page.exposeFunction('remoteNativeProof', async (command: string) => {+ calls.push(command)+ const status = { running, port: 11435, passcode: 'fixture', passcodeExpiresAt: 1, lanUrl: '', mobileUrl: '' }+ if (command === 'start_remote_server') { running = true; return status }+ if (command === 'remote_server_status') return status+ if (command === 'revoke_remote_memory') return null+ if (command === 'remote_qr_code') return { qr_png_base64: '', url: '', passcode: '' }+ throw new Error('Unsupported proof command')+ })+ await page.addInitScript(() => {+ Object.defineProperty(window, '__TAURI_INTERNALS__', { value: {+ invoke: (command: string) => (window as unknown as { remoteNativeProof: (name: string) => Promise<unknown> }).remoteNativeProof(command),+ } })+ })+ await page.goto('/e2e/remote-memory-proof.html')+ await page.getByRole('button', { name: 'Start proof remote session' }).click()+ await expect(page.locator('#remote-state')).toContainText('"qrVisible":true')+ await page.reload()+ // The production app-mount hook must recover without opening settings.+ await expect(page.getByRole('status')).toContainText('Restart Remote Access and reconnect')+ expect(calls.filter(command => command === 'revoke_remote_memory')).toHaveLength(1)+ await expect(page.locator('#remote-state')).toHaveText('{"enabled":true,"qrVisible":false}')+})+for (const fail of [false, true]) {test(`actual sensitive control ${fail ? 'reports unconfirmed native failure' : 'requests Remote revocation'}`, async ({ page }, testInfo) => {await page.addInitScript(({ fail }) => {diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 35973abf..253ca0c6 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -21,6 +21,7 @@ import { useProviderStore } from '../../stores/providerStore'import { useChatStore } from '../../stores/chatStore'import { useModelStore } from '../../stores/modelStore'import { useRemoteStore } from '../../stores/remoteStore'+import { useRemoteRecovery } from '../../hooks/useRemoteRecovery'import { useModelHealthStore } from '../../stores/modelHealthStore'import { extractMemoriesFromPair } from '../../hooks/useMemory'import { detectLocalBackends, type DetectedBackend } from '../../lib/backend-detector'@@ -118,6 +119,7 @@ const loadOnboarding = () => import('../onboarding/Onboarding').then((m) => ({ d* der Wurzel statt an 668 Call-Sites) steht dort.*/export function AppShell() {+ useRemoteRecovery()// Targeted, NOT `useUIStore()`. A whole-store subscription here put the// entire app tree behind every uiStore write — and the explorer's resize// handle writes `explorerWidth` on every pointermove, so dragging thediff --git a/src/hooks/useRemoteRecovery.ts b/src/hooks/useRemoteRecovery.tsnew file mode 100644index 00000000..58407102--- /dev/null+++ b/src/hooks/useRemoteRecovery.ts@@ -0,0 +1,10 @@+import { useEffect } from 'react'+import { isTauri } from '../api/backend'+import { useRemoteStore } from '../stores/remoteStore'++/** Recover native state on app mount, not only when Remote settings open. */+export function useRemoteRecovery(): void {+ useEffect(() => {+ if (isTauri()) void useRemoteStore.getState().refreshStatus()+ }, [])+}diff --git a/src/stores/__tests__/remote-memory-revocation.test.ts b/src/stores/__tests__/remote-memory-revocation.test.tsindex b357e9c3..4b6b9cbb 100644--- a/src/stores/__tests__/remote-memory-revocation.test.ts+++ b/src/stores/__tests__/remote-memory-revocation.test.ts@@ -32,6 +32,45 @@ afterEach(async () => {})describe('automatic Remote memory revocation', () => {+ it('revokes a running native snapshot discovered after frontend state was lost', async () => {+ call.mockResolvedValue({ ...started, running: true })+ await useRemoteStore.getState().refreshStatus()+ expect(call).toHaveBeenCalledWith('revoke_remote_memory')+ expect(useRemoteStore.getState().memoryNotice).toBe(REMOTE_MEMORY_CHANGED)+ call.mockClear()+ await useRemoteStore.getState().refreshStatus()+ expect(call).not.toHaveBeenCalledWith('revoke_remote_memory')+ })++ it('does not treat a normally started session as an unknown snapshot', async () => {+ await useRemoteStore.getState().startServer()+ call.mockClear().mockResolvedValue({ ...started, running: true })+ await useRemoteStore.getState().refreshStatus()+ expect(call).not.toHaveBeenCalledWith('revoke_remote_memory')+ })++ it('ignores a late running status response after explicit stop', async () => {+ const status = deferred<typeof started & { running: boolean }>()+ call.mockImplementation(async name => name === 'remote_server_status' ? status.promise : started)+ const refresh = useRemoteStore.getState().refreshStatus()+ await useRemoteStore.getState().stopServer()+ status.resolve({ ...started, running: true })+ await refresh+ expect(useRemoteStore.getState().enabled).toBe(false)+ expect(call).not.toHaveBeenCalledWith('revoke_remote_memory')+ })++ it('ignores a status response from before a fresh start', async () => {+ const status = deferred<typeof started & { running: boolean }>()+ call.mockImplementation(async name => name === 'remote_server_status' ? status.promise : started)+ const refresh = useRemoteStore.getState().refreshStatus()+ await useRemoteStore.getState().startServer()+ status.resolve({ ...started, running: false })+ await refresh+ expect(useRemoteStore.getState().enabled).toBe(true)+ expect(call).not.toHaveBeenCalledWith('revoke_remote_memory')+ })+it.each(['delete', 'edit', 'sensitive', 'scope', 'clear'] as const)('revokes a running prompt on %s', async kind => {await useRemoteStore.getState().startServer()expect(call.mock.calls.find(([name]) => name === 'start_remote_server')?.[1]?.systemPrompt).toContain(entry.content)diff --git a/src/stores/remoteStore.ts b/src/stores/remoteStore.tsindex 7dec5e79..3c12e27d 100644--- a/src/stores/remoteStore.ts+++ b/src/stores/remoteStore.ts@@ -8,6 +8,7 @@ import type { MemoryFile } from '../types/agent-mode'export const REMOTE_MEMORY_CHANGED = 'Remote memory changed. Restart Remote Access and reconnect before continuing. Previously delivered data cannot be recalled.'const REMOTE_MEMORY_UNCONFIRMED = 'Remote memory changed, but blocking Remote Access could not be confirmed. Disconnect remote devices and stop Remote Access before continuing.'let memoryRevision = 0+let lifecycleRevision = 0let revocationPending: Promise<void> = Promise.resolve()async function waitForMemoryRevocation(ignoreFailure = false): Promise<void> {@@ -271,6 +272,7 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({set({ loading: false, enabled: false, error: REMOTE_DEV_MODE_ERROR })throw new Error(REMOTE_DEV_MODE_ERROR)}+ lifecycleRevision += 1set({ loading: true, error: null })let serverStarted = falsetry {@@ -339,6 +341,7 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({},stopServer: async () => {+ lifecycleRevision += 1try {await backendCall('stop_remote_server')// A confirmed explicit stop also permits recovery from failed IPC.@@ -364,6 +367,8 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({},refreshStatus: async () => {+ if (get().loading) return+ const revision = lifecycleRevisiontry {const status = await backendCall<{running: boolean@@ -376,6 +381,10 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({tunnelUrl: stringpermissions?: RemotePermissions}>('remote_server_status')+ // A response requested before a start/stop must not resurrect stale UI+ // state or revoke the freshly started replacement session.+ if (revision !== lifecycleRevision || get().loading) return+ const unknownRunningSnapshot = status.running && !get().enabledconst next: Partial<RemoteState> = {enabled: status.running,port: status.port,@@ -393,6 +402,9 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({const perms = normalizeRemotePermissions(status.permissions)if (perms) next.permissions = permsset(next as RemoteState)+ // After a WebView reload, local revision history is gone while Rust may+ // still serve an old prompt. Require a fresh dispatch, not silent resume.+ if (unknownRunningSnapshot) await revokeRemoteMemory()} catch {// Non-critical}@@ -539,6 +551,7 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({set({ loading: false, enabled: false, error: REMOTE_DEV_MODE_ERROR })throw new Error(REMOTE_DEV_MODE_ERROR)}+ lifecycleRevision += 1set({ loading: true, error: null })let serverStarted = falsetry {