Repository navigation
#655 Sync session unread state with the server on v2 - #659
Conversation
On v2 servers, Home derives unread from the session's time.idle and
time.viewed watermarks and shows how the unseen run ended (Done,
Failed, Stopped). Session Chat acknowledges the focused root session
with POST /api/session/{id}/view, and session.viewed events clear the
row on every device. v1 keeps the local per-device Ready state.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ivanfenenko
left a comment
There was a problem hiding this comment.
Nice work overall. The v1 path stays off the network, and putting the watermark merge in one place keeps REST/event races from moving read state backwards in most cases. I found two spots where a session can still show as unread, or show the wrong state, for a short time. Details inline.
… on seeded status iOS: apply viewed watermarks under the session-list loop lock at publish time, so a session.viewed landing during the refresh cache write is not overwritten by the pre-await list. Android: Home unread outcomes wait for a seeded status snapshot in every paint path, matching iOS, so a running session with an older unviewed idle does not paint Done/Failed before its status is known. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion-unread-state # Conflicts: # android/app/src/main/java/dev/opencode/mobile/ui/main/MainScreenViewModel.kt
ivanfenenko
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround. Both earlier comments are resolved in 2f869fd:
- iOS refresh race:
publish(_:applying:)now re-applies the watermarks under the same lock asapplyViewed, andviewedDuringRefreshCacheWriteSurvivesPublishcovers the exact window. - Android unread before status seed:
homeUnreadOutcomeis now gated on a seeded snapshot in all three paint paths, with a test.
One small leftover on the Android gate, inline.
EvidenceiPhone 17 Pro simulator, this branch, against local opencode v2.0.28 at Two throwaway root sessions in Opening 655 evidence acknowledges that run. The server then has Back on Home, that row is Idle. 655 evidence stopped was not opened ( This server had no unread root session with The throwaway project is still on the server. |
The cache and REST home paints carry no status label, yet they set the unread outcome from a seeded-worktree set that survived a worktree list change. Adding or removing a project could then briefly paint a running session as Done/Failed. Only the live paint sets the outcome now, gated on its own seeded snapshot, so the set is gone. Tests assert the painted status (Running after seed) and that adding a project never paints the running session as Done from cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>



Summary
time.idle > time.viewed). The status pill shows how the unseen run ended: Done (success), Failed (error) or Stopped (warning). Running/Retrying keep priority; read sessions show Idle.SessionViewReporterpostsPOST /api/session/{id}/view {idle}. It checks the server first, posts once per idle watermark, and retries after 250 ms, doubling, for at most 5 retries before waiting for the next trigger (focus, run end, reconnect). A run that finishes while the chat is open ends up viewed.session.viewedevent patches Home right away. A per-session viewed watermark stops a stale REST list from making a session unread again. A v2 run end now refetches the session list, because the server setstime.idlewithout bumpingtime.updated.Session.idleAtEpochMs/viewedAtEpochMs/idleOutcome,isServerUnread,ServerCapabilities.supportsSessionViewed,markSessionViewed,SessionListStatusdone/failed/stopped.Checks
./gradlew --offline :app:testDebugUnitTestran 2014 tests: 0 failures, 1 skipped.:app:assembleDebugpasses. ktlint finds nothing on changed lines; the 316 existing violations remain.xcodebuild test -only-testing:"OpenCode MobileTests"ran 1922 tests in 199 suites, all passed. The build passes.Issue
Risks / Follow-ups
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.