Skip to content

Unify daily dog-work status - #61

Merged
OwenTanzer merged 2 commits into
mainfrom
codex/issue-47-canonical-daily-work
Jul 22, 2026
Merged

Unify daily dog-work status#61
OwenTanzer merged 2 commits into
mainfrom
codex/issue-47-canonical-daily-work

Conversation

@OwenTanzer

Copy link
Copy Markdown
Owner

Summary

  • derive one canonical per-dog session count from the report sessionDate and local calendar date
  • show neutral, worked-once, and distinct worked-multiple-times states on dog cards, profiles, pinned dogs, and dashboard activity lists
  • limit Needs Attention to currently assigned dogs in the pinned folder with no session yesterday
  • exclude released, graduated, and transferred source dogs from Recently Worked
  • roll all derived states over automatically at local midnight

Reset behavior

The indicator remains derived-only rather than adding a manual reset override. A resettable flag could disagree with the actual logs and with backdated edits; deleting, correcting, or backdating the underlying report immediately recomputes the canonical count instead.

Validation

  • npm test (20/20)
  • npm run build
  • npx tsc -b
  • npm run lint (only three pre-existing warnings)
  • npm --prefix worker run typecheck
  • git diff --check

Closes #47

@OwenTanzer
OwenTanzer marked this pull request as ready for review July 22, 2026 15:37
@OwenTanzer

Copy link
Copy Markdown
Owner Author

daily counts are memoized against an array that is mutated in place

useDailySessionCounts() memoizes against [reports, today].

However, the store deliberately mutates nested arrays and objects in place, then only shallow-clones the outer db object to trigger rendering. In particular:

createReport() uses db.reports.push(report).
updateReport() mutates the existing report with Object.assign.
Only deletion replaces the reports array with a new array.

React therefore rerenders after an edited report, but reports still has the same reference, so the memoized count is reused. On the dog profile:

changing a log from yesterday to today may leave the dog showing not worked today;
changing today’s log to another date may leave Worked once today visible;
changing dates among multiple sessions may leave the wrong once-versus-multiple state.

That directly contradicts the PR’s stated derived-only behavior, where correcting or backdating a report should immediately recompute the canonical count.

Fix: depend on the full database snapshot rather than the nested array reference, or simply compute the inexpensive count without useMemo, for example:

export function useDailySessionCounts(): Record<string, number> {
const state = useDatabase();
const today = useCurrentLocalDate();

return useMemo(
() => sessionCountsByDogOnDate(state.reports, today),
[state, today],
);
}

A component-level regression test should simulate an in-place sessionDate edit followed by a new outer-store snapshot. The current tests validate the pure counting and assignment functions but cannot expose this React memoization failure.

Everything else is well aligned with #47: zero/one/multiple states are distinct, attention is limited to assigned dogs in the pinned folder, transferred sources are excluded, and midnight rollover is explicitly handled. CI is fully green.

@OwenTanzer

Copy link
Copy Markdown
Owner Author

Addressed in 4c6e637. I removed the memoization entirely, so useDailySessionCounts() now derives the inexpensive count from the current report contents on every database render and cannot be held stale by a stable nested-array reference. I also added a regression that keeps the same reports array/object, mutates sessionDate in place, appends in place, then backdates in place, verifying the counts transition 0 → 1 → 2 → 1. Local validation passes: 21 tests, app and worker typechecks, lint (three pre-existing warnings only), diff check, and production build.

@OwenTanzer
OwenTanzer merged commit 36886cb into main Jul 22, 2026
1 check passed
@OwenTanzer
OwenTanzer deleted the codex/issue-47-canonical-daily-work branch July 22, 2026 16:41
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.

Show which dogs have been worked today

1 participant