fix(app): keep live thinking state across a full session refetch - #1579
Merged
bra1nDump merged 2 commits intoJul 28, 2026
Merged
Conversation
added 2 commits
July 25, 2026 01:43
fetchSessions hardcoded `thinking: false` on every session it decoded, and applySessions overwrites rather than merges that field. The server session record has no thinking state at all — it only ever arrives via activity ephemerals — so any full refetch declared every running session idle until the next heartbeat. Preserve the thinking state already held instead of resetting it.
Preserving thinking unconditionally would make a stale `true` immortal for sessions that died mid-turn (nothing ever sends the clearing ephemeral), resurfacing on resume and re-triggering the spurious unread this change fixes. And snapshotting inside the decrypt loop left a window where an activity ephemeral landing mid-fetch was overwritten by a pre-await snapshot. Resolve the preserved values synchronously with the apply, only for sessions the server still reports active.
Contributor
Author
|
Revised after a self-review pass, two changes:
Also worth noting for review: this lives in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fetchSessions()hardcodesthinking: falseon every session it decodes, andapplySessions()overwrites rather than merges that field. The server's session record has no thinking state at all — it only ever arrives throughactivityephemerals — so any full refetch declares every running session idle until the next heartbeat.Why it's visible
Creating a session triggers exactly that refetch:
new-sessionupdate →sessionsSync.invalidate()(sync.ts:2276) →fetchSessions()→thinking: false(sync.ts:1006) →applySessions()(storage.ts:457, the spread overwrites it)Two symptoms follow, and they hit every running session, not just the one being created:
thinking.applySessions(storage.ts:600-613) reads the same thing aswasActive && isNowIdleand marks the session unread — a session that never stopped working shows the solid unread dot until you open it.Fix
Preserve the thinking state already held instead of resetting it. Genuine
thinking: falsetransitions still arrive through the activity accumulator andturn-endmessage events, which pass an explicit value; this only stops the refetch path from inventing one.Notes
Complements #1567 (unread markers dropped by rebuilds that omit
unreadSessionIds) and #1577 (unread masking a live session). Those fix how the marker is rendered and retained — this fixes a source of markers that should never have been set. No file overlap with either.Testing
pnpm typecheckand the 793-test suite pass. Verified by hand on a fork build: with several sessions running, creating a new session no longer freezes their pulsing dots or flips them to unread.No unit test — the zustand store can't be imported under vitest (react-native flow types break the transform), which is why no existing test loads it.
No screenshot: the symptom is a one-to-two second freeze of a pulsing animation, which a still frame cannot show.