Skip to content

SWF(bug): keep tool calls when replaying conversation history - #59

Merged
maplepaladin73 merged 2 commits into
mainfrom
devin/1795378313-conversation-tool-call-replay
Nov 23, 2026
Merged

maplepaladin73 merged 2 commits into
mainfrom
devin/1795378313-conversation-tool-call-replay

Conversation

@maplepaladin73

@maplepaladin73 maplepaladin73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Tool-call history now survives a /v1/responses conversation. Stored function_call and function_call_output items now replay as assistant tool calls and tool results instead of being dropped. Based on main, which includes #56 (ConversationStore::append_items), #60 (conversation_prefix_len) and #63.

Root cause: IncomingMessage::from_conversation_item required a role. Function-call items have no role, so it returned None and they vanished on replay. Also, both persistence paths stored every incoming message as a plain message item and never saved the assistant's emitted function calls. The blocking path is responses_translate.rs; the streaming path is responses_stream/conv_items.rs and responses_stream_finalize.rs.

Fix:

  • from_conversation_item passes function_call and function_call_output to the existing from_responses_input_item, so one parser handles both.
  • New IncomingMessage::to_conversation_items (in chat_message_conversation.rs) is the one conversion both persistence paths use. Tool results become function_call_output items and assistant tool_calls become function_call items. Both paths still skip the replayed prefix with SWF(bug): stop instructions carrying over via previous_response_id #60's conversation_prefix_len and write with SWF(bug): persist Responses conversation turns with more than 20 items #56's append_items.
  • The blocking and streaming finalize paths also save the response's FunctionCall output items.
  • Replay and request-input lowering fold function_call items into the previous assistant message (push_responses_message). Text plus parallel calls is then one assistant turn; templates like mistral.jinja reject two assistant roles in a row.

Test plan

These regression tests failed on main before the fix:

test openai::chat_message::tests::conversation_tool_call_replay ... FAILED
test api::responses_incomplete_tests::conversation_tool_call_replay_blocking_persistence ... FAILED
tool item must replay
assertion `left == right` failed: store both tool result and assistant call
  left: 1
 right: 2
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 3233 filtered out

The review-round regression failed before its fix:

test openai::chat_message::conversation::tests::conversation_assistant_turn_merges_text_and_parallel_calls ... FAILED
assertion `left == right` failed: one assistant turn for text and parallel calls
  left: 5
 right: 3

All results below are from the final head, rebased on main:

conversation_tool_call_replay        test result: ok. 4 passed; 0 failed
conversation                         test result: ok. 49 passed; 0 failed
responses                            test result: ok. 38 passed; 0 failed
responses_instructions_tests (#60)   test result: ok. 6 passed; 0 failed
persists_large_conversation_turn (#56) test result: ok. 2 passed; 0 failed
full --bin spark                     test result: ok. 3248 passed; 0 failed; 14 ignored

Try it:

ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test -p spark-server --bin spark conversation_tool_call_replay
  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --workspace --tests (clean)
  • bash scripts/check-license-headers.sh (0 invalid) and typos (clean)
  • Tested against a real model / hardware: not done. No GPU host was used, so there was no live HTTP or model round trip.
  • Added tests

Notes for reviewers


Software Factory opened this PR for Robert
Implemented in session Keep function-call items when replaying stored history
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Split assistant turns block Mistral replay — Reproduced (5 messages instead of 3); replay and request-input lowering now fold function_call items into the preceding assistant message via one shared helper.
  • Expanded turns lose conversation history — Reproduced (0 of 21 items saved; also reachable on main with 20 inputs + text). Internal turn persistence uses append_turn_items without the public 20-item cap; public add_items keeps the cap.

View findings in Devin Review · Follow Devin's work

Devin Review

@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795378313-conversation-tool-call-replay branch from 33b346c to 7f90ed3 Compare November 22, 2026 20:39
@devin-ai-integration
devin-ai-integration Bot changed the base branch from main to devin/1795378327-responses-persist-large-turns November 22, 2026 20:39
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795378313-conversation-tool-call-replay branch from 7f90ed3 to 5829c63 Compare November 22, 2026 22:15
@devin-ai-integration
devin-ai-integration Bot changed the base branch from devin/1795378327-responses-persist-large-turns to main November 22, 2026 22:15
maplepaladin73 and others added 2 commits November 22, 2026 22:24
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795378313-conversation-tool-call-replay branch from 5829c63 to 9aa7082 Compare November 22, 2026 22:27
@maplepaladin73
maplepaladin73 merged commit f176f2b into main Nov 23, 2026
1 check passed
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.

1 participant