Skip to content

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

Open
iscekic wants to merge 3 commits into
mobile-live-loading-2be5from
mobile-live-loading-2be5-s2
Open

fix(mobile): track accepted live query outcomes#5649
iscekic wants to merge 3 commits into
mobile-live-loading-2be5from
mobile-live-loading-2be5-s2

Conversation

@iscekic

@iscekic iscekic commented Aug 28, 2026

Copy link
Copy Markdown
Contributor
  • Pull-to-refresh no longer mistakes a live update for a completed refresh; it waits for fresh session data or reports a failure.
  • Live sessions stay hidden while your sign-in details or personal or organization selection are still loading.
  • After an account switch, unfinished renames and deletions cannot change the new account's list, show old messages, or sign you out.
  • Exiting a live session refreshes only the selected personal or organization list, and delayed refreshes do not affect a different account or list.

Summary

ActiveSessionsQueryMetadata adds acceptedRevision and terminalError to each activeSessions.list Query; errors carry retryable or non-retryable kinds without changing cached responses.
Only accepted server successes advance the revision and clear failures; manual writes, socket updates, cancellation, and observer remounts preserve the metadata.
getActiveSessionsQueryMetadata and subscribeActiveSessionsQueryMetadata expose legacy entries as unconfirmed; removal resets metadata, while observation survives QueryClient.clear().

Files
  • apps/mobile/src/lib/query-client.ts — Source; modified; 127 changed lines. Adds Query metadata getters, subscriptions, revision capture, and stale-query guards without altering response envelopes.
  • apps/mobile/src/lib/query-client.test.ts — Test; modified; 221 changed lines. Updates the query-client suite.

refreshActiveSessionsNow(queryKey) and ActiveSessionsLiveSync.refreshNow(queryKey) replace the unscoped boolean contract with false | { accepted: boolean }; only false selects a fallback.
captureActiveSessionsQueryRefresh requires the same Query's newer acceptedRevision; useActiveSessions.refetch reports accepted results, while RemoteSessionRow keeps refreshes exact and ignores stale callbacks.
LiveSyncQueryClient requires a full QueryClient; fenceActiveSessionsQuery rejects stale account or attachment results while serialized cancellation, replacement waits, polling, and reconnect edges remain.

Files
  • apps/mobile/src/lib/active-sessions-live-sync.ts — Source; modified; 219 changed lines. Serializes exact cancellations and replacement fetches, fences account changes, and retains pending reasons until accepted success. Keeps copied owner inputs and enrichment throttling.
  • apps/mobile/src/lib/active-sessions-live-sync-mount.tsx — Source; modified; 115 changed lines. Shares guarded queries and refreshes; gates both socket leases on authentication and organization readiness. Preserves 30-second connected polling, 10-second disconnected polling, and five-second freshness.
  • apps/mobile/src/components/agents/remote-session-row.tsx — Source; modified; 42 changed lines. Binds exit refreshes to the mounted scope, account, organization, and Query; replaces broad invalidation with an exact key.
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx — Test; added; 273 changed lines. Adds the mounted remote-row 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-refresh suite.
  • apps/mobile/src/lib/active-sessions-live-sync.race.test.ts — Test; modified; 96 changed lines. Updates the refresh-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 helper; modified; 202 changed lines. Updates the shared live-sync test support.
  • apps/mobile/src/lib/active-sessions-live-sync.test.ts — Test; modified; 38 changed lines. Updates the main live-sync suite.

useLiveAgentSessions adds hasAcceptedSuccess, terminalError, isFetching, and isPaused; isLoading and isError remain compatible, and this level does not add the new loading presentation.
Both session hooks hide unreadable live rows; the combined hook also clears history exclusions and guards deferred departure maintenance with the account epoch.
UseAgentSessionsOptions becomes shared; useAgentSessions.refetch still returns no result while it awaits the accepted-result refresh path and serialized history refresh together.

Files
  • apps/mobile/src/lib/hooks/use-agent-sessions.ts — Source; modified; 120 changed lines. Subscribes to Query metadata, guards row publication and deferred history resets, and reuses the shared refresh path.
  • apps/mobile/src/lib/hooks/use-agent-sessions.combined.mounted.test.tsx — Test; added; 307 changed lines. Adds a mounted suite for combined sessions.
  • 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 ties deleteSession, renameSession, and renameSessionAsync to the originating account epoch without changing mutation inputs.
Stale operations cannot start queued requests, update or restore caches, invalidate lists, or publish old authorization errors, outcome messages, or deletion callbacks.
renameSessionAsync still rejects, while non-awaited calls suppress stale failures; current-account operations keep per-session sequencing, generation-checked rollback, and existing notifications.

Files
  • apps/mobile/src/lib/hooks/use-session-mutations.ts — Source; modified; 239 changed lines. Stores epochs outside request inputs and checks them across cancellation, network settlement, rollback, callbacks, and scheduled maintenance.
  • apps/mobile/src/lib/hooks/use-session-mutations.test.ts — Test; modified; 633 changed lines. Updates the session-mutation suite.

Tests: 12 changed files (11 suites, 1 helper): query-client.test.ts, remote-session-row.mounted.test.tsx, active-sessions-live-sync.manual-refresh.test.ts, active-sessions-live-sync.pending.test.ts, active-sessions-live-sync.race.test.ts, active-sessions-live-sync.reconnect.test.ts, active-sessions-live-sync.test-helpers.ts, active-sessions-live-sync.test.ts, use-agent-sessions.combined.mounted.test.tsx, use-agent-sessions.live.mounted.test.tsx, use-agent-sessions.test.ts, use-session-mutations.test.ts.
Generated: 0 files changed.


Verification

  • No manual tests ran for this level; runtime verification is pending on the stack tip.
  • The handoff supplies no passing native or hosted continuous integration (CI) verification result.

Visual Changes

Visual Changes: N/A

Reviewer Notes

Human steps

  • before merge: Wait for the final human-ready labels.
  • before merge: Complete the review.
  • before merge: Merge the stack from bottom to top. Do not merge automatically.
  • after merge: No additional setup, environment values, secrets, migrations, or cache resets are required.

Focused validation

  • The handoff reports 120 passing tests across 11 changed suites, lint and format checks for all 18 changed files, and passing whitespace checks.
  • No locale keys change in this level.

Scope and inventory

  • Repository: Kilo-Org/cloud.
  • Worktree: /Users/igor/Projects/.worktrees/mobile-live-loading-2be5.
  • Branch: mobile-live-loading-2be5-s2; base ref: mobile-live-loading-2be5.
  • Scope: level 2 only, commit 107bd3c5285a09abf5370c8edd95f3bb40baf8b2. Level 1 is cloud#5641; level 3 presentation is not implemented.
  • Total: 18 files, with 2 additions and 16 modifications; 2,167 inserted lines and 980 deleted lines.
  • The inventory contains 6 source files, 11 test suites, 1 test helper, and no generated files.
  • Each file entry gives its class, status, and changed-line count from the supplied statistics, including additions and deletions.

Notes

Runtime verification is pending on the stack tip; this level has focused test coverage only.

Stacked PRs — merge bottom to top. Each level shows only its own diff.

Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.

  1. mobile-live-loading-2be5fix(mobile): serialize development account replacement #5641
  2. mobile-live-loading-2be5-s2fix(mobile): track accepted live query outcomes #5649 ← this PR
  3. mobile-live-loading-2be5-s3fix(mobile): preserve live content during loading and reconnect #5652 (tip)

@kilo-code-bot

kilo-code-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • apps/mobile/src/components/agents/remote-session-row.mounted.test.tsx
Previous Review Summary (commit 107bd3c)

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

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: 137.9K · Output: 4.3K · Cached: 134.7K

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

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