Skip to content

Bridge remaining period gap and fix data-loss in merge (follow-up to #166)#165

Merged
mapgie merged 3 commits into
mainfrom
claude/period-logging-corruption-smyc69
Jul 5, 2026
Merged

Bridge remaining period gap and fix data-loss in merge (follow-up to #166)#165
mapgie merged 3 commits into
mainfrom
claude/period-logging-corruption-smyc69

Conversation

@mapgie

@mapgie mapgie commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Context

This branch originally duplicated work that landed independently in #166 (merged), which fixed the same underlying period-logging fragmentation bug via a different, and in several respects better, approach (deferred-until-Save persistence, a one-time repair migration, merge-with-either-neighbor in History). Rather than carry two competing implementations, this PR is now rebased on top of #166 and only adds what it was still missing, found by comparing the two approaches against the exact bug report (logging day 28 → 29 → 30 fragmented into a 1-day period on the 28th, an unloggable 29th, and a new ongoing period on the 30th).

What was still missing after #166

  1. The exact reported gap pattern wasn't auto-healed. periodForDate's "day after explicit end" match reopens the earlier period for a deferred extension, but if a second, separate period already starts the following day (exactly the reported scenario), extending the first one just leaves the two touching — still two rows, still needing a manual History merge. PeriodRepository.mergeGapAt now detects a tapped date bridging a one-day gap between two distinct periods and merges them immediately, wired through HomeScreen/HomeViewModel.
  2. The one-time repair migration didn't cover this pattern either. mergeAdjacentPeriods only merged periods that were already touching (zero-day gap); it never merged periods separated by the single unlogged day this bug actually produces. Extended the gap check from "touching only" to "touching or one day apart".
  3. The merge path was deleting real data. Both the manual History merge and the migration called deleteLogsForPeriod (a helper written for actual period deletion) on the absorbed period, silently discarding its flow/symptom tracking-log history instead of preserving it. Removed those calls — that data is still valid, dated history, not orphaned by merging two period rows into one.

Changes

  • PeriodRepository: new mergeGapAt; mergeAdjacentPeriods gap check widened to 1-2 days.
  • HomeViewModel / HomeScreen: route the gap-bridging check through the existing navigation flow.
  • HistoryViewModel / GoFloApplication: removed the destructive deleteLogsForPeriod calls from both merge paths.
  • PeriodRepositoryTest: new fake in-memory PeriodDao/SymptomDao and tests for mergeGapAt and the widened mergeAdjacentPeriods gap detection.
  • LESSONS.md: consolidated the two (now-overlapping) lessons left by the parallel work into one.
  • changelog/unreleased/period-logging-gap-merge-fix.json.

Test plan

  • New unit tests in PeriodRepositoryTest pass in CI (can't run Gradle in this environment).
  • python3 a11y_check.py passes (verified locally, clean).
  • Manually verify the exact reported scenario: log day 1 (ongoing), close it with an explicit end date, log a new period 2 days later — tapping the gap day in between joins them into one period instead of requiring a manual merge.
  • Manually verify History → merge two periods → both periods' original flow/symptom entries are still visible in Stats afterward (not deleted).

https://claude.ai/code/session_01WUWr5zTAXGDw1EooCpHxfy

Logging consecutive days used to fragment into disjoint period entries
once a period's end date became fixed (e.g. via the "no end date set"
confirmation): the next day no longer fell within any existing range,
so tapping it silently started a brand-new, disconnected period with
the in-between day unloggable in either one.

PeriodRepository.resolvePeriodForLogging now checks, before creating a
new entry, whether the logged date is adjacent to an existing period's
start or end and extends it, or bridges a one-day gap between two
periods and merges them. HomeScreen routes calendar taps and the Log
Period FAB through this resolver instead of the old "covers today"-only
check.

The History tab also gains a manual "Merge with previous period" action
per card (via PeriodRepository.mergePeriods, now reusable outside the
one-time migration) so users can fix up any already-fragmented history
that predates this fix or has a gap too large to auto-detect.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUWr5zTAXGDw1EooCpHxfy
@mapgie mapgie marked this pull request as ready for review July 3, 2026 09:56
claude added 2 commits July 3, 2026 11:30
…-corruption-smyc69

# Conflicts:
#	app/src/main/java/com/mapgie/goflo/ui/screens/history/HistoryScreen.kt
#	app/src/main/java/com/mapgie/goflo/ui/screens/history/HistoryViewModel.kt
#	app/src/main/java/com/mapgie/goflo/ui/screens/home/HomeScreen.kt
#	app/src/test/java/com/mapgie/goflo/data/repository/PeriodRepositoryTest.kt
Builds on #166's fix (periodForDate day-after-end adjacency, deferred
extension, one-time migration). Two gaps remained against the exact
reported scenario (a period ending day N, an unloggable day N+1, and a
new period starting day N+2):

- periodForDate's day-after-end match only reopens the earlier period
  for a deferred extension; if a second period already starts the
  following day, extending the first just leaves them touching,
  requiring a further manual History merge. PeriodRepository.mergeGapAt
  detects this and merges both immediately when the tapped date bridges
  them, wired through HomeScreen/HomeViewModel.
- mergeAdjacentPeriods (the one-time repair migration) only merged
  already-touching periods (zero-day gap), not periods separated by
  the single unlogged day this bug actually produces. Extended its gap
  check from "touching only" to "touching or one day apart".
- Both the manual History merge and the migration were calling
  deleteLogsForPeriod on the absorbed period — a helper written for
  actual period deletion — silently discarding its flow/symptom
  tracking-log history instead of preserving it. Removed those calls;
  the data is still valid, dated history and isn't orphaned by merging.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUWr5zTAXGDw1EooCpHxfy
@mapgie mapgie changed the title Fix fragmented period logging and add History merge action Bridge remaining period gap and fix data-loss in merge (follow-up to #166) Jul 3, 2026
@mapgie mapgie merged commit 0b8ae56 into main Jul 5, 2026
4 checks passed
@mapgie mapgie deleted the claude/period-logging-corruption-smyc69 branch July 5, 2026 18:55
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.

2 participants