Skip to content

feat: unified ordering foundation (effective_ts + arrival_seq)#93

Merged
ImpulseB23 merged 2 commits intomainfrom
feat/unified-ordering
Apr 20, 2026
Merged

feat: unified ordering foundation (effective_ts + arrival_seq)#93
ImpulseB23 merged 2 commits intomainfrom
feat/unified-ordering

Conversation

@ImpulseB23
Copy link
Copy Markdown
Owner

Adds the foundation for cross-platform message ordering and optimistic send (issue #88).

What

  • UnifiedMessage gains two fields:
    • effective_ts: i64 — sort timestamp under the snap rule
    • arrival_seq: u64 — monotonic per-process tie-breaker
  • SNAP_WINDOW_MS = 500 and pure helper compute_effective_ts(timestamp, arrival_time)
  • assign_arrival_seqs(batch, &mut counter) stamps a whole batch
  • Drain loop owns the counter for the lifetime of one sidecar run
  • Frontend ChatMessage mirrors the new fields

Snap rule

effective_ts = if |platform_ts - arrival_time| <= 500 then platform_ts else arrival_time

Trust the platform clock when it agrees with local arrival, otherwise fall back to arrival time. The sort key (effective_ts, arrival_seq) is stable across renderers and gives us coherent interleave for Twitch + YouTube + Kick without any custom sync server.

Why now

This is the substrate for issue #88 (optimistic send) and the future cross-platform unified feed. Both reuse the same machinery: optimistic sends start with effective_ts = now(), get re-anchored to the authoritative event when it echoes back.

Tests

  • 187 Rust unit tests (180 + 7 new for snap boundaries and seq counter)
  • 62 vitest pass
  • clippy/fmt/tsc clean

Copilot AI review requested due to automatic review settings April 20, 2026 21:02
@github-actions github-actions Bot added rust Rust/Tauri changes typescript Frontend/TypeScript changes size/m 100-500 lines changed labels Apr 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 81.66667% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
apps/desktop/src-tauri/src/sidecar_supervisor.rs 0.00% 22 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds foundational fields and helpers for unified cross-platform message ordering (snap-based effective timestamps + stable tie-break sequencing) to support future unified feed interleaving and optimistic send (issue #88).

Changes:

  • Extend UnifiedMessage / frontend ChatMessage with effective_ts and arrival_seq.
  • Add snap-rule helper (compute_effective_ts, SNAP_WINDOW_MS) and stamp effective_ts during batch parsing.
  • Assign monotonic arrival_seq in the drain loop before emitting message batches; update tests accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apps/desktop/src/stores/chatStore.ts Mirrors new ordering fields on the frontend ChatMessage type with usage guidance.
apps/desktop/src/stores/chatStore.test.ts Updates test message factory to include the new fields.
apps/desktop/src-tauri/src/sidecar_supervisor.rs Introduces drain-loop-owned arrival sequence counter and stamps batches before emitting.
apps/desktop/src-tauri/src/message.rs Adds effective_ts/arrival_seq to UnifiedMessage, snap-rule helper, and unit tests.
apps/desktop/src-tauri/src/host.rs Stamps effective_ts in parse_batch and adds a unit test for the snap behavior.

Comment thread apps/desktop/src-tauri/src/sidecar_supervisor.rs Outdated
@ImpulseB23 ImpulseB23 merged commit 20a7e63 into main Apr 20, 2026
13 checks passed
@ImpulseB23 ImpulseB23 deleted the feat/unified-ordering branch April 20, 2026 22:23
ImpulseB23 added a commit that referenced this pull request Apr 20, 2026
Closes #88. Stacked on #93.

Adds an optimistic-send path so locally-authored messages render the
moment the user hits Enter, without waiting for the platform echo
round-trip.

**Frontend (chatStore)**
- ChatMessage gains optional status (pending|failed), local_id,
error_message
- New API: insertPending, confirmPendingId, failPending, retryPending,
plus messageRevision signal for in-place mutation
- Reconcile incoming echo against pending tail by id (after confirm) or
fingerprint (platform + username + text + 30s window)
- Pending arrival_seq sourced from MAX_SAFE_INTEGER - 1M base so they
sort to tail in any future cross-platform sort layer
- buildOptimisticMessage helper builds the pending entry from {platform,
login, text}

**Frontend (UI)**
- MessageInput now takes the user login, builds optimistic, inserts,
then sends; on success calls confirmPendingId, on failure calls
failPending
- ChatFeed subscribes to messageRevision and clears its prepared-layout
cache on bump; pending entries render at 0.55 opacity, failed entries
get a red left-border + click-to-retry
- twitchAuth.sendMessage now returns Promise<{ message_id }>

**Backend**
- twitch_send_message returns Result<SendChatOk, SendCommandError> with
the Helix message_id so the frontend can swap the local id for the
authoritative one before the echo arrives

**Tests**
- 11 new chatStore tests cover insertPending, reconcile-by-id,
reconcile-by-fingerprint, fingerprint window expiry, cross-platform
isolation, failPending, retryPending state machine, scan-tail bound,
multi-pending ordering
- All 73 vitest tests + 187 cargo tests pass;
clippy/fmt/tsc/eslint/prettier clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Rust/Tauri changes size/m 100-500 lines changed typescript Frontend/TypeScript changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants