Fix: Sleep score not shown on app relaunch after extended background#20
Draft
Copilot wants to merge 3 commits into
Draft
Fix: Sleep score not shown on app relaunch after extended background#20Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
HomeSummary and its child structs are now Codable. HomeSummaryStore seeds summary from UserDefaults when the in-memory cache is cold (on app relaunch), and writes through to UserDefaults in cacheSummary() so every score source (month-cache, direct fetch, historical sync, polling) is persisted. The month-cache path in load() now calls cacheSummary() so those summaries are also durably stored." Co-authored-by: austinkimchi <40729751+austinkimchi@users.noreply.github.com> Agent-Logs-Url: https://github.com/SleepFocus/SleepFocus_Frontend/sessions/9c610f16-b098-4e0f-96c7-8f8dc2bf14d3
Copilot
AI
changed the title
[WIP] Fix bug where sleep score is missing after app relaunch
Fix: Sleep score not shown on app relaunch after extended background
Mar 21, 2026
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.
HomeSummaryStorecached sleep scores in memory only. After iOS terminates the app (memory pressure, extended background), that cache is gone — the score shows "–" until a fresh API round-trip completes, and any network failure leaves it permanently missing.Changes
Models/HomeSummary.swiftHomeSummary,SleepQualitySummary,FocusPredictionSummary,CircadianRhythmSummary, andProcessingSummaryfromDecodable→Codableto enable encoding for UserDefaults storage.Services/HomeSummaryStore.swiftpersistSummary(_:for:)/loadPersistedSummary(for:)— write/read JSON-encodedHomeSummarytoUserDefaultskeyed by date string (homeSummary.yyyy-MM-dd).cacheSummary()write-through — every path that updates the in-memory cache (direct fetch, month-cache, historical sync, polling) now also persists toUserDefaults.load()— seedssummaryfromUserDefaultsbefore any network I/O, so the last-known score is visible instantly on relaunch:The month-cache path in
load()now also callscacheSummary()so bulk-fetched monthly summaries are persisted — previously they bypassedcacheSummary()entirely.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.