Skip to content

fix(aws): pagination がスパースな時間範囲で取りこぼす問題を修正 - #29

Merged
myuron merged 1 commit into
mainfrom
fix/pagination-skip-empty-page
May 22, 2026
Merged

myuron merged 1 commit into
mainfrom
fix/pagination-skip-empty-page

Conversation

@myuron

@myuron myuron commented May 22, 2026

Copy link
Copy Markdown
Owner

Summary

v1.4.1 で導入した時間範囲チャンキング並列フェッチで、実 AWS 環境では 89MB → 15KB と大量のイベントを取りこぼす致命的な問題があった。本 PR で根本原因を修正。

根本原因

`paginateGetLogEvents` の終端条件に `len(out.Events) == 0` が含まれており、AWS が pagination 途中で「空イベント + 新しい NextForwardToken」を返した時点で end-of-stream と誤判定して打ち切っていた。

AWS CLI ドキュメントは次の通り明記:

The CloudWatch Logs service will sometimes (especially during periods of low or no activity) return an empty list of events even if you have not reached the end of the stream's log events. In this case, the operation returns nextForwardToken in the response, and you should call get-log-events again with this token.

時間チャンキングを入れたことで各チャンクがスパースな時間窓を見るようになり、空ページが頻発して大量のロスが顕在化した。floci は密に返すためローカルでは再現せず、実 AWS でのみ発現。

Changes

  • `len(out.Events) == 0` を終端条件から削除
  • `nextToken == prevToken` のみで終端判定(AWS 仕様準拠)
  • 既存テスト `TestClient_GetLogEvents_PaginationStopsOnEmptyPage` を「空ページを跨いで続行する」新仕様のテストに置換

Test plan

  • `go test ./...` 全テスト Green
  • floci での 30k スパースストリーム / 300k 密ストリームに対する回帰なしを確認(sequential/chunked いずれも全件取得)
  • 実 AWS 環境で大容量ストリームを開き、89MB クラスの取得が正常に完了すること
  • PR マージ後に v1.4.2 リリース + proxy.golang.org に v1.4.1 を retract 推奨

v1.4.1 の扱い

proxy.golang.org がキャッシュ済みのため `@v1.4.1` を引くと壊れたコードが取れます。次リリースで `go.mod` に以下の retract を入れるのが安全:

```
retract v1.4.1 // pagination prematurely truncates over sparse time windows (#?)
```

🤖 Generated with Claude Code

GetLogEvents を時間範囲チャンキングで並列化した v1.4.1 で、
89MB → 15KB と大量にイベントを取りこぼす問題があった。

根本原因:
paginateGetLogEvents の終端条件に len(out.Events) == 0 が含まれて
おり、AWS が pagination 途中で「空イベント + 新しい NextForwardToken」
を返した時点で end-of-stream と誤判定して打ち切っていた。

AWS CLI ドキュメントは次の通り明記している:
> The CloudWatch Logs service will sometimes (especially during periods
> of low or no activity) return an empty list of events even if you
> have not reached the end of the stream's log events. In this case,
> the operation returns nextForwardToken in the response, and you
> should call get-log-events again with this token.

時間チャンキングを入れたことで各チャンクがスパースな時間窓を見るよう
になり、空ページが頻発して大量のロスが顕在化した。floci は密に返す
ためローカルでは再現せず、実 AWS でのみ発現していた。

修正:
- len(out.Events) == 0 を終端条件から削除
- nextToken == prevToken のみで終端判定(AWS 仕様準拠)
- 既存テスト TestClient_GetLogEvents_PaginationStopsOnEmptyPage を
  「空ページを跨いで続行」する新仕様のテストに置き換え

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@myuron
myuron merged commit a2286ed into main May 22, 2026
1 check 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.

1 participant