-
Notifications
You must be signed in to change notification settings - Fork 120
[sandbox]add task id to sandbox #834
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -67,9 +67,35 @@ async def do_run(self, context: Context = None): | |||||
| if not self.task.is_sub_task: | ||||||
| logger.info(f'main task {self.task.id} will mark outputs finished') | ||||||
| await self.task.outputs.mark_completed(resp if resp is not None else self._response()) | ||||||
| for _, agent in AgentFactory._agent_instance.items(): | ||||||
| # Snapshot to avoid iteration issues if AgentFactory registry changes during awaits. | ||||||
| agents_snapshot = list(AgentFactory._agent_instance.values()) | ||||||
| for agent in agents_snapshot: | ||||||
| if agent and agent.sandbox: | ||||||
| await agent.sandbox.cleanup() | ||||||
| sandbox = agent.sandbox | ||||||
| # task_list tracks which root-tasks are using this sandbox. | ||||||
| # Only cleanup when the current task id is no longer referenced. | ||||||
| try: | ||||||
| metadata = getattr(sandbox, "metadata", {}) | ||||||
| task_list = metadata.get("task_list", []) | ||||||
|
|
||||||
| # If we can't find/understand task_list, fallback to original behavior. | ||||||
| if not task_list: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check
Suggested change
|
||||||
| await sandbox.cleanup() | ||||||
| continue | ||||||
|
|
||||||
| # Remove current task id from task_list (dedup by deletion). | ||||||
| task_id = self.task.id | ||||||
| if task_id in task_list: | ||||||
| task_list.remove(task_id) | ||||||
| if len(task_list) == 0: | ||||||
| await sandbox.cleanup() | ||||||
|
|
||||||
| except Exception as e: | ||||||
| logger.warning( | ||||||
| f"Failed to manage sandbox cleanup for agent {agent.id() if hasattr(agent, 'id') else ''}: {e}" | ||||||
| ) | ||||||
| # Keep the original semantics to avoid leaked resources. | ||||||
| await sandbox.cleanup() | ||||||
| # Release trajectory storage to free memory; trajectories have already | ||||||
| # been persisted by _save_trajectories() before reaching this point. | ||||||
| self.context.trajectory_dataset = None | ||||||
|
|
||||||
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.
This block for getting or initializing
task_listcan be simplified. Usingdict.setdefault()is more concise and Pythonic.Consider replacing lines 296-299 with: