Skip to content

fix(workflow): preserve routes when flushing and delegating output - #7931

Closed
1828703450qqcom-ux wants to merge 2 commits into
google:mainfrom
1828703450qqcom-ux:fix/workflow-preserve-route-with-deltas
Closed

1828703450qqcom-ux wants to merge 2 commits into
google:mainfrom
1828703450qqcom-ux:fix/workflow-preserve-route-with-deltas

Conversation

@1828703450qqcom-ux

@1828703450qqcom-ux 1828703450qqcom-ux commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Closes: #7930

Problem: Workflow routes can disappear from persisted events in two output-publication paths. The initial execution still follows the Context's route, but a parent retry cannot recover that decision and silently ends the selected branch instead of retrying its failed node.

  • A node sets deferred output, a route, and state/artifact deltas. The final flush constructs the route, then replaces the actions object with the deltas, discarding the route.
  • A parent delegates output with ctx.run_node(..., use_as_output=True) and returns Event(output=answer, route=...). Suppressing the duplicate output drops the entire parent event unless it has state/artifact deltas, so its route is lost too.

Solution: Merge deferred deltas into the event's existing actions using _flush_deltas. When suppressing delegated output, retain a parent event that carries a route and clear only its duplicate output. Check against None so False, 0, and an empty route list remain meaningful. The child result is still published exactly once.

Testing Plan

Unit and integration tests:

  • Original main: three deferred-delta combinations fail (state, artifact, both), while the no-delta control passes. The real Runner parent-retry integration case fails too.
  • Before the delegated-output addition, four public Runner regressions lose routes ('next', False, 0, []) and a delegated parent-retry case fails. All pass after the fix, while asserting a single published child output.
  • Three affected workflow test modules: 87 passed on each of Python 3.11, 3.12 and 3.14.
  • Complete workflow suite on Python 3.13: 1300 passed, 2 failed, 1 xfailed. Both failures are test_execute_bash_tool_node_runs_command_after_approval[False/True], which also fail on unchanged main on Windows: ExecuteBashTool explicitly supports POSIX only.
  • Source mypy compared with main using CI's line-number-normalized diagnostics: 258 existing diagnostics on each tree, zero new diagnostics.
  • Pre-commit formatting, imports, license, Ruff and spelling checks pass. Windows-incompatible shebang hooks were run through their Python entry points instead: new-file/guide checks, compliance and documentation checks all pass.
  • git diff --check passes.

Manual End-to-End (E2E):

Ran standalone scripts with real Runner, App, InMemorySessionService and public Workflow/Node APIs, with no model or cloud connection. An outer driver with a two-attempt retry policy invokes a nested workflow. Its router selects one branch; that branch fails once and succeeds on its second call. The other branch must never run.

Both the deferred state-writing router and the output-delegating router exhibit the bug on main: router runs once, selected branch runs once, no saved route, final result missing. With the fixes, router runs once, selected branch runs twice, other branch runs zero times, the route is saved, and the final result is produced. Repository regressions exercise these scenarios with the invariant-enabled Runner fixture.

Checklist

  • Read the contribution guide and reviewed the change.
  • Added failing regressions and manually tested public execution paths.
  • Recorded baseline platform failures and type diagnostics explicitly.
  • No public API or dependency changes.

AI assistance: Codex investigated, implemented, and verified this change.

Merge pending state and artifact changes into the existing event actions instead of replacing the actions object. Keep the route persisted so a parent retry can resume the selected workflow branch.

Fixes google#7930
@google-cla

google-cla Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@1828703450qqcom-ux
1828703450qqcom-ux marked this pull request as ready for review November 2, 2026 07:40
Keep a route-bearing parent event when its duplicate delegated output is suppressed. Preserve false, zero, and empty-list routes, and prove parent retry follows the saved branch without duplicating child output.
@1828703450qqcom-ux 1828703450qqcom-ux changed the title fix(workflow): preserve deferred routes alongside state deltas fix(workflow): preserve routes when flushing and delegating output Nov 2, 2026
copybara-service Bot pushed a commit that referenced this pull request Nov 2, 2026
Merge #7931

A node's final flushed event now keeps its route when it also carries state
or artifact deltas, and a parent that delegates its output with
`use_as_output=True` now persists its routing event (with the duplicate output
cleared) instead of dropping it. A parent retry can then rerun the selected
branch from the recorded route.

Closes #7930

PiperOrigin-RevId: 1012267523
@adk-bot

adk-bot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Thank you @1828703450qqcom-ux for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit af6f671.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Nov 2, 2026
@adk-bot adk-bot closed this Nov 2, 2026
@1828703450qqcom-ux
1828703450qqcom-ux deleted the fix/workflow-preserve-route-with-deltas branch November 2, 2026 20:27
@1828703450qqcom-ux
1828703450qqcom-ux restored the fix/workflow-preserve-route-with-deltas branch November 2, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow parent retry loses a deferred route when the node also writes deltas

3 participants