One function

_pages_for_segment in nossa-y/activity-frames

The author described this change as fix(frames): fix page count misattribution on revisit-then-dwell (#31) (#33). It counts as a record because the check below fails on the code as it stood at f8ef36c9c and passes on 465d8d9b0, with nothing else changed between the two runs.

Fix saved2026-08-01
Sharing licenceMIT · LICENSE
Change size+1 8

What the code was meant to do, written into the code itself as a docstring

Aggregate URL views in a segment into typed page references.

The change

11 def _pages_for_segment(seg: Segment) -> list[PageView]:
2- """Aggregate consecutive URL views into typed page references."""
2+ """Aggregate URL views in a segment into typed page references."""
33 views: list[PageView] = []
44 index: dict[tuple[str, str | None], PageView] = {} # O(1) duplicate lookup
5- last_key: tuple[str, str | None] | None = None
65 for f in seg.frames:
76 if not f.url:
87 continue
98 ref = parse_url(f.url)
109 key = (ref.kind, ref.entity)
11- if last_key == key and views:
12- views[-1].count += 1
13- continue
14- # Re-visit of an earlier page in the same segment: bump it instead
15- # of appending a duplicate entry.
1610 existing = index.get(key)
1711 if existing is not None:
1812 existing.count += 1
2014 pv = PageView(kind=ref.kind, entity=ref.entity, count=1)
2115 views.append(pv)
2216 index[key] = pv
23- last_key = key
2417 return views

The check that tells the two apart

failpass·tests/test_frames_emit.py::test_pages_for_segment_revisit_then_dwell

Check file tests/test_frames_emit.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf8ef36c9c2f387a9b7bed1cb1b95b55cc773473f
Broken version dated2026-08-01
Moduleactivity_frames.frames
Units changed_pages_for_segment
Fingerprintc0e4cbcd39c64f0e
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.