Skip to content

fix: admit fco_ and other item id prefixes OpenAI accepts - #553

Merged
maralbahari merged 5 commits into
mainfrom
fix/admit-item-id-prefixes
Nov 18, 2026
Merged

maralbahari merged 5 commits into
mainfrom
fix/admit-item-id-prefixes

Conversation

@maralbahari

Copy link
Copy Markdown
Collaborator

Summary

Codex stamps fco_ IDs on the function_call_output items it builds, and the gateway refused them with 400 invalid_value because InOutItem::admit accepted only fc_. OpenAI accepts them. Probing OpenAI shows a call also accepts its output's prefix, so custom_tool_call takes ctco_ and shell_call takes sho_, while an output keeps its own prefix. InOutItem::id_prefixes() now lists the prefixes OpenAI admits for each type, replacing the two id_prefix() functions on InputItem and OutputItem; new IDs are still minted with the first one (fc_, ctc_, sh_, ...).

Fixes #547.

Changes by API

API What changed
Responses (/v1/responses) and Conversations (/v1/conversations, /v1/conversations/{id}/items) function_call and function_call_output admit fco_ as well as fc_; custom_tool_call admits ctco_; shell_call admits sho_. Every other prefix and every minted ID is unchanged.

OpenAI behavior (store: false), which the gateway now matches:

Item Admitted Rejected (400 invalid_value)
function_call, function_call_output fc_, fco_ xyz_, fcabc...
custom_tool_call ctc_, ctco_ xyz_
custom_tool_call_output ctco_ ctc_
shell_call sh_, sho_ xyz_
shell_call_output sho_ sh_

Test Plan

  • Sent each case in the table to OpenAI and to the gateway (POST /v1/conversations, which runs the same admission check); all 11 statuses match.
  • cargo fmt -- --check and cargo clippy --all-targets -- -D warnings are clean.
  • cargo test -p agentic-server-core --test responses_api_test: 31 passed.
  • cargo test -p agentic-server-core --lib item: 117 passed.

Signed-off-by: maral <maralbahari.98@gmail.com>
@franciscojavierarceo

Copy link
Copy Markdown
Collaborator

the new fco_, ctco_, and sho_ admission rules change the Responses and Conversations wire contract, but this diff has no tests or recorded OpenAI/gateway cases for those IDs. a future change could reject Codex output IDs again without failing CI. we should add the accepted and rejected cases to the existing item-admission tests, record the provider and gateway behavior through the cassette workflow, and assert the replayed status and error envelope.

@tjtanaa tjtanaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One storage compatibility concern with the newly shared call/result prefixes. Based on source inspection; I did not run tests.

InputItem::ToolSearchCall(_) => Some(&["tsc_"]),
InputItem::ToolSearchOutput(_) => Some(&["tso_"]),
InputItem::CustomToolCall(_) => Some(&["ctc_", "ctco_"]),
InputItem::ShellCall(_) => Some(&["sh_", "sho_"]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we preserve the requested item kind when resolving stored references? The new shell and custom-tool aliases make their call and result ID namespaces overlap. Responses and Conversations both resolve stored items by public ID without checking the item kind, so successful admission no longer guarantees that the resolved item is still a call rather than its result. Please check provider behavior for a kind mismatch and add a storage-backed regression that asserts the resolved kind, not just the admission status.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I checked the provider first. OpenAI does not preserve the requested kind either: it resolves a reused public ID to the stored item, whatever type the request names. So the gateway's kind-agnostic resolution is the parity behavior, and I kept it.

Recorded in be1a0ff (OpenAI and gateway):

  • Conversations (conversations-item-id-prefixes-*.yaml, t15-t18): sending a function_call with a stored function_call_output ID, a function_call_output with a stored function_call ID, a custom_tool_call with a stored custom_tool_call_output ID, and a shell_call with a stored shell_call_output ID all return 200 with the stored item, kind and call_id included, from both providers.
  • Responses (response-item-id-prefixes-*.yaml, t8-t11): OpenAI also replaces the input with the stored item; its 400 names the stored item's call_id (No tool call found for shell call output with call_id call_seed_shell.).

Regressions:

  • item_id_prefix_recordings_admit_refuse_and_resolve_the_same_ids asserts that the resolved ID, type and call_id are the stored item's, in both recordings.
  • gateway_matches_openai_item_status_codes_and_bodies replays the OpenAI recording through ConversationHandler on SQLite and compares the resolved kind.
  • stored_reference_resolves_to_the_stored_item_kind covers the Responses path through resolve_input_items against a SQLite store.

Note that fc_ was already shared by function_call and function_call_output before this PR, so the overlap was not introduced here; the PR extends the same OpenAI rule to custom and shell.

Signed-off-by: maral <maralbahari.98@gmail.com>
Signed-off-by: maral <maralbahari.98@gmail.com>
@maralbahari

Copy link
Copy Markdown
Collaborator Author

@franciscojavierarceo @tjtanaa while recording the fco cases for the Conversations and Responses API edge cases, I noticed another item ID problem: OpenAI changed its behavior for repeated item IDs. Adding the same stored item twice in one request now returns 409 item_conflict (it was 200 in our earlier recording), while the same new ID twice is still 200. The gateway returned 200 and 500 for those. It is addressed in f2c86be with re-recorded edge cases for both.

@tjtanaa tjtanaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One follow-up finding on the new duplicate-ID handling. Based on source and cassette inspection; I did not run tests.

…fixes

Signed-off-by: maral <maralbahari.98@gmail.com>

# Conflicts:
#	crates/agentic-server-core/tests/cassettes/record_cassette.py
Signed-off-by: maral <maralbahari.98@gmail.com>
@maralbahari

maralbahari commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

@franciscojavierarceo I have a commit to resolve conflict and address @tjtanaa comment but I dont have write access anymore

@maralbahari
maralbahari merged commit 3009689 into main Nov 18, 2026
15 checks passed
@maralbahari
maralbahari deleted the fix/admit-item-id-prefixes branch November 18, 2026 04:59
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.

Codex tool results are refused: function_call_output does not admit the fco_ ID prefix

3 participants