BUG: MemoryInterface.get_request_from_response fails with IndexError for non-zero starting sequence or sequence gaps
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The bug is in _execute_get_request_from_response in pyrit/memory/memory_interface.py, which indexes the conversation list by response.sequence - 1. Read _execute_get_conversation_messages to see how messages are ordered, then reproduce with the SQLite script in the issue. Pull request #3190 is already open against this issue, so check it before starting a new fix. Done means the method returns the message with the closest lower sequence, or raises a clear error when none exists.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
In pyrit/memory/memory_interface.py, MemoryInterface._execute_get_request_from_response retrieves the request that produced a given assistant response:
def _execute_get_request_from_response(self, *, response: Message) -> Message:
if response.api_role != "assistant":
raise ValueError("The provided request is not a response (role must be 'assistant').")
if response.sequence < 1:
raise ValueError("The provided request does not have a preceding request (sequence < 1).")
conversation = self._dispatch_memory_operation(
"get_conversation_messages",
self._execute_get_conversation_messages,
conversation_id=response.conversation_id,
)
return conversation[response.sequence - 1]
The method treats response.sequence - 1 as a 0-based list index into conversation. However, get_conversation_messages returns messages ordered by sequence (sorted(conversation_by_sequence.keys())), where list index corresponds to sequence number only if the conversation started at sequence 0 and contains no sequence gaps.
Whenever:
- A conversation starts at a non-zero sequence (e.g. using
starting_sequenceinSeedPrompt.from_messagesorSimulatedConversationAttack), or - A conversation contains sequence gaps (e.g. after pruning or retries where pieces were deleted),
calling get_request_from_response (or get_request_from_response_async, or DecodingScorer which invokes this method) raises:
IndexError: list index out of range (or returns the wrong message if the index exists but does not align).
Steps/Code to Reproduce
import asyncio
from uuid import uuid4
from pyrit.memory import SQLiteMemory
from pyrit.models import MessagePiece
async def test_reproduce():
memory = SQLiteMemory(db_path=":memory:")
conversation_id = str(uuid4())
# Create a conversation with starting_sequence=10
pieces = [
MessagePiece(
role="user",
original_value="What is the capital of France?",
conversation_id=conversation_id,
sequence=10,
),
MessagePiece(
role="assistant",
original_value="Paris.",
conversation_id=conversation_id,
sequence=11,
),
]
await memory.add_message_pieces_to_memory_async(message_pieces=pieces)
conversation = await memory.get_conversation_messages_async(conversation_id=conversation_id)
response = conversation[1] # sequence=11
# Attempt to retrieve the request that produced the response
await memory.get_request_from_response_async(response=response)
asyncio.run(test_reproduce())
Expected Results
get_request_from_response_async returns the message immediately preceding the response in the conversation timeline (Message(role='user', sequence=10, ...)).
Actual Results
Traceback (most recent call last):
...
File "pyrit/memory/memory_interface.py", line 3041, in _execute_get_request_from_response
return conversation[response.sequence - 1]
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range
Suggested Fix
Instead of assuming conversation index equals sequence - 1, locate the preceding message in conversation with sequence < response.sequence:
conversation = self._dispatch_memory_operation(
"get_conversation_messages",
self._execute_get_conversation_messages,
conversation_id=response.conversation_id,
)
preceding_messages = [msg for msg in conversation if msg.sequence < response.sequence]
if not preceding_messages:
raise ValueError(
f"The provided request does not have a preceding request in conversation '{response.conversation_id}'."
)
return preceding_messages[-1]
- Ngôn ngữ chính
- Python
- Star
- 4.6k
- Fork
- 944
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 350
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/PyRIT
-
BUG: SQLInjectionOutputScorer misses standard inline comment bypasses ('-- and ' OR 1=1--)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/PyRIT#3204 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG: label queries only return the final conversation of an attackCó thể đã có người làm @u7k4rs6 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/PyRIT#3095 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG Configuration keeps runtime-status errors after polling recoversCó thể đã có người làm @joeyvictorino đã nhận 4 ngày trước. Đang mởBug: triage GUI help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
microsoft/PyRIT#2868 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
BUG: HTTPTarget sends conflicting Content-Length and Transfer-Encoding headersCó thể đã có người làm @Kaap10 đã nhận 9 ngày trước. Đang mởBug: triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
microsoft/PyRIT#3202 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/PyRIT
Issue tương tự
-
approved Good First Issue scope: docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
hiero-ledger/hiero-sdk-python#2730 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
wemake-services/wemake-django-template#3178 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
md/asciidoc/csv: an explicit `encoding="utf-8"` keeps a leading BOM, the auto-detect path drops itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
docling-project/docling#4846 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
neurostuff/NiMARE#1181 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pytest-dev/pytest#15180 ·
Maintainer thường phản hồi trong vòng 1 ngày