Skip to content

fix(mobile): track accepted live query outcomes - #5649

Merged
iscekic merged 4 commits into
mobile-live-loading-2be5from
mobile-live-loading-2be5-s2
Sep 1, 2026
Merged

iscekic merged 4 commits into
mobile-live-loading-2be5from
mobile-live-loading-2be5-s2

Conversation

@iscekic

@iscekic iscekic commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Live sessions appear only after sign-in and organization selection finish, and no longer remain visible during sign-out.
  • Refreshing live sessions only reports success after fresh results arrive for the selected organization.
  • After you switch accounts, earlier rename or delete actions no longer change the new account's lists, show old notices, or sign it out.
  • Exiting a live session refreshes only the current personal or organization list. That refresh cannot carry over when you switch organizations or accounts.

Maintainer changelog

ActiveSessionsQueryMetadata records acceptedRevision and retryable/non-retryable terminalError for activeSessions.list; old or manually written data does not establish accepted success.
captureActiveSessionsQueryRefresh checks query identity and a newer revision; fenceActiveSessionsQuery rejects results when their account or attachment expires.
createKiloAppQueryClient installs the observer; getActiveSessionsQueryMetadata and subscribeActiveSessionsQueryMetadata expose metadata, with activeSessionsQueryKeySchema limiting which keys qualify.

Files
  • apps/mobile/src/lib/query-client.ts — Source; modified; 127 changed lines. Keys metadata and listeners by Query without changing session payloads. Accepted responses increment the revision and clear errors; manual writes and cancellation preserve metadata. Query removal resets metadata, while the client-lifetime observer survives cache clearing. Adds terminal error classification, identity/revision capture, and cancellation fences before and after responses.
  • apps/mobile/src/lib/query-client.test.ts — Test; modified; 221 changed lines. Updates the query-client suite.

refreshActiveSessionsNow and ActiveSessionsLiveSync.refreshNow now require a QueryKey; false means no matching owner, while { accepted: boolean } reports handled completion.
Acceptance requires a newer server result for the exact query, current account, and current attachment; cancelled replacements remain pending.
LiveSyncQueryClient now requires a full QueryClient; callers must supply their scope and must not start a fallback fetch after a handled failure.

Files
  • apps/mobile/src/lib/active-sessions-live-sync.ts — Source; modified; 219 changed lines. Copies owner options, guards writes and refreshes by account and attachment, and cancels only the exact query. Fetches wait for queued writes; manual refresh follows replacement fetches. Only accepted results clear pending reasons; failures retain them for retry.
  • apps/mobile/src/lib/active-sessions-live-sync.attention.test.ts — Test; modified; 4 changed lines. Updates the attention suite.
  • apps/mobile/src/lib/active-sessions-live-sync.manual-refresh.test.ts — Test; modified; 67 changed lines. Updates the manual refresh suite.
  • apps/mobile/src/lib/active-sessions-live-sync.pending.test.ts — Test; modified; 8 changed lines. Updates the pending-reasons suite.
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts — Test; modified; 96 changed lines. Updates the race suite.
  • apps/mobile/src/lib/active-sessions-live-sync.reconnect.test.ts — Test; modified; 8 changed lines. Updates the reconnect suite.
  • apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts — Test; modified; 202 changed lines. Updates the shared live-sync test helper.
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts — Test; modified; 38 changed lines. Updates the live-sync suite.

useActiveSessions shares exported UseAgentSessionsOptions with useAgentSessions, exposes queryKey/canRead, and gates reads and socket leases on authentication and organization readiness.
useLiveAgentSessions adds hasAcceptedSuccess, terminalError, isFetching, and isPaused; its boolean refetch confirms a new accepted response rather than a successful cache state.
Legacy flags remain available; account changes block cached active rows and departure reconciliation, while obsolete organization scopes and unmounted callers cannot confirm refresh success.

Files
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx — Source; modified; 115 changed lines. Centralizes guarded reads and exact-scope refreshes, preserving 30-second connected polling, 10-second disconnected polling, and five-second freshness. Authentication and organization readiness control socket leases; epoch, scope, query identity, and unmount checks fence completion. A handled failure does not trigger the plain-query fallback.
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts — Source; modified; 120 changed lines. Exports shared options, subscribes to query metadata, and hides unreadable active rows and history exclusion IDs. Tracks departure IDs by account epoch and guards deferred history resets; both consumers delegate active refresh to the shared hook.
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx — Test; added; 307 changed lines. Adds a mounted combined-session suite.
  • apps/mobile/src/lib/hooks/use-agent-sessions.live.mounted.test.tsx — Test; modified; 427 changed lines. Updates the mounted live-session suite.
  • apps/mobile/src/lib/hooks/use-agent-sessions.test.ts — Test; modified; 5 changed lines. Updates the session-hook suite.

useSessionMutations binds rename and delete work to its starting authentication epoch without changing cliSessionsV2.rename or cliSessionsV2.delete inputs.
After account changes, queued requests, late outcomes, optimistic writes, rollbacks, toasts, deletion callbacks, and deferred invalidation stop affecting the new account.
renameSessionAsync keeps its rejecting promise contract, while current-account edits retain per-session sequencing, optimistic updates, and latest-generation rollback.

Files
  • apps/mobile/src/lib/hooks/use-session-mutations.ts — Source; modified; 245 changed lines. Stores operation epochs beside mutation inputs in a WeakMap and checks them across asynchronous boundaries. Fences both mutation outcomes before global authentication callbacks, suppresses stale side effects, and retains current-account error handling and deletion announcements.
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts — Test; modified; 640 changed lines. Updates the session-mutation suite.

RemoteSessionRow limits exit-triggered refreshes to the selected organization and the current query instance, rather than refreshing every cached context.
refreshActiveSessionsNow receives that exact QueryKey; only an unhandled request permits the fallback invalidation.
Account changes, unresolved organization selection, unmounting, and replaced queries suppress obsolete completion work.

Files
  • apps/mobile/src/components/agents/remote-session-row.tsx — Source; modified; 42 changed lines. Replaces prefix invalidation with exact invalidation after an unhandled owner refresh. Checks organization readiness, row lifetime, query identity, and account epoch before refreshing or falling back.
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx — Test; added; 267 changed lines. Adds a mounted remote-row suite.

Tests: 13 changed files (12 suites, 1 helper), with 2 additions, 11 modifications, and 2,290 changed lines.
Generated: none (0 changed files).


Verification

Local end-to-end verification on an iOS simulator, 2026-09-01. Four of six checks passed. Two have no verdict.

This section covers the stack's three PRs together: #5641, #5649, and #5652.

No product bug was found. No product source changed. The worktree stayed clean.

Check Result Evidence
Existing live content stays visible during loading, reconnect, and recoverable errors PASS 56-live-recoverable-error.png
Task creation and account tools stay usable during live loading and errors PASS 50-create-ready-during-live-load.png
PR Review opens while membership queries wait on a lock PASS 32-pr-review-org-pending.png
Refresh stays pending until fresh results arrive PASS 48-refresh-fresh-result.png
History loads independently of live sessions NO VERDICT see below
Unresolved organization selection gates the live query NO VERDICT see below

Why two checks have no verdict

Both gaps are test-harness limits, not defects.

  • History isolation. The history query and the live query both read cli_sessions_v2 and github_branch_pull_requests. No table belongs to history alone, so a table lock delays live loading too and cannot isolate the history request. A request-specific delay on cliSessionsV2.list would close this.
  • Organization selection. The stored selection loads through local SecureStore.getItemAsync at apps/mobile/src/lib/organization-context.tsx:45. A backend lock cannot delay or fail a local keychain read, so no fault seam exists for this timing.

Setup

  • Real worktree stack and Metro, with the app built and installed on the simulator.
  • Signed in through the normal email-code screen. Delays came from bounded PostgreSQL transactions on named tables.
  • Screenshots captured with xcrun simctl io <udid> screenshot. Full report and images: /Users/igor/Projects/.scratch/local-e2e-live-loading/.

@kilo-code-bot

kilo-code-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

Organization switches can be treated as live-session departures and empty every cached history list.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/mobile/src/lib/hooks/use-agent-sessions.ts 315 Org switches look like departures and empty all history lists
Files Reviewed (21 files)
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts - 1 issue
  • apps/mobile/src/lib/hooks/use-agent-sessions.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.live.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-session-mutations.ts
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts
  • apps/mobile/src/lib/query-client.ts
  • apps/mobile/src/lib/query-client.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.ts
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts
  • apps/mobile/src/lib/active-sessions-live-sync.manual-refresh.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.pending.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.reconnect.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.attention.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx
  • apps/mobile/src/components/agents/agents-tab-badge.mounted.test.tsx
  • apps/mobile/src/components/agents/agents-tab-badge.test-helpers.ts

Fix these issues in Kilo Cloud

Previous Review Summaries (5 snapshots, latest commit cf5e3c9)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit cf5e3c9)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (19 files)
  • apps/mobile/src/lib/query-client.ts
  • apps/mobile/src/lib/query-client.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.ts
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts
  • apps/mobile/src/lib/active-sessions-live-sync.manual-refresh.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.pending.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.reconnect.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.attention.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.live.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-session-mutations.ts
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx

Previous review (commit 43168e4)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (19 files)
  • apps/mobile/src/lib/query-client.ts
  • apps/mobile/src/lib/query-client.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.ts
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts
  • apps/mobile/src/lib/active-sessions-live-sync.manual-refresh.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.pending.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.reconnect.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.attention.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.live.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-session-mutations.ts
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx

Previous review (commit ee2ef4f)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • apps/mobile/src/lib/hooks/use-session-mutations.ts
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.attention.test.ts
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx

Previous review (commit 2b65e3a)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx

Previous review (commit 107bd3c)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (18 files)
  • apps/mobile/src/lib/query-client.ts
  • apps/mobile/src/lib/query-client.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.ts
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts
  • apps/mobile/src/lib/active-sessions-live-sync.manual-refresh.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.pending.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts
  • apps/mobile/src/lib/active-sessions-live-sync.reconnect.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.test.ts
  • apps/mobile/src/lib/hooks/use-agent-sessions.live.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx
  • apps/mobile/src/lib/hooks/use-session-mutations.ts
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts
  • apps/mobile/src/components/agents/remote-session-row.tsx
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx

Reviewed by grok-4.6 · Input: 241.4K · Output: 25K · Cached: 1.5M

Review guidance: REVIEW.md from base branch mobile-live-loading-2be5

@iscekic iscekic added human-ready The PR is ready for human review. and removed human-ready The PR is ready for human review. labels Aug 29, 2026
@iscekic
iscekic force-pushed the mobile-live-loading-2be5-s2 branch from ee2ef4f to 43168e4 Compare August 30, 2026 00:22
@iscekic iscekic added the human-ready The PR is ready for human review. label Sep 1, 2026
@iscekic
iscekic force-pushed the mobile-live-loading-2be5-s2 branch from dc86832 to cf5e3c9 Compare September 1, 2026 11:04
@iscekic
iscekic force-pushed the mobile-live-loading-2be5-s2 branch from cf5e3c9 to 005fd98 Compare September 1, 2026 11:56
@iscekic
iscekic merged commit 544a35d into main Sep 1, 2026
24 of 44 checks passed
@iscekic
iscekic deleted the mobile-live-loading-2be5-s2 branch September 1, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants