Files
pipelines/app/notes/chat-workspace-persistence.md

1.9 KiB

Local chat workspace persistence

ChatWorkspaceSnapshot encodes the split tree, stable pane IDs, chat session IDs, axes, divider ratios, active pane, and sidebar mode. It contains no message bodies, drafts, authentication, or server-side session operations. The SharedPreferences store scopes its key by the supplied logical server storage identity; browser and mobile preferences remain local to their installation.

The screen owns loading and saving. Capture controller.revision before an async read and supply it as expectedRevision to restoreLayout so opening, splitting, resizing, or activating chats during loading takes precedence over stored state. Explicit initial routes can select their chat after a successful restore. Save mutations and sidebar changes with debounce/serialized writes. A validated empty snapshot records deliberate closure rather than resurrecting an older workspace.

Version 1 validates IDs, uniqueness, active membership, axes and finite ratios, with a maximum 128 KiB representation, 127 nodes and depth 32. Invalid or unknown versions return null; unknown ordinary fields remain compatible. The store also returns null for unavailable/corrupt preferences and false for failed writes. Session availability is a screen/provider concern: the codec preserves identities without contacting or reopening sessions on the server.

Production ChatDestination enables ChatWorkspaceBinding. Embedded/test screens opt in explicitly. The binding serializes debounced saves, flushes pending edits on disposal, and guards both tree and sidebar edits against late preference reads. A direct-link chat is selected if already present or added beside the restored panes. Logical server changes bind a separate snapshot and cannot carry panes from the previous server. Narrow devices retain the tree and show its active pane.

Focused validation uses tool/memwatch/full.sh test/features/chat/workspace and the real-screen chat_workspace_restore_test.dart.