Skip to content

Fix time-bucket bug for advanced groups format#65

Merged
Majorfi merged 2 commits into
mainfrom
fix/issue-46
May 28, 2026
Merged

Fix time-bucket bug for advanced groups format#65
Majorfi merged 2 commits into
mainfrom
fix/issue-46

Conversation

@Majorfi
Copy link
Copy Markdown
Owner

@Majorfi Majorfi commented May 28, 2026

Summary

Closes #46. AND-group configs in advanced mode skipped the sliding-window time-bucket merge that was added in #40 for the legacy and expression code paths, so photos within delta but straddling a fixed bucket boundary failed to stack. The user reported "only 2 of 3 stacks formed" on his test set; with the same logical config expressed as an expression, all 3 stacked correctly.

Root cause

Commit d94ba48 (the #40 fix) added a post-pass call to mergeTimeBasedGroups in stackByLegacy and stackByAdvanced but NOT in stackByLegacyGroups. The bucket-division code in extractTimeWithDelta is still used by all three modes for the initial keying; the sliding-window post-pass is what recovers boundary-straddling assets, and the groups mode never ran it.

What changed

  • pkg/stacker/stacker.go: dispatcher now routes AND-only groups through stackByAdvanced (which already has the sliding-window merge). OR groups stay on the legacy connectivity-graph path because their cross-criterion union semantics aren't representable in expression OR (walkMatchingCriteria collects values only from the first matching child).
  • pkg/stacker/stacker_grouping.go: new helpers canConvertGroupsToExpression, convertGroupsToExpression, groupToExpression perform the syntactic AND-group to OR(AND,...) rewrite. Documented caveat for overlapping AND groups.
  • pkg/stacker/advanced_test.go: 3 regression tests + 4 shared helpers, placed next to the existing TestStackByLegacyGroups_UnionSemantics.

Test plan

  • go test ./... -count=1
  • go test -race ./...
  • go vet ./...
  • All existing TestStackByLegacyGroups_UnionSemantics subtests pass (OR semantics preserved)
  • Negative-test verified: temporarily neutered canConvertGroupsToExpression and confirmed the new regression test FAILS with exactly the "2 of 3 stacks" symptom from the issue

Breaking changes

None. OR groups keep the legacy code path. AND groups produce equivalent stacks (the conversion is a pure syntactic rewrite of AND group operators into expression AND nodes — same matching values, same extractors).

@Majorfi
Copy link
Copy Markdown
Owner Author

Majorfi commented May 28, 2026

Aim to fix #46

This comment was marked as outdated.

Majorfi added 2 commits May 28, 2026 12:16
Users configuring criteria in advanced groups format with AND-only operators were not receiving the sliding-window time-merge fix applied for issue #40. This caused photos straddling time-delta bucket boundaries to fail to stack.

Add dispatcher logic in StackBy to detect AND-only groups, convert them to an OR(AND, AND, ...) expression tree, and route through stackByAdvanced which includes the sliding-window merge post-pass.

Introduce helper functions:
- canConvertGroupsToExpression: Checks whether groups contain only AND operators (safe for expression conversion)
- convertGroupsToExpression: Builds expression tree from AND groups with proper handling of empty groups and single criteria
- groupToExpression: Converts single AND group to expression node

OR groups remain on the legacy connectivity-graph path since their cross-criterion union semantics are not representable in expression OR.

Change-Type: fix
Scope: stacker
Add test helpers (quietTestLogger, mustMarshalCriteria, assertContainsStack, stringSet) and three regression tests validating that AND-only groups inherit the sliding-window time-merge behavior.

Include TestStackByGroups_AndGroupsApplyTimeBucketMerge which exercises realistic Pixel Motion-Photo and DSC RAW+JPEG variants straddling bucket boundaries — the exact symptom reported in issue #46. Also test single AND group routing and verify OR groups continue using legacy union semantics.

All tests exercise the public StackBy entry point to validate the dispatcher fix end-to-end.

Change-Type: test
Scope: stacker
@Majorfi Majorfi changed the title Add file size-based parent selection for photo stacks Fix time-bucket bug for advanced groups format May 28, 2026
@Majorfi Majorfi requested a review from Copilot May 28, 2026 10:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@Majorfi Majorfi merged commit 69490da into main May 28, 2026
2 checks passed
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.

Criteria behavior inconsistent in advanced groups format and advanced expression format

2 participants