Skip to content

fix: clear jump_to state after each MessagesModelHook execution to prevent residual values#4423

Open
zhexueqi wants to merge 1 commit intoalibaba:mainfrom
zhexueqi:fix/messages-model-hook-jump-to-residual
Open

fix: clear jump_to state after each MessagesModelHook execution to prevent residual values#4423
zhexueqi wants to merge 1 commit intoalibaba:mainfrom
zhexueqi:fix/messages-model-hook-jump-to-residual

Conversation

@zhexueqi
Copy link
Copy Markdown

Problem

When a MessagesModelHook overrides canJumpTo() to return List.of(JumpTo.end), the framework registers a conditional edge that reads the jump_to field from state to decide routing.

Previously, if beforeModel() or afterModel() returned new AgentCommand(messages) (no jump intent), the jump_to field was not written to state. This left any residual value from a previous execution intact, causing the workflow to terminate prematurely even when the hook did not intend to jump.

Root Cause

In MessagesModelHook.BeforeModelAction and AfterModelAction:

// Before fix - only writes when jumpTo != null
if (command.getJumpTo() != null) {
    result.put("jump_to", command.getJumpTo().name());
}

Fix

Always write jump_to to state. When there is no jump intent, explicitly set null to clear any stale value from prior executions.

// After fix - always clears or sets jump_to
result.put("jump_to", command.getJumpTo() != null ? command.getJumpTo().name() : null);
Fixes #4421

…event residual values

When a MessagesModelHook overrides canJumpTo() to return List.of(JumpTo.end),
the framework registers a conditional edge that reads the jump_to field from state.
Previously, if beforeModel/afterModel returned AgentCommand without a JumpTo intent,
the jump_to field was not written to state, leaving any residual value from a
previous execution intact. This caused the workflow to terminate prematurely even
when the hook did not intend to jump.

Fix: Always write jump_to to state in BeforeModelAction and AfterModelAction.
When the AgentCommand has no JumpTo intent, explicitly set null to clear any
stale value from prior executions.

Fixes alibaba#4421
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 16, 2026

CLA assistant check
All committers have signed the CLA.

@zhexueqi zhexueqi changed the title fix: clear jump_to state after each MessagesModelHoofix: clear jump_to state after each MessagesModelHook execution to prevent residual valuesk execution to pr… fix: clear jump_to state after each MessagesModelHook execution to prevent residual values Mar 16, 2026
@wangliuliu1115
Copy link
Copy Markdown

I've verified this PR fixes the issue described in #4421. Thanks for the quick fix!

Tested on my local environment with the fix/messages-model-hook-jump-to-residual branch and it works as expected.

Thanks again!

@robocanic
Copy link
Copy Markdown
Collaborator

@robocanic

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.

[BUG] MessagesModelHook 跳转控制逻辑异常

4 participants