fix: Slackリトライによるtimes-allへの重複投稿を防止#51
Merged
Merged
Conversation
Slackが3秒以内にレスポンスを受け取れない場合にリトライを送信し、 別のLambdaインスタンスが同じイベントを処理することで重複投稿が発生していた。 x-slack-retry-numヘッダーの存在をチェックし、リトライリクエストは即座に200を返す。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
APIGatewayProxyEventV2はBoltのAwsEventに構造的に代入可能なためキャスト不要。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
重複投稿の原因(Slackのリトライが別Lambdaインスタンスで並行処理される)に対して、入口でリトライを検知して早期に200を返す方針は、影響範囲が小さく運用改善に直結する良い対応です。
Changes:
- Slackの
x-slack-retry-numヘッダーを検知し、Boltへ渡す前にリトライをスキップして200を返す処理を追加 handlerのイベント型をAPIGatewayProxyEventV2に修正し、as anyキャストを除去- リトライ判定ロジックを
isSlackRetryとして切り出し、ユニットテストを追加
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/lib/slackRetry.ts | Slackリトライ検知(x-slack-retry-num)のユーティリティを追加 |
| src/handler.ts | リトライの早期スキップと、イベント型の厳密化を実施 |
| src/tests/handler.test.ts | リトライ判定ロジックのテストを追加(※配置/カバレッジに指摘あり) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 227d279cb9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
全リトライをスキップするとLambdaエラー時のリトライまで捨ててしまうため、 重複投稿の原因であるhttp_timeoutの場合のみスキップするよう変更。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
issue
なし(運用中に発覚)
変更内容
x-slack-retry-reason: http_timeoutで再送したリクエストを、Boltに渡す前にスキップして200を返すようにしたhttp_error等)はスキップせず、回復の機会を残すhandlerのevent引数の型をRecord<string, unknown>からAPIGatewayProxyEventV2に修正し、as anyキャストを除去した確認したこと
tsが2回処理されたケースが4件あることを確認(約1〜2秒差で別のLambdaインスタンスが処理)スクリーンショット
なし
補足事項
Slackは3秒以内にレスポンスを返さないとリトライを送信する。Lambdaのコールドスタートや
conversations.infoのAPI呼び出しで3秒を超えると、リトライが別のLambdaインスタンスで処理され重複投稿が発生していた。PR時のセルフチェック