Task 10: Messages, typing, read state (#10) #46
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "task/10-core-messages-readstate"
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/8-core-store-session
What this builds
fluxer-coremessages, typing and read state (Foundation plan, Task 10; spec §4).messages.rs:Messages { by_channel },ChannelMessages { items, oldest_loaded, reached_start, loading, pending },MessageRecord { message, state: Sent | Pending | Failed },PendingMessage { nonce, content, created_at }. Reducers forSelectChannel(first page of 50),ScrolledToOldest(page beforeoldest_loaded),ApiResult::Messages/Sent/Edited/Deleted,MESSAGE_CREATE/UPDATE/DELETE/DELETE_BULK,CHANNEL_DELETE,SendDraft,RetrySend,EffectFailed.typing.rs:TypingState,typing_users(app, channel), incoming indicators that expire after 10 s and outgoingApi Typingat most every 8 s per channel.read_state.rs:ReadStates { by_channel }fromREADY,MESSAGE_ACK,READ_STATE_UPDATE;unread(app, channel),mention_count(app, channel);MarkReademitsApi Ackand applies it locally.selectors/messages.rs:timeline(app, channel)with day separators and grouping (rule read from the fork'sMessageGroupingUtils.ts: same author, same day, at most 7 minutes, previous not a system message, current not a reply).Review Focus 2: a
MESSAGE_CREATEfor a channel that is not inapp.channels.by_idis ignored with atracing::debug!. It creates no message entry, no channel, no read state, andunreadstays false (message_create_unknown_channel_is_ignored).How it was tested
crates/fluxer-core/tests/messages.rs, 25 tests throughApp::applyonly, using theREADY,MESSAGE_CREATE,MESSAGE_UPDATE,TYPING_STARTandmessages_pagefixtures: the 11 tests the plan names, plus unasked/stale pages, a failed first page, a create arriving while the first page loads, update/delete, REST-only confirmation, empty drafts, own messages not becoming unread, reconnect, channel delete and logout. Tests were written first and committed failing.cargo xtask ciis green locally.Deviations from the plan
TypingState.by_channelmaps user to theTimerIdof its expiry timer instead of anInstant; the 8 s throttle is a timer too. The runtime (Task 14) must deliverCoreEvent::Timer.items.PendingMessage::created_atis the time of the newest message known at that moment, not wall-clock time. If a real send time is wanted for pending rows, the runtime has to supply the time in an event; that is a decision for Charles and is not blocking.app.rs):Channels { by_id }andUiState { drafts }, with the names from those tasks' Interfaces. Nothing fills them here; the tests fill them by hand. Merging Tasks 9 and 11 will conflict inapp.rson these stubs and onselectors/mod.rs(both sides add it): keep their types, keep bothpub modlines.SendDraftreads and removes the text fromapp.ui.drafts; it relies on Task 11 storing the draft onDraftChangedand not clearing it onSendDraftbefore the messages reducer runs.MESSAGE_CREATEwritesChannel::last_message_idinapp.channels(Task 9's reducer list has noMessageCreate).effect.rs(Effects::schedule, timer ids from the same counter as effect ids),app.rs(wiring, a newApp::typingfield, the stubs),lib.rs,selectors/mod.rs,Cargo.toml(time, already a workspace dependency, forDate),README.md.itemsstays one contiguous run; the first-page check is "loaded" rather than "no items", so an empty channel is not fetched again.READY(a new session, not a resume) drops the history of open channels and fetches their first page again, because events may have been missed.MESSAGE_CREATEmoves the read marker (the Electron client'sackCurrentUserMessage).timeline_with_offset(app, channel, UtcOffset)for local days;timelineuses UTC.Closes #10
🤖 Generated with Claude Code
Independent review: Task 10 (core-messages-readstate) at
38a4f01Scope:
git diff cacedcb..38a4f01only. Read cold; the server behaviour quoted below was checked against the fork checkout.Checks
crates/fluxer-core/tests/messages.rsand assert the plan's values (limit 50,before: oldest_loaded, short page =>reached_start, 8 s throttle, 10 s expiry, nonce replace, failed + retry with the same nonce, unread fromlast_message_id, ack, grouping at exactly 7 min and day separators). 14 extra edge-case tests. Tests were committed failing first (223ac63).Messages,ChannelMessages(all five fields),PendingMessage { nonce, content, created_at },MessageRecord,ReadStates,unread,mention_count,timeline,TimelineItemexist as written. One deviation:TypingStatemaps user ->TimerId, notInstant(finding 3).fluxer-core(timeis an existing workspace dep), no I/O, nounwrap/expect/indexing on server data in the new modules, no secrets in code or tests.message_create_unknown_channel_is_ignoredcovers it: no message entry, no channel, no read state,unreadfalse,mention_count0, no effects; the rest of an unknown channel's traffic is covered too.cargo xtask ciin the review worktree: green (screenshot step skipped,FLUXER_SCREENSHOT_TESTSnot set).Findings
messages.rssend_draft: the nonce is deterministic ("highest id seen + 1"), and the server deduplicates on it.fork:fluxer_api/.../MessageOperationsHelpers.ts findExistingMessagekeys a cache onmessage-nonce:{userId}:{nonce}for 5 minutes (MESSAGE_NONCE_TTL): a reused nonce in the same channel returns the earlier message and creates nothing; in another channel it throwsUnknownMessageError. Within one session the nonces only grow, so this is safe. It is not safe across a restart or logout/login inside 5 minutes, becausenewest_seenrestarts from 0: load channel Y (newest id G), send in X => nonce G+1; restart, load Y (still G), send in Y => nonce G+1 again => the send fails, andRetrySendreuses the nonce so it keeps failing until the TTL runs out. Two native clients of one account that are at the same newest id and send into the same channel get the worse case: the second message is dropped by the server and the client shows it as sent. Found by reading, not reproduced against a server. The Electron client usesSnowflakeUtils.fromTimestamp(Date.now()). The fix needs a clock or randomness from the runtime (for example a per-launch random base passed inCoreConfig), which touches Task 8/14 interfaces, so it is not for this PR; but it is a design question for Charles and CLAUDE.md asks for aquestionorfollow-upissue linked from the PR, which is missing.messages.rssend_draft: the pending message'stimestamp/PendingMessage.created_atis the newest known message time, not the send time. In a channel with no messages and nothing seen yet (first message of a new DM) the provisional id is 1, so the pending row is dated 2015-01-01 andtimelineputs a day separator for that date above it until the echo arrives. Same root cause as finding 1 (no clock); the implementer disclosed the deviation. Also, a message from someone else that arrives while mine is pending sorts after it, since the provisional id is lower than any new real id.typing.rs:TypingState::by_channelholdsTimerIdwhere the plan's Interfaces block saysInstant. Reasonable (the merged store never reads a clock, andtyping_usersis the read API), but consumers must not read the map's values, and Task 14 must deliverCoreEvent::Timeror indicators never expire and outgoing typing is announced once per channel only.app.rs:Channels { by_id }andUiState { drafts }are filled in here ahead of Tasks 9 and 11, andAppgains a pubtypingfield. Field names and types match those tasks' Interfaces blocks, so this is a merge conflict, not a contract break. Two things for the integrator:SendDraftreads and removesapp.ui.drafts[channel], so Task 11's reducer must not clear the draft beforeMessages::reduceruns; andcrate::app::{Messages, ReadStates}no longer exist (they moved to their modules; the crate-root re-exports are unchanged).READYdrops and refetches open channels' history; the user's ownMESSAGE_CREATEadvances the read marker; the three domains are reset on every event while logged out, which also discardsFailedsends at logout.Verdict: APPROVE (0 blocking, 5 minor; local ci green). Please open the follow-up/question issue for finding 1 and link it here before merge.