fix: DynamoDBのイベント取得順をpayload.timestampに統一 - #6
Open
y-oga-819 wants to merge 3 commits into
Open
Conversation
DynamoDB backend の FindBySessionID は created_at(サーバ受信時刻)で整列 していたが、sqlite/postgres/turso/memory は transcript 行の payload.timestamp(イベント時刻)で整列しており食い違っていた。同期・順序 どおりの配送では両者がほぼ一致するため顕在化しなかったが、遅延や順不同の 取り込みでは DynamoDB だけ表示順が崩れる。 sort_key が重複排除のため UUID ベースになった際に時系列順が失われ、その 代替として created_at ソートが入った経緯による(コード内コメントにも記載)。 他バックエンドに揃える: - event.go: sort.SliceStable + payload.timestamp 整列に変更。欠落時は created_at にフォールバック(RFC3339Nano → "...000Z" → CreatedAt)で、 sqlite/turso の getTimestampFromPayload と同一ロジック。 - testsuite: created_at の順を payload.timestamp の逆順に仕込んだ共有順序 テストを追加し、全バックエンドの整列契約を固定。修正前は DynamoDB での み fail、他バックエンドでは pass。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
追加した sort/helper/test のコメントが周辺(sqlite の getTimestampFromPayload は doc 無し、既存テストもメソッド doc 無し)より過剰だったため house style に 合わせて簡潔化。ロジックは不変、テスト green。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
DynamoDB に追加した整列ヘルパを eventTimestamp から、memory/sqlite/turso が 使う getTimestampFromPayload に rename。機能は不変、命名を揃えるだけ。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
y-oga-819
marked this pull request as ready for review
June 5, 2026 08:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
DynamoDB backend の
FindBySessionIDがイベントをcreated_at(サーバ受信時刻)で整列していましたが、sqlite/postgres/turso/memoryの各 backend は transcript 行のpayload.timestamp(イベント時刻)で整列しており、挙動が食い違っていました。本 PR は DynamoDB を他 backend に揃えます。背景
同期・順序どおりの配送では
created_at≒payload.timestampのため顕在化しませんが、遅延・順不同の取り込みでは DynamoDB だけ表示順が崩れます。sort_keyが重複排除のため UUID ベースになった際に時系列順が失われ、その代替としてcreated_atソートが入った経緯によるものです(event.goのコメントにも記載があります)。変更
dynamodb/event.go:sort.SliceStable+payload.timestamp整列に変更。欠落時はcreated_atフォールバック(RFC3339Nano→"...000Z"→CreatedAt)で、sqlite/turso/memoryのgetTimestampFromPayloadと同一ロジック・同一命名。testsuite/event_suite.go:created_atの挿入順をpayload.timestampの逆順に仕込んだ共有順序テストを追加。全 backend で整列契約を固定。修正前は DynamoDB のみ fail、他 backend は pass。テスト
DynamoDB Local +
go test -tags integrationでmemory/sqlite/dynamodbのEventRepositoryスイートが green。やらなかったこと(Out of scope)
getTimestampFromPayload(payload.timestamp 抽出 + フォールバック)はmemory/sqlite/turso/ 本 backend に同等のコピーが分散しています(今回の drift の遠因でもあります)。本来は共通パッケージへ括り出す(dedup)のが望ましいですが、本 PR は DynamoDB の整列バグ修正に絞り、正常な他 backend のコードには手を入れない方針としました。backend 間の整列契約は追加した共有テストで担保しています。共通化は別 PR の候補です。