chunk_events_by_key: gap/pulsetime check is broken (events[-1] is always the last event)
メンテナーはふだん 10 日以内に返信
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 65
- フォーク
- 74
- 平均マージ
- 7日 7時間
- マージ済み PR(30日)
- 11
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ActivityWatch/aw-core のほかの issue
-
Peewee explicit event IDs can move events between buckets対応中かも @TimeToBuildBob が 26 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
ActivityWatch/aw-core#195 ·
メンテナーはふだん 10 日以内に返信
-
Peewee range queries omit accepted events longer than 24 hours対応中かも @TimeToBuildBob が 26 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ActivityWatch/aw-core#194 · コメント 1 件 ·
メンテナーはふだん 10 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
ActivityWatch/aw-core#174 ·
メンテナーはふだん 10 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ActivityWatch/aw-core#78 · コメント 4 件 ·
メンテナーはふだん 10 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
ActivityWatch/aw-core#52 · コメント 4 件 · リアクション 3 件 ·
メンテナーはふだん 10 日以内に返信
ActivityWatch/aw-core の issue をすべて見る
似ている issue
-
bug docs
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capture対応中かも @jianyx1 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
volcengine/OpenViking#8354 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
メンテナーはふだん 1 日以内に返信
-
comp/tools P2 tool/skills type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NousResearch/hermes-agent#159541 ·
メンテナーはふだん 1 日以内に返信