Skip to content

fix(server): drop all superseded routed experts across multi-turn trajectories - #653

Open
Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/events-drop-superseded-routed-experts
Open

Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/events-drop-superseded-routed-experts

Conversation

@hardikkaurani

Copy link
Copy Markdown

Summary

In _drop_superseded_routed_experts (agentlightning/server/routes/events.py), an unconditional return statement was located at the end of the backwards event loop. This caused the loop to terminate immediately upon inspecting the first model_request:

  1. If an intermediate model_request lacked routed_experts (or did not extend context, e.g. an unrouted turn or alternate step), the function returned early without checking earlier ancestor turns that had routed_experts.
  2. In multi-turn trajectories with 3 or more turns where multiple prior turns had routed_experts, only the immediately preceding turn was updated, leaving earlier turns with outdated route tensors.
  3. If token ID lists were empty ([]), prompt_ids[:len(previous_context)] == previous_context could evaluate to True even when no prompt tokens were present.

Changes

  • Removed the premature return inside the event iteration loop in _drop_superseded_routed_experts so that all superseded ancestor turns in the mergeable trajectory have their routed_experts dropped as intended.
  • Added explicit truthiness checks (bool(prompt_ids) and bool(previous_context)) before comparing prompt and context prefix matches.
  • Added regression tests in tests/server/test_endpoints.py verifying:
    • Multi-turn rollouts (Turn 1, Turn 2, Turn 3 with routed experts) correctly retain route tensors only on the latest turn.
    • Interleaved turns without routed experts do not prematurely abort scanning earlier matching ancestor turns.
    • Query parameter include_routed_experts=False correctly excludes route tensors.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@hardikkaurani

Copy link
Copy Markdown
Author

Hi Zhiyuan He (@hzy46), could you please take a look at this PR when you have a moment? It fixes an issue where superseded route tensors in multi-turn trajectories could be retained due to an early return in _drop_superseded_routed_experts, along with comprehensive test coverage. Thanks!

This branch has not been deployed

No deployments
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.

2 participants