Skip to content

FIX: Store conversation ids up to 128 characters on SQL Server - #4486

Open
Richard Lundeen (richlundeen) wants to merge 2 commits into
microsoft:mainfrom
richlundeen:richlundeen-widen-conversation-ids
Open

Richard Lundeen (richlundeen) wants to merge 2 commits into
microsoft:mainfrom
richlundeen:richlundeen-widen-conversation-ids

Conversation

@richlundeen

@richlundeen Richard Lundeen (richlundeen) commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

On SQL Server, the GUI's "detect capabilities" failed on every chat target with supports_multi_turn failed; capabilities were not changed. The multi-turn probe registers a conversation named capability-probe-<uuid> (53 characters), but #2026 sized Conversations.conversation_id (and AttackResultEntries.conversation_id) at VARCHAR(36) for a bare UUID, so SQL Server rejected the insert with "String or binary data would be truncated". SQLite ignores the declared length, which is why tests never caught it. Message pieces already store conversation ids as VARCHAR(128) because they are free-form, not necessarily UUIDs.

  • Add migration 0d3592c62ad8, which widens both columns to 128 on SQL Server. It drops and re-creates the Conversations primary key under its original name and clustering, because SQL Server cannot alter a key column in place. On SQLite it updates only the declared types, using SQLite's documented schema edit, so the schema matches the models without rebuilding AttackResultEntries and its generated analytics column. The downgrade restores 36 characters, so an earlier release's schema check accepts the database. On SQL Server it refuses when longer ids are stored. The SQL Server migration check in CI now round-trips the newest migration, so downgrades run against a real server.
  • Share one CONVERSATION_ID_MAX_LENGTH across all three tables. A @validates hook on each entry rejects longer ids with a ValueError on every backend, for inserts and updates alike, so SQLite fails the same way SQL Server would.
  • Name the cause in detection errors. The outer probe handler used to replace the inner failure with the capability name, so every failure (a 401, a timeout, the SQL error above) looked the same. Messages now include the failed step and a one-line error summary. Database errors show the driver message, not the full statement:
    • Before: supports_multi_turn failed; capabilities were not changed.
    • After: supports_multi_turn: Could not prepare the multi-turn probe: ProgrammingError: ... String or binary data would be truncated in table 'Conversations' ...; capabilities were not changed.
  • When no control request passes, the error now lists each input's failure, for example Control request ['text']: AuthenticationError (HTTP 401): ....
  • The backend logs each detection failure at WARNING with its traceback. Previously nothing reached the server logs.
  • Ordering tests no longer assume unique timestamps. Windows clocks before Python 3.13 can tie them, and SQLite's tie order depends on which equivalent index the planner picks.

Verified on a personal Azure SQL deployment. The migration ran (3e55dd099e38 -> 0d3592c62ad8), and detection now succeeds on every OpenAI Chat and Responses target, with multi-turn confirmed. Targets that still fail report a specific cause, for example Modality probe ['image_path', 'text'] failed: NotFoundError (HTTP 404): No endpoints found that support image input.

Conversations.conversation_id and AttackResultEntries.conversation_id were
VARCHAR(36), sized for a bare UUID, while PromptMemoryEntries stores 128.
SQL Server rejected longer ids, so capability detection failed on every
chat target with "supports_multi_turn failed". A new migration widens both
columns, and memory now rejects ids no table can store on every backend.

Capability detection errors now name the failed check and its cause, and
the backend logs each failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 03:14

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.

🟡 Changes recommended

Updates bypass conversation ID length validation, creating inconsistent behavior across databases, and SQL Server downgrades leave column lengths incompatible with the previous release’s strict schema check.

2 open issues
What changed in this PR

Fixes SQL Server conversation-ID truncation that blocked GUI capability detection, extending the bounded-column work from #2026 to support free-form IDs.

Changes:

  • Widens conversation-ID columns to 128 and adds shared length validation.
  • Preserves specific capability-detection errors and logs failures with tracebacks.
  • Adds migration, persistence, and diagnostic regression coverage.
File Description
tests/​unit/​prompt_target/​test_discover_target_capabilities.py Covers detailed probe failure messages.
tests/​unit/​memory/​test_conversation_id_length_migration.py Covers column lengths, validation, and SQLite migration round trips.
tests/​integration/​memory/​test_azure_sql_memory_integration.py Checks 128-character ID persistence on SQL Server.
pyrit/​prompt_target/​common/​discover_target_capabilities.py Includes failure causes and control-input diagnostics.
pyrit/​memory/​memory_models.py Shares the 128-character bound and validates constructed entries.
pyrit/​memory/​memory_interface.py Validates ID lengths before message insertion.
pyrit/​memory/​alembic/​versions/​0d3592c62ad8_widen_conversation_ids.py Widens SQL Server columns and updates SQLite declarations.
pyrit/​backend/​services/​target_service.py Logs detection failures with tracebacks.

Review effort: Balanced

Comment thread pyrit/memory/memory_interface.py Resolved
…y id write

Address review feedback on the conversation id migration:
- The SQL Server downgrade now narrows both columns back to 36 characters,
  so an earlier release's schema check accepts the database. It refuses when
  longer ids are stored and re-creates the AttackResultEntries indexes that
  cover conversation_id, which SQL Server cannot narrow in place.
- The SQL Server migration check round-trips the newest migration, so the
  downgrade runs against a real server in CI.
- A SQLAlchemy validator on each entry rejects too-long conversation ids on
  every assignment, so updates are checked as well as inserts.

Ordering tests no longer depend on unique timestamps, which coarse clocks
(Windows before Python 3.13) cannot guarantee.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

3 participants