Skip to content

fix: Slackリトライによるtimes-allへの重複投稿を防止#51

Merged
eai04191 merged 5 commits into
mainfrom
fix/duplicate-slack-retry
Jun 9, 2026
Merged

fix: Slackリトライによるtimes-allへの重複投稿を防止#51
eai04191 merged 5 commits into
mainfrom
fix/duplicate-slack-retry

Conversation

@eai04191

@eai04191 eai04191 commented Jun 9, 2026

Copy link
Copy Markdown
Member

issue

なし(運用中に発覚)

変更内容

  • Slackがx-slack-retry-reason: http_timeoutで再送したリクエストを、Boltに渡す前にスキップして200を返すようにした
    • Lambda障害等による他のリトライ理由(http_error等)はスキップせず、回復の機会を残す
  • handlerevent引数の型をRecord<string, unknown>からAPIGatewayProxyEventV2に修正し、as anyキャストを除去した

確認したこと

  • CloudWatch Logsで直近2日間に同じtsが2回処理されたケースが4件あることを確認(約1〜2秒差で別のLambdaインスタンスが処理)
  • typecheck, lint, テスト全パス

スクリーンショット

なし

補足事項

Slackは3秒以内にレスポンスを返さないとリトライを送信する。Lambdaのコールドスタートやconversations.infoのAPI呼び出しで3秒を超えると、リトライが別のLambdaインスタンスで処理され重複投稿が発生していた。

PR時のセルフチェック

  • 関数や変数の命名は一目で分かるものになってますか?
  • コメントは適切な量で、誰が見ても分かるコメントになってますか?
  • PR内容に関するテストは書きましたか?
  • PR内容に付随する各種ドキュメントは一緒に修正しましたか?
  • IssueをCloseする場合、完了の定義は満たせていますか?

byClaude Code

eai04191 and others added 3 commits June 9, 2026 11:32
Slackが3秒以内にレスポンスを受け取れない場合にリトライを送信し、
別のLambdaインスタンスが同じイベントを処理することで重複投稿が発生していた。
x-slack-retry-numヘッダーの存在をチェックし、リトライリクエストは即座に200を返す。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
APIGatewayProxyEventV2はBoltのAwsEventに構造的に代入可能なためキャスト不要。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 02:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/handler.ts Outdated
Comment thread src/__tests__/handler.test.ts Outdated
Comment thread src/__tests__/handler.test.ts Outdated
@eai04191

eai04191 commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/handler.ts Outdated
eai04191 and others added 2 commits June 9, 2026 11:57
全リトライをスキップするとLambdaエラー時のリトライまで捨ててしまうため、
重複投稿の原因であるhttp_timeoutの場合のみスキップするよう変更。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@eai04191 eai04191 merged commit 9504864 into main Jun 9, 2026
3 checks passed
@eai04191 eai04191 deleted the fix/duplicate-slack-retry branch June 9, 2026 03:01
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.

2 participants