-
Notifications
You must be signed in to change notification settings - Fork 478
Bug Fix:Prevent duplicate rollouts caused by stale task requeue + lat… #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e worker submission
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces an attempt-based tracking mechanism to prevent duplicate rollouts caused by stale task requeuing in the AgentLightning system.
- Adds
attempt_idfields toTaskandRolloutmodels to track task claim attempts - Implements validation logic in the server to reject rollouts from outdated task attempts
- Updates worker code to include
attempt_idwhen submitting rollouts
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agentlightning/types.py | Adds attempt_id field to both Task and Rollout models |
| agentlightning/server.py | Generates unique attempt IDs for task claims and validates them when storing rollouts |
| agentlightning/runner.py | Updates rollout creation to include the task's attempt ID |
Comments suppressed due to low confidence (1)
agentlightning/types.py:1
- [nitpick] The comment on line 77 is duplicated from line 72. Consider updating it to be more specific about the attempt_id field, such as '# Unique identifier for each task claim attempt'.
from typing import Any, Dict, List, Optional, Union, Literal, Annotated
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| logger.warning(f"Ignoring rollout {rollout.rollout_id}: task not in processing anymore") | ||
| return # drop stale result | ||
|
|
||
| if getattr(rollout, "attempt_id", None) != current_task.attempt_id: |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using getattr with a default value is unnecessary since rollout.attempt_id is a defined field in the Rollout model. Consider using direct attribute access: rollout.attempt_id != current_task.attempt_id.
| if getattr(rollout, "attempt_id", None) != current_task.attempt_id: | |
| if rollout.attempt_id != current_task.attempt_id: |
| rollout_obj = Rollout(rollout_id=task.rollout_id, attempt_id=task.attempt_id) # Default empty rollout | ||
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra trailing space on line 230 that should be removed.
| rollout_obj = Rollout(rollout_id=task.rollout_id, attempt_id=task.attempt_id) # Default empty rollout | |
|
In server.py, we already had a |
This PR addresses an issue with stale task requeueing that could cause duplicate rollouts to be received and stored.
Problem
_check_and_requeue_stale_tasks)./rollout.or led to rollout id key error because this rollout is not from current batch

Solution
/task, a newattempt_id(UUID) is generated.attempt_idwhen submitting rollouts.attempt_idmatches the currently active one in_processing_tasks.This ensures at most one valid rollout is stored per logical task, and late stale results will not break training.
Changes
Taskto includeattempt_id.get_next_taskassigns a newattempt_idupon each claim.store_rolloutvalidates theattempt_idbefore accepting results.Why this is important
Related issues
AssertionError: assert len(self._completed_rollouts) == self._total_tasks_queuedcaused by duplicate rollouts from stale tasks.