Skip to content

#655 Sync session unread state with the server on v2 - #659

Merged
ivanfenenko merged 4 commits into
mainfrom
feature/655-sync-session-unread-state
Oct 14, 2026
Merged

ivanfenenko merged 4 commits into
mainfrom
feature/655-sync-session-unread-state

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • v2 servers: Home unread comes from the server (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.
  • Acknowledging: while Session Chat is focused on a root session, a new SessionViewReporter posts POST /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.
  • Other devices: a session.viewed event 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 sets time.idle without bumping time.updated.
  • v1: unchanged. The local per-device Ready store and the Ready pill keep working, with no new requests.
  • Both platforms use the same names: Session.idleAtEpochMs / viewedAtEpochMs / idleOutcome, isServerUnread, ServerCapabilities.supportsSessionViewed, markSessionViewed, SessionListStatus done/failed/stopped.

Checks

  • Android: ./gradlew --offline :app:testDebugUnitTest ran 2014 tests: 0 failures, 1 skipped. :app:assembleDebug passes. ktlint finds nothing on changed lines; the 316 existing violations remain.
  • iOS: xcodebuild test -only-testing:"OpenCode MobileTests" ran 1922 tests in 199 suites, all passed. The build passes.
  • Not run: a real v2 server end to end, and the iOS UI test target. In an earlier run the UI tests failed because a cloned simulator refused to launch the test runner.

Issue

Risks / Follow-ups

  • First-launch backlog: mobile never reported views before, so older v2 sessions may show as unread after the update. There is no bulk "mark all read" yet.
  • Subagent child sessions are not acknowledged. The TUI acknowledges the root when a child is viewed; here only root sessions opened directly are.
  • Retries ignore foreground state: retries aren't tied to the app being in the foreground, but each burst is short and bounded.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.

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
ivanfenenko marked this pull request as ready for review October 13, 2026 21:49

@ivanfenenko ivanfenenko left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

ivanfenenko and others added 2 commits October 14, 2026 09:33
… 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 ivanfenenko left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 as applyViewed, and viewedDuringRefreshCacheWriteSurvivesPublish covers the exact window.
  • Android unread before status seed: homeUnreadOutcome is now gated on a seeded snapshot in all three paint paths, with a test.

One small leftover on the Android gate, inline.

@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Evidence

iPhone 17 Pro simulator, this branch, against local opencode v2.0.28 at 127.0.0.1:4096.

Two throwaway root sessions in ~/Projects/oc-655-evidence. Both had time.idle set and no time.viewed. Home shows the server outcome: succeeded unread is Done, interrupted unread is Stopped.

Home before opening the succeeded session

Opening 655 evidence acknowledges that run. The server then has time.viewed == time.idle (1791968936258).

Session Chat for the succeeded session

Back on Home, that row is Idle. 655 evidence stopped was not opened (outcome: interrupted, time.idle 1791968936231, still no time.viewed), so it stays Stopped.

Home after the view

This server had no unread root session with outcome: failed, so these frames do not show a Failed pill. v1 was not part of this pass.

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]>
@ivanfenenko
ivanfenenko merged commit 8f0fd17 into main Oct 14, 2026
@ivanfenenko
ivanfenenko deleted the feature/655-sync-session-unread-state branch October 14, 2026 09:55
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