Skip to content

feat(conversations): record read acks and report read state - #1323

Open
RonenMars wants to merge 1 commit into
mainfrom
feat/unread-read-state
Open

RonenMars wants to merge 1 commit into
mainfrom
feat/unread-read-state

Conversation

@RonenMars

Copy link
Copy Markdown
Owner

What

First streamer half of the unread dot, tracked in #1296.
Plan: #1295
A client acks the range of replies it put on screen, and the server records read state per message, shared by every paired device.

  • PUT /api/conversations/:id/read takes { from, through } (ISO, inclusive).
    The server expands the range from its own index, countable replies only, skips already-acked messages, and caps one request at 500 so a resend always progresses.
    Acks are first-wins, then the read point advances over the unbroken acked prefix; messages sharing a timestamp are all-or-nothing.
  • read_state_changed is broadcast only when at least one ack was new.
  • Read state is in runtime.db (migration 012), so it survives a restart and cache clear.
    A baseline row recorded once by the migration makes every pre-existing conversation read as read.
  • The cache index gains counts_for_unread and last_countable_ts (migration 032), refreshed on every ingest path.
  • /api/info reports readState: true.

Not in this PR

List, message and session_update decoration (unread, readThrough, readAt) is the next streamer change.
readState: true is advertised before that exists, so mobile must wait for a release that carries both.

Deviations from the plan

  • Migration numbers are 032 and 012 (the plan says 030 and 010).
  • last_countable_ts is refreshed from the index (MAX(ts) over a partial index) after each index write, instead of in updateMetaBatch.
  • The isThinking guard is dropped from the countable rule: a thinking-only line has no text, and a line with thinking and text is still a reply.

Verification

  • Lint passes.
  • Full suite: 4810 passed, 4 failed. The same four fail on main at 2bb24ec (server.test.ts reaping test, three deploy-prune-builds pid-host tests).
    One more failure in recursive-jsonl-watch passed on rerun, and runtime-store.test.ts needed the new migration added to its list, which is included.
  • 25 new tests plus server-identity, written first.
  • Mutant check: every changed line killed except two accepted equivalents (an unreachable baseline fallback, and the resolver fallback, which production never takes).

A client acks a transcript-time range with PUT /api/conversations/:id/read.
The server expands the range into per-message rows from its own index, records them first-ack-wins, and advances a monotonic per-conversation read point over the unbroken acked prefix.
Read state lives in runtime.db, so it survives a restart and a cache clear.
Conversations that existed before the upgrade read as read, through a baseline recorded once by the migration.
The cache index gains counts_for_unread and last_countable_ts so the route can tell which replies are countable.
read_state_changed is broadcast when an ack was new, and /api/info reports readState.
List, message and session_update decoration follows in a separate change, so clients should wait for a release that carries both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant