Skip to content

fix(image_gen): prevent double interaction defer in auto image style generation - #134

Open
YoneRai12 wants to merge 1 commit into
mainfrom
codex/fix-double-defer-in-auto-style-generation
Open

fix(image_gen): prevent double interaction defer in auto image style generation#134
YoneRai12 wants to merge 1 commit into
mainfrom
codex/fix-double-defer-in-auto-style-generation

Conversation

@YoneRai12

Copy link
Copy Markdown
Owner

Motivation

  • 自動スタイルボタン(style_auto)が既にinteraction.response.defer()しているときに、共通処理start_generationが再度defer()を呼んでしまい、Discordの二重応答エラー(InteractionResponded)で自動生成フローが中断される問題を修正するため。

Description

  • src/views/image_gen.pyStyleSelectView.start_generationで、if not interaction.response.is_done(): await interaction.response.defer()というガードを追加して、既に応答済みのインタラクションに対しては二重でdefer()しないようにした。

Testing

  • python -m py_compile src/views/image_gen.pyを実行して構文チェックが成功したことを確認した。
  • 変更差分を確認し(期待どおり最小の修正であることを検証)、自動スタイル経路の二重deferが回避されることを確認した。

Codex Task

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds a check to prevent double-deferring interactions in the start_generation method. The reviewer suggests refactoring the method to consistently use the passed interaction object instead of self.original_interaction to avoid potential expiration errors and improve maintainability.

Comment thread src/views/image_gen.py
Comment on lines +26 to +27
if not interaction.response.is_done():
await interaction.response.defer()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

この修正により、style_auto 経由で既に defer() が呼ばれている場合の二重応答エラー(InteractionResponded)を適切に回避できています。

改善の提案として、このメソッド内で引数の interactionself.original_interaction(初期化時に保存されたもの)が混在して使用されている点に注意してください。32行目などの処理で self.original_interaction を使用していますが、これは古いインタラクションであるため、ユーザーがスタイル選択画面で長時間放置した場合などに期限切れ(15分)でエラーになるリスクがあります。

start_generation が引数の interaction の状態を保証するようになったため、メソッド全体でこの最新の interaction を一貫して使用するようにリファクタリングすることで、堅牢性と保守性が向上します。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant