Skip to content

fix(desktop): clear previous account's conversations and memories on in-place account switch - #9821

Merged
kodjima33 merged 1 commit into
mainfrom
kodjima33/fix-conversations-owner-switch
Jul 15, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
kodjima33/fix-conversations-owner-switch

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator

Bug (reproduced live)

Signing out of account A and into account B in the running app left A's conversations rendering for B (and A's memories until the deferred container reset). Verified data-side: the rendered rows existed only in A's cloud while the app's RewindDatabase had already retargeted to B's per-uid store.

Root cause

An in-place account switch re-auths through commitSignedInSession → performEffectiveOwnerTransition, which posts only .runtimeOwnerDidChange — never .userDidSignOut. ConversationRepository was absent from every owner-change reset path (its only reset hung off the signOut()-only .userDidSignOut view handler), and ConversationsPage.onAppear skips its reload while the array is non-empty. MemoriesViewModel had the same gap (deferred-only reset).

Fix

Both now subscribe to .runtimeOwnerDidChange and reset themselves — mirroring TasksStore's existing owner fence. repository.reset() already advances requestGeneration/cacheWriteScope (cancels in-flight loads/mutations fail-closed) and publishes an empty snapshot so the page reloads the new account.

Verification

  • Regression tests: repository clears + publishes an empty snapshot on the notification; memories clear likewise. Full ConversationRepositoryTests (26) + TasksStoreOwnerBoundaryTests (14) + new memories fence test = 41 green.
  • Real path on a named bundle signed into the real account: Conversations showed the account's rows → swap_test_owner (drives the production performEffectiveOwnerTransition path — the exact vector of the reported re-login) cleared the list to "No Conversations" instead of leaking the previous owner's rows → restore_test_owner reloaded the correct account's conversations. Three-panel screenshot captured.
  • Independent agent review: approved (MainActor post-site audit, reset-mid-mutation fail-closed semantics, deinit observer removal, deterministic synchronous test delivery).

Named follow-ups (same failure class, not fenced here)

  • AppState.folders + folder/date/starred filter selections: cleared only in the .userDidSignOut handler; reload sites skip while non-empty (same mechanism as this bug, same page).
  • AppState.people: never cleared on any auth path.
  • DashboardViewModel / HomeStatusStore / AppProvider / MemoryGraphViewModel: deferred-only reset via ViewModelContainer.resetStartupState.

Product invariants affected

none

🤖 Generated with Claude Code

Review in cubic

…in-place account switch

Reproduced live: signing out of account A and into account B in the running
app left A's conversations rendering on the Conversations page (and A's
memories until the deferred container reset). Root cause: an in-place
account switch re-auths through commitSignedInSession →
performEffectiveOwnerTransition, which posts only .runtimeOwnerDidChange —
never .userDidSignOut — and ConversationRepository was absent from every
owner-change reset path (its only reset hung off the signOut()-only
.userDidSignOut view handler). With the stale array non-empty,
ConversationsPage.onAppear also skipped its reload. RewindDatabase and
TranscriptionStorage retarget correctly, which masked the bug as
cloud-level bleed.

Fix (mirrors TasksStore's owner fence): the conversation
repository and MemoriesViewModel now subscribe to .runtimeOwnerDidChange
and reset themselves — repository.reset() already advances
requestGeneration/cacheWriteScope, cancelling in-flight loads and
publishing an empty snapshot so the page reloads the new account.

Verification: regression tests (repository clears + publishes empty
snapshot on the notification; memories clear likewise) plus the existing
ConversationRepository and owner-boundary suites — 41 tests green. Real
path on a named bundle signed into the real account: Conversations showed
the account's rows, swap_test_owner (drives the production
performEffectiveOwnerTransition path) cleared the list to 'No
Conversations' instead of leaking the previous owner's rows, and
restore_test_owner reloaded the correct account's conversations.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kodjima33
kodjima33 merged commit fe1aaa9 into main Jul 15, 2026
7 of 8 checks passed
@kodjima33
kodjima33 deleted the kodjima33/fix-conversations-owner-switch branch July 15, 2026 17:47
kodjima33 added a commit that referenced this pull request Jul 15, 2026
…ail on in-place account switch (#9823)

## What

Completes the owner fence from #9821 (reviewer-identified residuals): an
**open conversation detail** (`ConversationsPageHost` keeps
`selectedConversation` in view-local `@State`) kept showing the previous
account's conversation after an in-place account switch, and **folders /
folder-date-starred filters / counts / loading-error flags / people**
were cleared only by the `signOut()`-only `.userDidSignOut` handler.

- `AppState` now subscribes to `.runtimeOwnerDidChange` →
`resetOwnerScopedContent()` (mirrors the sign-out handler's conversation
subset; people were never cleared on any auth path before).
- `ConversationsPageHost` dismisses any open detail on the same signal.

## Verification

- New `AppStateOwnerFenceTests` regression: folders, filter selections,
counts, flags, and people all clear on the notification. 31 tests green
across the fence suites (`ConversationRepositoryTests`,
`MemoriesViewModelOwnerFenceTests`, `AppStateOwnership`/`OwnerFence`).
- Real path on a named bundle signed into the real account: opened a
conversation detail (`open_latest_conversation`), ran `swap_test_owner`
(production `performEffectiveOwnerTransition` path) — the detail
dismissed and the list showed the empty state with the previous
account's folder chips gone (All/Starred/Work/Personal/Social/Test →
All/Starred); `restore_test_owner` returned cleanly. Two-panel
screenshot captured.

## Still-deferred (named)

`DashboardViewModel` / `HomeStatusStore` / `AppProvider` /
`MemoryGraphViewModel` remain deferred-only via
`ViewModelContainer.resetStartupState`.

## Product invariants affected

none

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kodjima33 added a commit that referenced this pull request Jul 15, 2026
…witch (#9826)

## What

Third and final residual of the account-switch owner fence (#9821,
#9823): with a **search active** during an in-place account switch, the
previous account's rows kept rendering from `ConversationsPage`'s
view-local `searchResults` even after AppState and the repository reset.

The page now clears its owner-scoped local state (search
query/results/flags, multi-select/merge state, folder sheets,
filter-loading flags) on `.runtimeOwnerDidChange` — the same fence as
the repository, AppState, and the detail host. Also adds a
`set_conversations_search` automation-bridge action (same notification
pattern as `open_conversation`) so the real debounced search path can be
exercised in verification without synthetic keyboard/mouse input.

## Verification

Live on a named bundle signed into the real account:
`set_conversations_search query=nik` rendered the account's search
results; `swap_test_owner` (production `performEffectiveOwnerTransition`
path) cleared the query and results to the empty state with the previous
account's folder chips gone; `restore_test_owner` returned cleanly.
Two-panel screenshot captured. Fence suites
(`ConversationRepositoryTests` 26, `MemoriesViewModelOwnerFenceTests`,
`AppStateOwnerFenceTests`) — 28 tests green; test-quality checker at
baseline. (The cleared state is view-local `@State`, so coverage is the
live bridge verification rather than a unit seam.)

## Product invariants affected

none

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kodjima33 added a commit that referenced this pull request Jul 15, 2026
… account switch (#9829)

## What

Race residual of the account-switch fence series (#9821/#9823/#9826):
`AppState` cleared folders/people on `.runtimeOwnerDidChange`, but
`loadFolders()` / `fetchPeople()` had no owner fence — a previous
account's **in-flight response landing after the reset** repopulated the
cleared state, and the skip-while-non-empty reload guards then pinned
the stale data for the new account.

Adds `ownerScopeGeneration` (bumped by `resetOwnerScopedContent()`); the
loads capture it before awaiting and drop their result if it moved —
same pattern as `ConversationRepository.requestGeneration`. Injectable
fetch seams enable hermetic race coverage.

## Verification

- Two new behavioral regressions: a gate-suspended folder load and
people fetch complete **after** `.runtimeOwnerDidChange` and are ignored
(state stays empty). 30 tests green across the fence suites
(`ConversationRepositoryTests` 26 incl. the owner-change regression,
`MemoriesViewModelOwnerFenceTests`, `AppStateOwnerFenceTests` 3).
- Live account-switch round trip re-verified on the named bundle at this
commit (real account's conversations render → `swap_test_owner` clears
to the empty state → `restore_test_owner` returns cleanly); two-panel
screenshot captured.

## Product invariants affected

none

🤖 Generated with [Claude Code](https://claude.com/claude-code)
kodjima33 added a commit that referenced this pull request Jul 20, 2026
…etes the ask step

- reloadForCurrentOwner resets transient celebrationPending so an in-place
  account switch never shows the previous owner's 'second brain is live'
  greeting (PR #9821 bleed class); same-store owner-switch regression test
  posts .runtimeOwnerDidChange and asserts B inherits nothing and A's
  restored progress carries no celebration.
- ChatPage main_chat send marks askedOmi (adjacent to its telemetry call,
  same contract as the floating-bar and home ask sites) so a first question
  asked from the Chat page completes first-win activation.

Verified: ActivationProgressStoreTests 11/11 green; changed-file swift-format
lint clean; bundle relaunched and Home evidence recaptured.

Co-Authored-By: Claude Fable 5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Aug 4, 2026
…ks (#11029)

## Summary

- Make the durable `account_deletions/{uid}` marker a single fail-closed
admission policy across Firebase, developer/MCP keys, OAuth issuance,
HTTP/WebSocket entry points, Agent proxy sessions, and Agent VM
provisioning. Completed and unknown markers remain fenced so an old
token cannot revive a deleted UID.
- Make deletion admission atomic at `pending`, revoke UID-bearing
API/OAuth credentials, delete the account's GCE Agent VM before its
Firestore pointer disappears, and transactionally fence late proxy/VM
writes so in-flight work cannot recreate owner data.
- Make accepted macOS cleanup durable across restart, drain owner-bound
VM/sync work before deleting storage, remove the legacy anonymous
fallback, upload a consistent SQLite snapshot with cancellable
compression and bounded retries, and preserve typed startup errors in
Flutter.

Repeated delete requests during `pending`/`running` intentionally
receive typed `403 account_deletion_in_progress` responses without
marker rollback or requeue. The deletion fence is preserved.

Canonical project: [BasedHardware Project
#15](https://github.com/orgs/BasedHardware/projects/15)

## Sanitized incident evidence

- A delete confirmation preceded a later same-provider
sign-in/onboarding sequence by nine days.
- The deleted UID's user document and GCE instance were gone, while its
durable deletion marker completed after retried queue acceleration
failures.
- No verified event proves old server memory reads after deletion. This
PR treats legacy local-database migration, still-valid old credentials,
and late owner-scoped work as identity-isolation risks; typed readiness
failures remain timeout-class evidence rather than proof of server data
disclosure.

Related lineage: #10444, #7696, #9632, #10597, #9821, #6891, #6892,
#10600, and #10694.

## Failure class

Failure-Class: none

This is an audit-driven hardening sweep across durable deletion
admission, credential revocation, local owner-data disposal, and Agent
VM/proxy lifecycle safety. The reusable prevention surfaces are the
shared fail-closed policy, transactional admission/CAS writers, the
durable local cleanup journal, the effective-owner generation fence, and
behavioral regression tests.

## Product invariants affected

- INV-AUTH-1 — preserves the exclusive effective-owner transition,
clears accepted-deletion storage before credential/session publication,
blocks every credential family after durable admission, and rejects late
owner-bound Agent VM continuations.
- INV-CHAT-1 — drains Agent VM/sync work at the existing owner
transition, transactionally fences late proxy message/session writes,
and preserves typed startup failures without changing canonical
transcript ownership.

## Changed paths

-
`.github/scripts/product_file_line_count_ratchet_baseline/backend-database.json`
-
`.github/scripts/product_file_line_count_ratchet_baseline/backend-routers.json`
-
`.github/scripts/product_file_line_count_ratchet_baseline/desktop-swift-root.json`
- `app/lib/services/agent_chat_service.dart`
- `app/test/services/agent_chat_service_test.dart`
- `backend/agent-proxy/Dockerfile`
- `backend/agent-proxy/main.py`
- `backend/database/account_deletion_projection_fence.py`
- `backend/database/mcp_oauth.py`
- `backend/database/users.py`
- `backend/dependencies.py`
- `backend/routers/apps.py`
- `backend/routers/desktop_agent_vm.py`
- `backend/routers/mcp_sse.py`
- `backend/routers/oauth.py`
- `backend/routers/transcribe.py`
- `backend/services/users/account_deletion.py`
- `backend/testing/e2e/test_account_deletion_cloud_tasks.py`
- `backend/tests/services/users/test_account_deletion.py`
- `backend/tests/unit/test_account_deletion_auth_fence.py`
- `backend/tests/unit/test_agent_proxy_async_boundaries.py`
- `backend/tests/unit/test_agent_proxy_startup_client_gone.py`
- `backend/tests/unit/test_byok_security.py`
- `backend/tests/unit/test_dependency_async_boundaries.py`
- `backend/tests/unit/test_desktop_agent_vm.py`
- `backend/tests/unit/test_mcp_api_key_auth_context.py`
- `backend/tests/unit/test_mcp_oauth.py`
- `backend/tests/unit/test_oauth_token_async_boundaries.py`
- `backend/utils/account_deletion_access.py`
- `backend/utils/other/endpoints.py`
- `desktop/macos/Desktop/Sources/AgentSyncService.swift`
- `desktop/macos/Desktop/Sources/AgentVMService.swift`
- `desktop/macos/Desktop/Sources/AuthService.swift`
- `desktop/macos/Desktop/Sources/Chat/RuntimeOwnerIdentity.swift`
- `desktop/macos/Desktop/Sources/DefaultsKey.swift`
- `desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift`
-
`desktop/macos/Desktop/Sources/MainWindow/Pages/Settings/Components/SettingsContentView+SettingsUpdates.swift`
-
`desktop/macos/Desktop/Sources/Rewind/Core/RewindDatabase+AccountDeletion.swift`
- `desktop/macos/Desktop/Tests/AgentSyncBatchQueryTests.swift`
- `desktop/macos/Desktop/Tests/AgentVMLifecycleFenceTests.swift`
- `desktop/macos/Desktop/Tests/AuthSessionCoordinatorTests.swift`
- `desktop/macos/Desktop/Tests/OnboardingPersistenceClearingTests.swift`
- `desktop/macos/Desktop/Tests/RewindDatabaseLifecycleTests.swift`
-
`desktop/macos/changelog/unreleased/20260802-account-deletion-local-data.json`
- `desktop/macos/e2e/flows/logout.yaml`

## Verification

- Focused backend deletion/auth/proxy/VM suite: `194 passed`.
- Hermetic Cloud Tasks deletion suite: `5 passed`; repeated
pending/running requests are asserted as typed `403` without requeue.
- Focused macOS deletion, owner-fence, snapshot, and sync suite: `32
tests`, `0 failures`.
- Focused Flutter Agent Chat suite: `2 passed`.
- Follow-up MCP OAuth consent suite: `37 passed`.
- Follow-up macOS cleanup/bridge compile suite: `17 tests`, `0
failures`.
- Python runtime sources compile cleanly; pinned Python/Dart/Swift
formatters and `git diff --check` are clean.
- Required CI-lane PR-body preflight: `34 checks passed` in `108.01s`.

Backend Hermetic Merge Gate: in scope because backend runtime and
hermetic contract code changed.

## Limitations

- No production Firebase/Auth, Firestore, Cloud Tasks, GCE, deployment,
release, or customer-data mutation was performed.
- Same-provider recreation is covered hermetically at the UID/auth
boundary; no live Google sign-in was attempted.
- Agent readiness and teardown are covered through backend
state-machine, proxy protocol, owner-generation, snapshot/upload,
credential cleanup, and stale-pointer tests; no live GCE VM was
provisioned.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11029?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
kodjima33 added a commit that referenced this pull request Aug 27, 2026
…tions) (#12312)

## Why

Cross-review caught the #9821 account-switch-bleed class in the new
prompt surfaces: all rating/remote-prompt state was device-global, so
one account's answer or dismissal suppressed prompts for every later
account on the same Mac.

## What

Every key (question count, submitted rating, dismissed, history-seed
marker, per-prompt remote resolutions) is now owner-scoped via
ScopedDefaultsKey. First scoped access migrates the pre-scoping global
keys to the currently signed-in account (single-account Macs keep their
state — nobody who already answered gets re-prompted) and deletes the
globals. The remote engine's question count is now literally
`RatingPromptManager.questionCount` — one owner-scoped ledger.

## Verification

`PromptStateAccountScopingTests` (3): submit on account A → account B
starts clean, asks 3 questions, sees the prompt; switching back
preserves A's submission; remote prompt dismissed by A is still offered
to B; legacy global state migrates to the first account only, second
account starts clean. All prompt suites 23/23. swift build clean.

Failure-Class: none
igor-popov-dev pushed a commit to igor-popov-dev/omi that referenced this pull request Aug 27, 2026
…ions

Cross-review caught the BasedHardware#9821 account-switch-bleed class: every prompt key
(question count, submitted rating, dismissed, history-seed marker, remote
prompt resolutions) was device-global, so one account's answer suppressed
prompts for every later account on the Mac. All state now lives under
owner-scoped ScopedDefaultsKeys; the first scoped access migrates the
pre-scoping global keys to the signed-in account (single-account Macs keep
their state, nobody gets re-prompted) and removes them. The remote engine's
question count is now literally RatingPromptManager.questionCount — one
owner-scoped ledger accessor.

PromptStateAccountScopingTests (3): rating submission does not suppress the
next account and survives switching back; remote resolutions are
per-account; legacy global state migrates to the first account only. Full
prompt suites 23/23.

Failure-Class: none
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