Task 12: Persistence (fluxer-platform::store) (#12) #49
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "task/12-platform-persistence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on: task/9-core-guilds-channels, task/10-core-messages-readstate, task/11-core-presence-ui (merged into this branch at
73799f7; everything after that commit is Task 12)What this builds
fluxer-core::persistPersistOp { SaveToken, ClearToken, SaveSettings(LocalSettings), CacheMessages { channel_id, messages }, CacheReady(Box<ReadyPayload>) }andPersistResult { Loaded { token, settings, cached_ready }, Ok }.LocalSettings(instance_url,installation_id,sidebar_width,window {x,y,w,h,maximized},notifications_enabled,status_api {enabled, token});Debugdoes not print the status token.Loadedwith a token ->Discovering(Api Discover) ->LoggingIn(Api Me) ->LoggedIn+ConnectGateway, noSaveToken. A 401 onMeemitsClearTokenand ends inSessionExpired; any other failure leaves the token in the keyring.cached_ready(only with a token) fills guilds, channels, users, presences, read markers and the synced user settings and setsApp::stale. The liveREADYreplaces all of it; the data is also dropped when the attempt ends orMeanswers for another account.CacheReadyon each liveREADY,CacheMessageson each non-empty history page,SaveSettingswhenSidebarResized/SetInstance/SetNotificationsEnabled/SetStatusApiEnabledchange something.fluxer-platformPaths::new("fluxer-native")/Paths::under(root).settings::load/settings::save: defaults when missing (written at once), invalid file renamedsettings.toml.bad, per-field fallback, atomic write, mode 0600 on Unix. Status token = 24 random bytes base64url, as infork:fluxer_desktop/src/common/DesktopConfig.ts.Secrets::new(host),save_token/load_token/clear_tokenoverkeyring::Entry::new("fluxer-native", host).Cache::open(rusqlite bundled,user_version = 1): a file that is not a database, failsquick_check, or has another version is deleted and recreated; if the file is unusable the cache runs in memory. Never fails (Review Focus 5).put_messages(newest 200 per channel),get_messages(channel, limit)in ascending id order,put_ready/get_ready,clear.Store:Store::load(paths) -> (Store, PersistResult::Loaded)andStore::execute(&PersistOp)for the runtime (Task 14).How it was tested
cargo xtask cigreen locally (Linux). New tests:crates/fluxer-core/tests/persist.rs(15):loaded_token_triggers_me_then_connect,cached_ready_marks_store_stale_until_live_ready, plus rejected token, unreachable instance, other account, cancelled restore, caching and settings writes.crates/fluxer-platform/tests/settings.rs(7):settings_default_when_missing_and_bad_file_renamedand per-field fallbacks, round trip, file mode.crates/fluxer-platform/tests/cache.rs(11):cache_rebuilt_when_corrupt,cache_rebuilt_when_user_version_differs,cache_roundtrips_messages_in_id_order, truncated file, bound per channel, undecodable rows, in-memory fallback.Store,PathsandSecrets. The keyring tests run against keyring-core's in-memory mock store: the real OS keyring is not exercised by any test, here or in CI. Not built or run on Windows locally.Deviations from the plan
LocalSettingsis defined influxer-core(PersistOp::SaveSettingscarries it and core cannot depend on platform), so loading and saving arefluxer_platform::settings::load(&paths)/save(&paths, &settings), not methods. Core gains auuiddependency forinstallation_id.cached_readyisOption<Box<ReadyPayload>>(boxed like the mergedGatewayEvent::Ready).Appfieldssettings: Option<LocalSettings>andstale: bool; newSession::token(), which the runtime needs to sendMebefore a logged-in state exists.Loadedevent. This also keeps the Task 9-11 tests, which assert thatREADYemits no effects and never sendLoaded, unchanged.RegenerateStatusTokenis not handled: the store has no randomness.settings::new_status_token()is public for whoever implements it.UserActionreports it yet, so nothing updates it.directories,keyring,rusqlite):toml,base64,getrandom, dev-onlytempfileandkeyring-core.deny.tomlnow ignores RUSTSEC-2026-0370/-0371/-0372 (zvariant,zbus_names,zvariant_derive5.x marked unmaintained after being merged into zbus 6; they come in through keyring's Secret Service store and there is no upgrade yet). Follow-up: #48. This is a policy exception for Charles to accept or reject.For the reviewer: the stacking merge was not purely mechanical
Tasks 9, 10 and 11 each replaced the others' stub types, so merging them conflicted in
crates/fluxer-core/src/{app.rs,lib.rs,selectors/mod.rs}and the README. Resolved in the two merge commits before73799f7:App::applyruns the reducers of all three (guilds/channels, then messages/typing/read state, then users/presence/ui, withuiaftermessagesas its comment requires); the stub structs are gone.messages.rs,typing.rs,read_state.rsimportChannels/UiStatefrom their real modules.tests/presence_ui.rs: theuser()helper no longer asserts that a user action emits no effects, because with Task 10 presentSelectChannelfetches the first page.Closes #12
🤖 Generated with Claude Code
Independent review: Task 12 (head
6eb27db, diff from73799f7)Verdict: APPROVE — no blocking findings;
cargo xtask cigreen locally on Linux in a fresh review worktree with its own target dir (screenshot step skipped,FLUXER_SCREENSHOT_TESTSunset). Not checked by me: Windows build/run, and the real OS keyring (tests use keyring-core's mock store only).Checks
settings_default_when_missing_and_bad_file_renamed(320 /https://fluxer.forked.io// notifications on,.badholds the original bytes),cache_rebuilt_when_corrupt(garbage bytes, open succeeds on disk, empty,user_version1),cache_rebuilt_when_user_version_differs,cache_roundtrips_messages_in_id_order,loaded_token_triggers_me_then_connect(Discover, Me, ConnectGateway, no SaveToken),cached_ready_marks_store_stale_until_live_ready.PersistOpandPersistResultvariants,Paths::new,Secrets::{save,load,clear}_token,Cache::open/put_messages/get_messages/put_ready/get_readyare present. Deviations are listed under minor.uuid, still no I/O; the token isSecretString,StatusApiSettingsredactsDebug, only the scrubbedflx_FIXTURE…placeholder appears; cache and settings files are 0600 on Unix; no panic path on server or disk data (the oneexpectis on a constant with a test).Cache::opencannot fail.Meclears the token, other failures keep it. Covered by tests.Findings (all minor)
Loaded.cached_readyisOption<Box<ReadyPayload>>(plan:Option<ReadyPayload>);LocalSettingslives influxer_core::persistand load/save are free functionsfluxer_platform::settings::{load,save}rather thanLocalSettings::load(&Paths); the keyring user ishost[:port], not the bare host.crates/fluxer-core/src/persist.rs): everySaveSettingscarries core's wholeLocalSettings, and no event updatesstatus_api.tokenorwindowin it. If Task 15 regenerates the status token, or the app saves window geometry, straight to the file, the next sidebar drag writes the old values back.RegenerateStatusTokenand geometry are not implemented (stated by the implementer); they need a core event, and deserve a follow-up issue.crates/fluxer-platform/src/lib.rs): the cache is emptied only onClearToken. After a restore that failed for a non-401 reason followed by a login as a different user, or aMethat returns another account,CacheReadyreplaces the READY row but the previous account'smessagesrows stay. Clearing on a READY whose user id differs from the cached one would close it.SaveSettingsper sidebar-drag event does a full write + fsync (settings.rs); documented as coalescible by the runtime, so Task 14 has to do that.deny.tomlignores RUSTSEC-2026-0370/-0371/-0372 (zvariant, zbus_names, zvariant_derive 5.x unmaintained, via keyring 4's Secret Service store); follow-up #48. Extra dependencies beyond the plan's three:toml,base64,getrandom,uuidin core, dev-onlytempfileandkeyring-core.