Skip to content

fix(transform): split uncertain flood gaps at midpoint - #146

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/flood-midpoint-spec
Jul 23, 2026
Merged

fix(transform): split uncertain flood gaps at midpoint#146
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/flood-midpoint-spec

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Problem

Python and Rust assign short gaps between differing-data events differently:

  • Python gave the entire gap to whichever surrounding event was longer.
  • Rust splits the gap at its midpoint.

That makes the same stored events produce different timelines depending on the server implementation. Neither side has evidence about the actual transition point; the gap exists precisely because collection did not observe it.

Decision: meet in the middle

Both rules are defensible:

  • Longer wins can be read as a local confidence heuristic: a longer observed run may be more likely to continue through the gap. It also minimizes changes to the shorter event.
  • Midpoint is neutral: it does not infer confidence from event length, is symmetric under swapping the neighbouring event durations, and keeps output consistent across Python and Rust.

I chose midpoint. Event duration is not a confidence measure; for heartbeat-derived events it often reflects batching or earlier transforms. Letting it decide an unobserved transition adds an unsupported bias and can move the boundary dramatically when one event happens to be long. Midpoint states the weaker, more honest assumption and already has an explicit Rust regression test.

Changes

  • Split positive gaps between differing-data events at the midpoint in Python.
  • Add an exact-boundary regression with unequal event lengths, so this cannot accidentally degrade into a mere no-gap assertion.
  • Update the custom-pulsetime regression and affected three-event normalization expectation.
  • Expand flood()'s API documentation into the intended behavior/spec: ordering, pulsetime boundary, same-data merging, differing-data midpoint, and overlap precedence.

The equal-data behavior remains unchanged: neighbouring equal-data events merge, preserving the longer event's extent.

Verification

  • poetry run pytest -q — 176 passed, 2 skipped
  • poetry run ruff check . — clean
  • poetry run mypy aw_transform/flood.py — clean

Follow-up to #105; incorporates the implementation parity requested in #105 (comment).

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR aligns Python flood-gap handling with the Rust midpoint behavior. The main changes are:

  • Split short gaps between differing-data events at the midpoint.
  • Preserve the existing longer-extent merge for equal-data events.
  • Document ordering, merging, gap, and overlap behavior.
  • Add exact-boundary and multi-event test coverage.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Midpoint splitting leaves each pair adjacent and preserves the right event's end time.
  • Existing normalization still resolves overlapping events.

Important Files Changed

Filename Overview
aw_transform/flood.py Adds symmetric midpoint splitting while preserving event adjacency and each right-hand event's end time.
tests/test_flood.py Updates expectations and adds exact checks for midpoint, custom-pulsetime, and three-event behavior.

Reviews (1): Last reviewed commit: "fix(transform): split uncertain flood ga..." | Re-trigger Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@ErikBjare
ErikBjare merged commit cfcc34a into ActivityWatch:master Jul 23, 2026
5 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.

2 participants