fix(ai): a retried LLM chat task should keep its conversation history - #1480
Open
ling-senpeng13 wants to merge 1 commit into
Open
fix(ai): a retried LLM chat task should keep its conversation history#1480ling-senpeng13 wants to merge 1 commit into
ling-senpeng13 wants to merge 1 commit into
Conversation
manan164
requested changes
Aug 5, 2026
manan164
left a comment
Contributor
There was a problem hiding this comment.
Does this happen with all worker task that we lose input parameters on retry?
ling-senpeng13
force-pushed
the
fix/3876-mapper-snapshots-messages
branch
2 times, most recently
from
August 5, 2026 20:49
7805f7e to
c621c44
Compare
Contributor
Author
Yes — re-resolving taskToBeRetried.getInputData().putAll(taskInput); // taskToBeRescheduled |
NicholasDCole
requested changes
Aug 5, 2026
NicholasDCole
left a comment
Contributor
There was a problem hiding this comment.
Couple suggestions. Please check
ling-senpeng13
force-pushed
the
fix/3876-mapper-snapshots-messages
branch
2 times, most recently
from
August 6, 2026 00:22
5a7a242 to
e6eaf3c
Compare
manan164
approved these changes
Aug 6, 2026
ling-senpeng13
force-pushed
the
fix/3876-mapper-snapshots-messages
branch
from
August 6, 2026 15:55
ace2b3e to
5c5d139
Compare
v1r3n
requested changes
Aug 6, 2026
ling-senpeng13
force-pushed
the
fix/3876-mapper-snapshots-messages
branch
from
August 6, 2026 16:23
5c5d139 to
6a1976b
Compare
…on — both mappers, shared mechanism
Supersedes the snapshot approach with its inverse, and extends the fix to
the plain LLM_CHAT_COMPLETE mapper, which has the identical bug (its
getHistory() walks prior turns and f-string substitutes message text —
all imperative, all clobbered by retry's template re-resolution).
Retry and rerun do not re-run task mappers: they copy the task and
re-resolve the carried WorkflowTask definition's inputParameters over it,
overwriting mapper-assembled input with the static template. Instead of
snapshotting the assembled messages INTO a task-owned definition copy —
which round-trips conversation content through the template engine on
retry (text containing ${...} would be re-interpreted) and doubles the
task payload — DETACH the assembled keys from the task-owned copy:
re-resolution then never produces those keys, and the copied attempt's
own inputData, the exact conversation the first attempt used, survives
retry and rerun untouched.
The shared helper lives in AIModelTaskMapper and is called by both chat
mappers; the deep copy protects the cached WorkflowDef's shared instance,
and new schedules (including DO_WHILE iterations) map from the
definition's own instance, so they are unaffected.
Tests: detach semantics, retry simulation (replicating
taskToBeRescheduled's copy+putAll) preserving the conversation, a
negative control documenting the pre-fix clobber, template-pattern
content surviving verbatim, shared-definition immutability, no-op and
null paths. ai+agentspan suites: 1301 tests green.
ling-senpeng13
force-pushed
the
fix/3876-mapper-snapshots-messages
branch
from
August 6, 2026 19:06
82f6038 to
4a401f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Retrying an
LLM_CHAT_COMPLETEtask in an agent workflow loses the entire conversation. The retried attempt sees only the static[system, user]template from the workflow definition, not the history the first attempt had.Why it happens
Conversation history is never expressed as a
${...}reference in the workflow definition.AgentChatCompleteTaskMapperassembles it imperatively in Java at scheduling time — walking the workflow's completed tasks, extracting tool results, condensing if the context window demands it — and writes the result into the task'sinputData.Retry doesn't re-run the mapper. It copies the task and re-resolves the definition:
Since the definition's
inputParameterscontain only the static template,putAlloverwrites the assembled conversation with it. The history existed solely in the first attempt'sinputData, and that's what gets replaced.Fix
The mapper strips
messagesandtoolsfrom the task's own copy of the definition before it's persisted, so at retry timegetWorkflowTask().getInputParameters()doesn't have them, the re-resolvedtaskInputintaskToBeRescheduled()doesn't have them, andputAllcan't overwrite the assembled values which is the root cause of this bug.AIModelTaskMapper#detachAssembledInputFromDefinition(TaskModel, String... keys), shared by both chat-complete mappers.Testing