feat: scope AI session browser storage to the logged-in user#9518
Draft
Guilhem-lm wants to merge 2 commits into
Draft
feat: scope AI session browser storage to the logged-in user#9518Guilhem-lm wants to merge 2 commits into
Guilhem-lm wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Deploying windmill with
|
| Latest commit: |
d65b81d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://952b5947.windmill.pages.dev |
| Branch Preview URL: | https://glm-make-sessions-user-speci.windmill.pages.dev |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AI "sessions" (the fork/draft workspaces feature behind
/sessions, plus the AI chat history that backs them) persisted entirely in the browser un-scoped to the logged-in user. On a shared browser (sequential logins, or a superadmin handing off a machine), user B saw user A's sessions, chat history, and unread badges, and silently inherited A's autonomy setting — including the unsafe auto-execute "YOLO" mode.This PR namespaces all four browser-persisted session surfaces by the logged-in instance user email — the only identity stable across a fork family (a single session deliberately spans multiple
workspace_ids;usernamevaries per workspace,emaildoes not). Existing single-user data is claimed-then-migrated on first login; logged-out / pre-resolve state is empty and fail-safe.Changes
frontend/src/lib/userScopedStorage.ts— owns a singleuserStoresubscription and exposes:scopedKey(base)→`${base}::${email}`(orundefinedwhen logged out → callers no-op)onUserChange(cb)— fires immediately on registration (covers late registrants whose email already resolved) and on every email changemigrateLegacyLocalStorage(legacy, target)— claim-then-delete of pre-namespacing datasessionState.svelte.ts) — starts empty; hydrates/persists underwindmill_sessions::email;persistSessions()no-ops while logged out; resets in-memory list + active session on logout / user switch.sessionUnread.svelte.ts) — scoped key + hydrate-on-email.HistoryManager.svelte.ts) — per-user DB name; email-gatedinit(); legacy DB copied-then-deleteDB. The singleton self-heals viaonUserChange.AIChatManager.svelte.ts) — initialises to the safeACCEPT_EDITdefault before email resolves; the module-level singleton re-hydrates fromai-chat-autonomy-mode::email(+ legacyai-chat-yolo-mode) viaonUserChange; per-session managers read the scoped key at construction.ai-chat-open/panel size stays global (cosmetic).onUserChange(per-session managers are post-login and read scoped keys directly) so the never-unregistered callback set stays bounded.No backend / EE changes (frontend localStorage + IndexedDB only).
Test plan
npm run check— 0 errorsuserScopedStorage.test.ts+ updatedAIChatManager.test.ts/sessionState.test.ts— 38 tests pass (isolation, legacy-claim migration, no-persist-while-logged-out, safe autonomy default)windmill_sessions+ai-chat-autonomy-mode=yolo; after login both claimed into…::admin@windmill.devand legacy keys deleted; a seeded…::other@user.devleft untouched (isolation); migration did not fire on the logged-out workspace picker; migratedyoloshowed live on a new session (reactive hydration)Notes / follow-ups
HistoryManagerIndexedDB migration (maybeMigrateLegacyChatDb) —fake-indexeddbisn't currently a dev dependency. Verified manually in-browser; a future test seeding a legacy DB and asserting copy-then-delete would be valuable.🤖 Generated with Claude Code