Fix partial chat display: path encoding, reconnect safety, and JSONL parsing#108
Open
mcintyre94 wants to merge 1 commit intomainfrom
Open
Fix partial chat display: path encoding, reconnect safety, and JSONL parsing#108mcintyre94 wants to merge 1 commit intomainfrom
mcintyre94 wants to merge 1 commit intomainfrom
Conversation
…parsing
The root cause was a path-encoding mismatch: Claude Code encodes project
directories by replacing both '/' and '.' with '-', but Wisp only replaced
'/'. Worktree chats under .wisp/ had their JSONL paths computed incorrectly
(e.g. -home-sprite-.wisp-... vs the actual -home-sprite--wisp-...), so
loadRemoteHistory silently found nothing and fell back to whatever partial
state was in SwiftData.
Three fixes:
1. Path encoding (claudeProjectPathEncoding helper): replace both '/' and '.'
with '-' in all Claude project directory lookups (fetchRemoteSessions and
loadRemoteHistory). Extracted into a named static helper with tests.
2. Auto-load remote history on empty messages: reconnectIfNeeded now triggers
loadRemoteHistory when messages are empty but a sessionId is known. Guards
against concurrent calls with isLoadingHistory. This recovers the full chat
from the JSONL even if SwiftData was wiped or a prior path-encoding failure
left the chat blank.
3. Reconnect replay safety (two sub-fixes):
- Truncated service logs: if a replay completes without a system event
(logs don't start from the beginning), restore the pre-reconnect snapshot
rather than showing a partial mid-response fragment.
- No-UUID retry deduplication: on retry iterations without UUID tracking,
reset replay state before re-fetching so events aren't doubled.
4. parseSessionJSONL block-format user messages: some Claude Code versions
write user turns as [{type:text, text:...}] arrays instead of plain
strings. These were silently dropped; now treated as user messages.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
/and.with-, but Wisp only replaced/. Worktree chats (under.wisp/) had their JSONL paths computed as-home-sprite-.wisp-...instead of the actual-home-sprite--wisp-..., soloadRemoteHistorysilently found nothing and fell back to whatever partial state was in SwiftData — producing the "chat starts at 'Now let me do a quick sanity check...'" symptom.sessionIdis known, so the full chat is always recoverable even after a SwiftData loss.[{type:text}]arrays instead of plain strings) were being silently dropped.Changes
claudeProjectPathEncodinghelper (ChatViewModel.swift)/and.with-, matching Claude Code's actual on-disk encodingnonisolated statichelper used by bothfetchRemoteSessionsandloadRemoteHistoryreconnectIfNeededmessages.isEmptybutsessionId != nil, firesloadRemoteHistoryto recover the full conversation from the JSONL file on the sprite!isLoadingHistoryto prevent concurrent duplicate calls (dashboard, detail view, and background resume all call this)runReconnectLoopparseSessionJSONL[{type:\"text\", text:\"...\"}]block arrays are now treated as user messages (same as the plain-string case), not silently discardedTest plan
xcodebuild -scheme Wisp -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 17' testloadRemoteHistoryclaudeProjectPathEncodingtests pass (3 cases: standard path, worktree path with.wisp, repo path)parseSessionJSONLtests pass (block-format user messages, multi-turn, tool-result disambiguation)🤖 Generated with Claude Code