Skip to content

Fix study session persistence and add recovery tests#26

Closed
geokoko wants to merge 7 commits intofix/icons-planner-reload-bugsfrom
fix/study-session-persistence-and-restore
Closed

Fix study session persistence and add recovery tests#26
geokoko wants to merge 7 commits intofix/icons-planner-reload-bugsfrom
fix/study-session-persistence-and-restore

Conversation

@geokoko
Copy link
Copy Markdown
Owner

@geokoko geokoko commented Mar 28, 2026

Fix study session persistence and add recovery safeguards

Description

A bug was reported where study sessions and other recent changes could appear saved in the UI but were not reliably durable in the local database file. In the reported flow, the app later uploaded or reloaded a stale database snapshot, which caused the missing data to reappear as lost after restart or cross-device sync.

This PR hardens the local persistence and Drive sync flow around study sessions, improves recovery/visibility of active and incomplete session state, and adds regression coverage for the affected paths.

What changed

  • hardened study-session persistence after start, completion, deletion, and related goal updates
  • amended the shutdown/upload flow so Drive upload happens from a durable DB state
  • hardened manual Drive upload/local-save behavior around the affected persistence path
  • improved UI reload behavior so Drive downloads are reflected on the first attempt
  • prevented planner refresh from overwriting in-progress session notes
  • restored active sessions even when they span midnight, while keeping the session logged under its original start date
  • added regression tests covering:
  • session start/end persistence
  • incomplete-session recovery
  • active-session recovery across day boundaries
  • shutdown/manual-upload durability ordering

Why

The goal is to prevent cases where the UI implies a session was saved, but the local database file or uploaded Drive snapshot does not actually contain the latest committed session state.

Testing

  • added persistence-focused automated tests for study-session recovery and Drive durability paths
  • verified:
    • ./gradlew compileJava
    • ./gradlew test --tests com.studysync.integration.drive.GoogleDriveServiceTest --tests com.studysync.domain.service.StudyServicePersistenceTest --tests com.studysync.config.DatabaseReloadServiceTest

@geokoko geokoko self-assigned this Mar 28, 2026
@geokoko geokoko marked this pull request as ready for review April 3, 2026 12:38
@geokoko geokoko force-pushed the fix/study-session-persistence-and-restore branch from 8804a1f to cee0980 Compare April 3, 2026 20:53
@geokoko
Copy link
Copy Markdown
Owner Author

geokoko commented Apr 3, 2026

Manual soak-test plan before merging into the parent PR

Goal:

Validate that recent persistence/sync fixes hold up under normal usage, suspend/resume, cross-device sync, UI refreshes, and overnight active-session recovery.

Scenarios to verify

  • Normal local persistence: start/end a study session, close the app, reopen, confirm the session is still there.
  • Save locally + restart: make session/goal/task changes, use “Save Locally”, reopen, confirm changes persist.
  • Push to Drive + cross-device sync: make changes on one device, use “Push to Drive & Exit”, load on the second device, confirm latest data appears.
  • Suspend/resume next-day flow: make changes, suspend laptop, resume next day, confirm UI still shows them, push to Drive, verify on second device, then reopen laptop and confirm nothing disappeared.
  • Manual Drive upload: make changes, use “Sync to Drive now”, verify from restart or second device that latest data was uploaded.
  • Manual Drive download visibility: change data from another device, click “Download from Drive” once, confirm UI updates immediately and no second click is needed.
  • In-progress note preservation: start a session, type notes, switch tabs / trigger refresh, confirm notes are not overwritten.
  • Active session across midnight: start before midnight, end after midnight, confirm the session stays logged under the original start date.
  • Active session recovery across midnight: start before midnight, reopen/refresh after midnight before ending, confirm the active session is recovered and a second active session cannot be started.
  • Incomplete-session recovery: leave a session active/incomplete, restart or reload, confirm it remains visible and recoverable.
  • Goal/task/project durability regression: create/edit/delete goals, tasks, and project sessions, restart, confirm changes persist locally and sync correctly if Drive is involved.

Record for each test:

  • date/time
  • device
  • whether Drive sync was involved
  • whether this was restart vs suspend/resume
  • pass/fail
  • relevant log lines if anything fails

Merge only if:

  • no reproduced data-loss case
  • no double-click needed for Drive download reload
  • no note loss during refresh
  • no duplicate active-session possibility after midnight recovery
  • cross-device sync stays consistent over several days of normal usage

@geokoko
Copy link
Copy Markdown
Owner Author

geokoko commented Apr 9, 2026

Soak-test update as of 2026-04-09

Passed:

  • normal local persistence
  • save locally + restart
  • push to Drive + cross-device sync
  • suspend/resume next-day flow
  • manual Drive upload
  • in-progress note preservation during refresh
  • active session across midnight
  • active session recovery across midnight
  • goal/task/project durability regression checks

Still failing:

  • Manual Drive download visibility: one click does not always fully refresh the UI; sometimes a second click is still needed.

Not yet tested:

  • incomplete-session recovery after restart/reload

Conclusion:

  • the original data-loss/persistence scenarios appear fixed in manual testing
  • the branch is not ready to merge into the parent PR yet because the Drive-download UI refresh issue is still unresolved

@geokoko
Copy link
Copy Markdown
Owner Author

geokoko commented Apr 19, 2026

Superseded by #28. Closing this PR in favor of the rewrite branch, which replaces the hot-reload approach with staged Drive download/apply and verified upload guards.

@geokoko geokoko closed this Apr 19, 2026
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.

DB reload-from-Drive procedure needs to be run twice for the new data to show up Database download from drive does not work as expected

1 participant