Skip to content

FIX: return 409 Conflict when add_message hits AttackStateConflictError - #4688

Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/add-message-conflict-status
Open

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/add-message-conflict-status

Conversation

@ManoharPaturi

Copy link
Copy Markdown
Contributor

Description

Fixes #4685

POST /api/attacks/{attack_result_id}/messages now returns HTTP 409 Conflict when add_message_async raises AttackStateConflictError, matching apply_chat_scorer_async, save_conversation_async, and submit_message_send_async.

  • catch (AttackStateConflictError, ManualSendConflictError) in add_message before the generic ValueError handler, since AttackStateConflictError subclasses ValueError

Before, when add_message_async raised AttackStateConflictError:

POST /api/attacks/{attack_result_id}/messages returns 400 Bad Request

After, on the same conflict:

POST /api/attacks/{attack_result_id}/messages returns 409 Conflict

Signed-off-by: ManoharPaturi <186662190+ManoharPaturi@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change to return HTTP 409 on message state conflicts.

No open issues 🎉

What changed in this PR

Fixes #4685 by returning HTTP 409 Conflict when adding a message raises AttackStateConflictError, matching related attack endpoints.

Changes:

  • Handles state conflicts before the generic ValueError handler to prevent incorrect 400 Bad Request responses.
  • Adds a regression case for the expected 409 response.
File Description
tests/​unit/​backend/​test_api_routes.py Adds AttackStateConflictError to the route’s exception-mapping tests.
pyrit/​backend/​routes/​attacks.py Maps both state and manual-send conflicts to HTTP 409.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

POST /api/attacks/{attack_result_id}/messages returns 400 instead of 409 on AttackStateConflictError

2 participants