Skip to content

fix: reject unknown conversation id instead of implicit creation - #531

Merged
maralbahari merged 4 commits into
vllm-project:mainfrom
justrightnow:fix/155-unknown-conversation-id-404
Nov 16, 2026
Merged

maralbahari merged 4 commits into
vllm-project:mainfrom
justrightnow:fix/155-unknown-conversation-id-404

Conversation

@justrightnow

Copy link
Copy Markdown
Contributor

Summary

Closes #155.

A Responses request that references a conversation id no longer creates that conversation implicitly when the id does not exist. Previously, with store: true, a missing conversation fell through from_conversation to ConversationHandler::get_or_create, so an unknown client-supplied id silently created a new conversation.

The OpenAI Conversations contract requires creating a conversation through POST /v1/conversations first; referencing an unknown id must fail rather than be created. This change lets the storage not-found error surface, so the request returns 404 (type: not_found) for both stored and unstored turns.

Changes:

  • Remove the not-found + store implicit-creation branch in from_conversation and propagate the conversation not-found.
  • Drop the now-unused ConversationHandler::get_or_create and its unit tests (the lower-level ConversationStore::get_or_create remains for storage tests).
  • Update two tests that relied on implicit creation to create the conversation explicitly first, and add a regression covering unknown ids for store false/true.

Test Plan

  • cargo test -p agentic-server-core --test stateful_responses_integration — 27 passed (includes the new unknown_conversation_id_is_not_created_implicitly).
  • cargo test -p agentic-server-core --test stateful_conversation_integration — 8 passed.
  • cargo test -p agentic-server-core --lib conversation — related cases pass.
  • cargo clippy -p agentic-server-core --all-targets -- -D warnings — no warnings.
  • cargo fmt -- --check — formatted.

A Responses request referencing a conversation id that does not exist no longer creates the conversation implicitly; it now returns the storage not-found (HTTP 404), matching the OpenAI Conversations contract (closes vllm-project#155)

Signed-off-by: Jack Wei <[email protected]>

@maralbahari maralbahari left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking up #155. The direction is right: OpenAI rejects a Responses request whose conversation names an unknown id, for both store: true and store: false and for the {"id": ...} form, instead of creating it. A few things are needed before this can go in.

The error envelope. OpenAI answers 404 with type: invalid_request_error and the message Conversation with id '<id>' not found.. This PR returns type: not_found with storage error: not found: Conversation with id '<id>'. Missing responses already follow OpenAI through typed StorageError::ResponseNotFound / PreviousResponseNotFound variants that carry OpenAI's message and map to invalid_request_error in ExecutorError::error_type; a missing conversation should do the same. ConversationStore::rehydrate already detects it (StorageError::not_found("Conversation", ...) in storage/conversation.rs), so returning a typed conversation-not-found error from there is enough; no separate lookup is needed.

Finish the removal. With implicit creation gone, ConversationStore::get_or_create and models::conversation::get_or_create (an INSERT ... ON CONFLICT ... RETURNING * upsert) have no production caller left; they would only run in test_conversation_get_or_create_same_id and postgres_get_or_create_creates_then_returns_the_existing_conversation. Since rehydrate already reports the missing conversation, please remove them with those tests (explicit creation stays separate, in ConversationStore::create behind POST /v1/conversations), and update ARCHITECTURE.md, which still says a missing conversation "is created for a stored turn" and lists get_or_create among the store and handler methods.

@justrightnow

Copy link
Copy Markdown
Contributor Author

Verification: before vs after

I ran two gateway binaries on an isolated port (9100) with separate SQLite databases, sending the same request (reference an unknown conversation id with store: true).

Scenario: unknown conversation id + store:true Before (old binary) After (fixed binary)
POST /v1/responses status 200 (proceeded to inference) 404
Ollama invoked yes (~7s) no (rejected in 0.004s, before inference)
conversations table row created implicitly (empty tenant_id) 0 rows
responses table +1 row 0 rows

The implicitly-created row from the old binary had an empty tenant_id, so fetching it by tenant afterwards returned 404 (an orphaned row) — further evidence implicit creation is wrong.

Valid path still works (verified on the fixed binary, step by step):

  1. POST /v1/conversations explicitly → 200, returns conv_…
  2. Reference that conversation with "remember 42" → 200, reply "got it"
  3. Follow up in the same conversation with "what number did I ask you to remember?" → 200, answer "42"; history loaded correctly (4 persisted items)

So only "reference an unknown id → create implicitly" is removed (now a fast 404); the normal "create first, then reference" stateful multi-turn flow is unchanged.

Note for anyone reproducing: rebuild the agentic-server binary itself (cargo build -p agentic-server --bin agentic-server) after pulling — rebuilding only the core crate/tests does not relink the executable.

@maralbahari

maralbahari commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Verification: before vs after

I ran two gateway binaries on an isolated port (9100) with separate SQLite databases, sending the same request (reference an unknown conversation id with store: true).

Scenario: unknown conversation id + store:true Before (old binary) After (fixed binary)
POST /v1/responses status 200 (proceeded to inference) 404
Ollama invoked yes (~7s) no (rejected in 0.004s, before inference)
conversations table row created implicitly (empty tenant_id) 0 rows
responses table +1 row 0 rows
The implicitly-created row from the old binary had an empty tenant_id, so fetching it by tenant afterwards returned 404 (an orphaned row) — further evidence implicit creation is wrong.

Valid path still works (verified on the fixed binary, step by step):

  1. POST /v1/conversations explicitly → 200, returns conv_…
  2. Reference that conversation with "remember 42" → 200, reply "got it"
  3. Follow up in the same conversation with "what number did I ask you to remember?" → 200, answer "42"; history loaded correctly (4 persisted items)

So only "reference an unknown id → create implicitly" is removed (now a fast 404); the normal "create first, then reference" stateful multi-turn flow is unchanged.

Note for anyone reproducing: rebuild the agentic-server binary itself (cargo build -p agentic-server --bin agentic-server) after pulling — rebuilding only the core crate/tests does not relink the executable.

Thanks for verifying this. Please add the case as a cassette recording so it's gated in the repo: append turns to the response-conversation scenario in crates/agentic-server-core/tests/cassettes/record_cassette.py that reference an unknown conversation id (store: true and false), sent with _item_request(..., "POST", "/v1/responses", body=..., expected_status=None) so the 404 is recorded. Record it with record_responses_api_cassettes.sh (RESPONSES_SCENARIO=conversation) for OpenAI and the gateway, and update the turn count. responses_api_test.rs then checks the gateway's status and error type/code/param against OpenAI's. Steps are in crates/agentic-server-core/tests/cassettes/README.md.

Add typed StorageError::ConversationNotFound returned by ConversationStore::rehydrate,
mapping to HTTP 404 with type invalid_request_error, param conversation and message
Conversation with id '<id>' not found. Remove the now-unused get_or_create store/upsert
and their tests; update ARCHITECTURE.md. Addresses review on vllm-project#155.

Signed-off-by: Jack Wei <[email protected]>
@justrightnow

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Points 1–3 are addressed in the new push (f9a7837f):

  1. Error envelope. Added a typed StorageError::ConversationNotFound { id }, returned directly from ConversationStore::rehydrate. It renders exactly as OpenAI:

    • status 404
    • type: invalid_request_error
    • param: "conversation"
    • message Conversation with id '<id>' not found. (no storage error: prefix)

    The integration test now asserts the full envelope instead of just "some not-found error".

  2. Finish the removal. Removed ConversationStore::get_or_create, the models::conversation::get_or_create upsert, and both tests (test_conversation_get_or_create_same_id, postgres_get_or_create_creates_then_returns_the_existing_conversation). Explicit creation stays in create behind POST /v1/conversations.

  3. Docs. Updated ARCHITECTURE.md: a missing conversation is now described as a 404 for both stored and unstored turns, and get_or_create is removed from the method lists.

Point 4 (cassette): I don't have access to an OpenAI API key, so I can't produce the recorded cassette via record_responses_api_cassettes.sh (and per the repo rules it must be recorded, not hand-authored). How would you like to handle this? Options:

  • someone on your side records the OpenAI + gateway turns for the response-conversation scenario, or
  • you point me to an environment/key I should use, and I'll record it and update the turn count and responses_api_test.rs.

Verification run locally (Rust 1.98.1): core lib 1419 passed; stateful_responses_integration 29 passed; storage_integration 27 passed; clippy -D warnings clean; cargo fmt --check clean.

@maralbahari

Copy link
Copy Markdown
Collaborator

@justrightnow I will help to add those cassettes in.

@maralbahari
maralbahari merged commit 4aa37fd into vllm-project:main Nov 16, 2026
15 checks passed
LeaderOnePro added a commit to LeaderOnePro/agentic-api that referenced this pull request Nov 16, 2026
Bring in model capability validation (vllm-project#512), unknown conversation id
rejection (vllm-project#531), persisted-turn documentation (vllm-project#533), and the shared
input-item test helper (vllm-project#545).

Signed-off-by: LeaderOnePro <[email protected]>
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.

Conversations API: match OpenAI for unknown conversation ids (currently created implicitly)

2 participants