chunk_events_by_key: gap/pulsetime check is broken (events[-1] is always the last event)
I maintainer di solito rispondono entro 10 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Read aw_transform/chunk_events_by_key.py and the existing test_chunk_events_by_key tests first; reproduce the one-hour gap case from the issue. The issue leaves open whether to fix pulse semantics or remove the check to match Rust, so get that behavior decision settled before changing code. Done means the chosen behavior is covered by a gap test and the Python implementation matches that decision.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The gap check in chunk_events_by_key has never worked — events[-1] always refers to the last event of the input list, not the previous event, so the timediff computed is garbage and unrelated events get merged across arbitrarily large gaps.
Repro (aw-core master, 4496e2e):
from datetime import datetime, timezone, timedelta
from aw_core.models import Event
from aw_transform.chunk_events_by_key import chunk_events_by_key
t0 = datetime(2026, 1, 1, 10, 0, 0, tzinfo=timezone.utc)
events = [
Event(timestamp=t0, duration=timedelta(seconds=10), data={"app": "A"}),
Event(timestamp=t0 + timedelta(hours=1), duration=timedelta(seconds=10), data={"app": "A"}),
]
chunks = chunk_events_by_key(events, "app", pulsetime=5)
assert len(chunks) == 1 # BUG: gap is 1 hour, pulse is 5s
assert chunks[0].duration == timedelta(seconds=20)
Two events one hour apart get chunked into one with pulsetime=5.
The line at fault:
timediff = event.timestamp - (events[-1].timestamp + events[-1].duration)
events[-1] is the last event of the whole input, not the one before event, so timediff is meaningless unless event happens to be the final element. This has been there since the pulsetime parameter was introduced in 59e6912 (2018, "Cleaned up sum_durations and fixed pulsetime in chunk_events_by_key").
Fun fact: since sort_by_timestamp is normally applied first and input from actual watchers is usually chronological, events[-1] at the last iteration equals the previous event, so the bug hides in normal daily use and only fires for backfilled/reordered data... except it also means the pulse window is enforced only for the very last pair of events in the list. The variant that shows it is any same-key pair with a large gap that is not at the tail (or missing keys after it, or list end).
Also worth noting:
- aw-server-rust's
chunk_events_by_keyhas no pulsetime at all and deliberately merges across gaps, so Python and Rust already behave differently here - the whole transform is deprecated (see #1466) with no drop-in replacement, so whether to fix the check or remove the function entirely is genuinely ambiguous — happy to PR either way:
Option A (minimal fix, keeps pulse semantics):
timediff = event.timestamp - (chunked_events[-1].timestamp + chunked_events[-1].duration)
Option B: drop the pulse check entirely and match Rust (merging across gaps is arguably the "spec" now, given it's what both the Rust implementation does and what the buggy Python code accidentally does in sorted-input practice).
Existing tests don't cover gaps (all three events in test_chunk_events_by_key share the same timestamp), so whichever direction is chosen I'd add a gap test.
- Lingua principale
- Python
- Stelle
- 65
- Fork
- 74
- Merge medio
- 7g 7h
- PR unite (30g)
- 11
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ActivityWatch/aw-core
-
Peewee explicit event IDs can move events between bucketsForse già presa @TimeToBuildBob l’ha presa 26 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
ActivityWatch/aw-core#195 ·
I maintainer di solito rispondono entro 10 giorni
-
Peewee range queries omit accepted events longer than 24 hoursForse già presa @TimeToBuildBob l’ha presa 26 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
ActivityWatch/aw-core#194 · 1 commento ·
I maintainer di solito rispondono entro 10 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
ActivityWatch/aw-core#174 ·
I maintainer di solito rispondono entro 10 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
ActivityWatch/aw-core#78 · 4 commenti ·
I maintainer di solito rispondono entro 10 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
ActivityWatch/aw-core#52 · 4 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 10 giorni
Tutte le issue di ActivityWatch/aw-core
Issue simili
-
bug docs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier captureForse già presa @jianyx1 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
volcengine/OpenViking#8354 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
I maintainer di solito rispondono entro 1 giorno
-
comp/tools P2 tool/skills type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#159541 ·
I maintainer di solito rispondono entro 1 giorno