fix: make operation report resilient to deleted agents#3341
Open
fix: make operation report resilient to deleted agents#3341
Conversation
Operations that reference agents which have been deleted would error when generating reports or viewing in the UI. Now falls back to using link.paw from the chain when agent objects are missing.
Contributor
There was a problem hiding this comment.
Pull request overview
Improves Operation reporting and link-wait logic so the UI/report generation doesn’t crash when links reference agents that were removed mid-operation.
Changes:
- Avoids
IndexErrorinwait_for_links_completion()when an agent referenced by a link no longer exists inself.agents. - Makes
report()include paws seen inself.chain(in addition toself.agents) so deleted agents still show up in the report. - Makes
get_skipped_abilities_by_agent()tolerate missing ability entries for an agent.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/objects/test_operation.py | Adds regression tests ensuring report() works with deleted agents (empty/partial agent list). |
| app/objects/c_operation.py | Hardens link-wait and reporting codepaths against deleted agents and missing ability mappings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
258
to
+263
| link = [link for link in self.chain if link.id == link_id][0] | ||
| if link.can_ignore(): | ||
| self.add_ignored_link(link.id) | ||
| member = [member for member in self.agents if member.paw == link.paw][0] | ||
| members = [member for member in self.agents if member.paw == link.paw] | ||
| if not members: | ||
| continue |
Comment on lines
258
to
+261
| link = [link for link in self.chain if link.id == link_id][0] | ||
| if link.can_ignore(): | ||
| self.add_ignored_link(link.id) | ||
| member = [member for member in self.agents if member.paw == link.paw][0] | ||
| members = [member for member in self.agents if member.paw == link.paw] |
Comment on lines
+319
to
+323
| agent_paw_map = {a.paw: a for a in self.agents} | ||
| chain_paws = {link.paw for link in self.chain} | ||
| all_paws = set(agent_paw_map.keys()) | chain_paws | ||
| host_group = [agent_paw_map[p].display if p in agent_paw_map else dict(paw=p) | ||
| for p in all_paws] |
| abilities_by_agent = await self._get_all_possible_abilities_by_agent(data_svc) | ||
| skipped_abilities = [] | ||
| for agent in self.agents: | ||
| if agent.paw not in abilities_by_agent: |
| for p in all_paws] | ||
| report = dict(name=self.name, host_group=host_group, | ||
| start=self.start.strftime(self.TIME_FORMAT), | ||
| steps=[], finish=self.finish, planner=self.planner.name, adversary=self.adversary.display, |
| if isinstance(entry, dict) and 'paw' in entry: | ||
| paws_in_host_group.append(entry['paw']) | ||
| elif hasattr(entry, 'get') and entry.get('paw'): | ||
| paws_in_host_group.append(entry['paw']) |
|
|
❌ The last analysis has failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
IndexErrorinwait_for_links_completion()when an agent referenced by a link has been deleted from the operationreport()to buildhost_groupandagents_stepsfrom bothself.agentsAND unique paws inself.chain, so deleted agents still appear in reportsget_skipped_abilities_by_agent()to skip agents missing from the abilities mapDetails
When an agent participates in an operation and is later deleted, viewing that operation in the UI would crash because:
wait_for_links_completionused[0]indexing on a filtered list that could be emptyreport()builthost_groupandagents_stepsonly fromself.agents, missing chain links from deleted agentsget_skipped_abilities_by_agentassumed all agents would be in the abilities mapThe fix uses
self.chainlink paws as source of truth alongsideself.agents, with safe fallbacks for missing agent objects.Test plan
test_report_with_empty_agents_and_chain_links- verifies report works when all agents deleted but chain has linkstest_report_with_partial_deleted_agents- verifies report includes steps from both present and deleted agentstest_report_includes_steps_for_agents_not_in_host_groupcontinues to pass