Skip to content

#981 Page Home sessions and roll up busy sub-agents off the main thread - #984

Merged
ivanfenenko merged 2 commits into
mainfrom
fix/981-home-paged-session-loading
Nov 5, 2026
Merged

ivanfenenko merged 2 commits into
mainfrom
fix/981-home-paged-session-loading

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Home froze on large projects. The live session list downloaded every session (v2 followed every cursor page; v1 took the server's 100-row default including sub-agent children), and every status or list event rebuilt each row's family on the main thread: O(roots × sessions × depth). This PR changes how Home loads and rolls up sessions, on both apps and both protocols.

  • Roots-only window: Home asks for the 50 newest roots in one request (v1 roots=true&limit, v2 parentID=null&archived=false&order=desc&limit). The window grows by 50 when the list scrolls near its end, and a skeleton row shows while the next page loads. Every refetch (events, reconnect, pull to refresh) asks for the current window size in one request. The full listSessions stays for its other callers.
  • Roll-up from the busy set: a busy sub-agent marks its root "working" through a per-profile session ancestry. The ancestry learns parent links from loaded windows and fetches unknown parents one session at a time, at most 8 levels up, caching each result (failed lookups wait 60 s before a retry). A busy root outside the window still appears on Home until its family is idle. Cost is O(busy × depth) instead of O(roots × sessions).
  • Off the main thread: Android builds rows on Dispatchers.Default with conflate(); iOS builds them in a detached task and drops stale results. Only the state assignment runs on main.
  • Counts removed: session counts are gone from the Home dock, the project picker and the Worktrees screen (rows, actions sheet, remove dialog). Running counts stay.
  • Unread: Done/Failed only shows for rows in the loaded window.

Checks

Low-end Android (Galaxy A15, Helio G99, 4 GB) running the release-like benchmark build against the scenario harness (opencode v2 dev, about 9,000 sessions: 901 roots and 8,101 sub-agents), with live load of 4 prompts every 1.5 s:

Before After
One Home update 6.6–8.0 s on main 5 ms on average, 25 ms at most, off main
Frames during load 234 rendered, 50% janky, median 1.4 s 2,086 rendered, 5% janky, median 13 ms
Input during load the app couldn't report its view tree (swipes failed) all swipes went through

At 3,000 sessions, main already spent about 0.7 s per update (121 s of main-thread work in a 136 s run).

  • Android: ./gradlew :app:testDebugUnitTest (3,402 tests, 0 failures) and :app:assembleDebug pass after the rebase. ktlint still fails on existing violations; the new code adds none except two lines indented to match the surrounding call.
  • iOS: the full unit-test target passes (3,368 Swift Testing tests, 101 XCTest cases). The grandchild roll-up test was flaky; it now waits for its real end state and passed 10 runs in a row.
  • Real apps against the harness:
    • Android v2 on the Galaxy A15: paging grew 50 → 500 rows, and a busy grandchild of the oldest root was fetched up its parent chain and merged into the rows.
    • iOS v2 and v1 on the simulator: paging works, and on v1 a busy grandchild shows its root as Running.
    • On v1 the old default list returned 100 rows, 93 of them children, so Home showed only 7 sessions. The window now returns 50 roots.

Evidence

Screenshots in the evidence comment (harness data only).

Issue

Fixes #981

Risks / Follow-ups

  • Not checked on screen: Android on v1 (covered by unit tests; the device was locked).
  • Session Chat's permission and question panels still fetch the full session list when a request comes from an unknown sub-agent (SessionChatInbox). Separate follow-up.
  • v2 still lists the whole project once per added worktree path. That's cheap now with one page each, but it's still a duplicate request.
  • The window never shrinks. After scrolling to 500 rows, refetches ask for 500 (same as the official v1 web client).
  • Each newly busy sub-agent costs one or two single-session lookups (each cached after the first fetch); about 300 during a heavy load run.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Changes core Home data loading, live-store refresh, and activity roll-up across v1/v2; behavior is heavily tested but affects the primary session list path.

Overview
Fixes Home freezing on large projects by loading sessions in windows instead of full lists or multi-page v2 cursors. Home now uses listRootSessionsWindow (50 roots per page on v1/v2), SessionLiveStore.loadMore grows the window on scroll, and SessionListSnapshot.hasMore drives infinite scroll with a footer skeleton.

Busy sub-agent roll-up no longer walks every listed session: SessionAncestry learns parent links from windows and fetches missing parents one at a time; SessionActivitySnapshot.homeActivityByRoot picks the status row per root; HomeSessionRows merges the window with active roots outside it. Row assembly runs off the main thread via observeHomeRows / homeRowsDispatcher.

UI/product: scope tabs use hasSessions instead of session counts (dock, picker, worktrees, strings). Filter empty-state logic and gallery/tests follow the same model.

Reviewed by Cursor Bugbot for commit 9484edb. Bugbot is set up for automated code reviews on this repo. Configure here.

Home's live session list downloaded every session of a project (v2 followed
every cursor page; v1 took the server's 100-row default including children)
and rebuilt each row's family on the main thread for every status or list
event. With thousands of sessions that blocked the main thread for seconds.

- Load Home as a roots-only window: 50 newest roots in one request
  (v1 roots=true&limit, v2 parentID=null&archived=false&order=desc&limit),
  growing by 50 when the list nears its end. Every refetch asks for the
  current window size; full listSessions stays for other callers.
- Roll a busy sub-agent up to its root from the busy set only. A per-profile
  session ancestry learns parent links from loaded windows and fetches
  unknown parents one session at a time; busy roots outside the window
  join Home until their family is idle.
- Build Home rows off the main thread (Android Default dispatcher with
  conflation, iOS detached task) and apply only the result on main.
- Drop session counts from the Home dock, project picker and Worktrees
  screen; running counts stay. The load-more footer is a skeleton row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Android (Galaxy A15, benchmark build) and iOS (simulator, Debug) against the scenario harness with seeded fixture sessions. v2 = opencode dev, v1 = opencode 1.19.5.

Android iOS
Home dock without session counts (v2, ~9,000 sessions) Android Home without counts iOS Home without counts
Busy grandchild rolls up to its root (v1; the list loads roots only) Not captured (device locked); covered by unit tests iOS root shows Running from a busy grandchild

Performance numbers (before/after on the Galaxy A15) are in the PR description.

@ivanfenenko
ivanfenenko marked this pull request as ready for review November 5, 2026 08:07
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review: no finding that 2+ of 3 passes agreed on.

10 finding(s) from a single pass, not posted
  • android/app/src/main/java/dev/opencode/mobile/ui/main/HomeSessionRows.kt:40 high: empty parentId roots dropped from rows (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/UI/Main/HomeSessionRows.swift:31 high: empty parentID roots dropped from rows (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/session/V1SessionRemote.kt:32 medium: hasMore misses servers that return more than limit (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Session/SessionWindow.swift:17 medium: hasMore misses replies larger than limit (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/live/DefaultSessionLiveStore.kt:109 medium: failed loadMore permanently inflates window (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/domain/live/SessionAncestry.kt:179 medium: fetch accepts session with wrong id, retry storm (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/UI/Main/ProjectListHomeViewModel.swift:2296 medium: First-load row build skipped when status and ready streams already emitted, leaving the load skeleton stuck (glm-5.3-flash)
  • ios/OpenCode Mobile/OpenCode Mobile/UI/Main/ProjectListHomeViewModel.swift:2453 medium: Load-more on a worktree scope pages sibling worktrees and shows a footer for rows that are not displayed (deepseek-v4.1-flash)
  • android/app/src/main/java/dev/opencode/mobile/domain/session/SessionModels.kt:520 low: homeActivityByRoot tie-break between two non-root busy sessions is non-deterministic (glm-5.3-flash)
  • android/app/src/main/java/dev/opencode/mobile/ui/main/MainScreenViewModel.kt:1895 low: Unresolvable Home scope pages every observed directory (deepseek-v4.1-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.158 · 1 pass(es) stopped early

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9484edb. Configure here.

The Home list asked for older sessions only from a near-end row, so an
empty worktree filter never paged, and a window that turned hasMore
after a cache seed with the same rows did not ask again until a scroll.
The list now treats no rows as its end and samples again when more
becomes available or a load ends. A filter with no rows yet but more to
load shows its loading placeholder. A window whose refresh failed stops
paging until a refresh succeeds, so the list never retries in a loop.

Renames the Android remove-worktree note to worktrees_remove_sessions_stay
to match the iOS key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko merged commit 8adeb61 into main Nov 5, 2026
@ivanfenenko
ivanfenenko deleted the fix/981-home-paged-session-loading branch November 5, 2026 10:18
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.

Android ANR: SessionFamily.resolveRoot/memberIds on main thread (1.4.0 (37))

1 participant