Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Enhance logging for org-level microagent loading to improve debugging (#9471)

Robert Brennan9280bc34ad03
diff --git a/openhands/runtime/base.py b/openhands/runtime/base.py
index be103bf772..35ace653b3 100644
--- a/openhands/runtime/base.py
+++ b/openhands/runtime/base.py
@@ -565,9 +565,19 @@ fi
A list of loaded microagents
"""
loaded_microagents: list[BaseMicroagent] = []
+
+ self.log(
+ 'info',
+ f'Attempting to list files in {source_description} microagents directory: {microagents_dir}',
+ )
+
files = self.list_files(str(microagents_dir))
if not files:
+ self.log(
+ 'warning',
+ f'No files found in {source_description} microagents directory: {microagents_dir}',
+ )
return loaded_microagents
self.log(
@@ -705,15 +715,33 @@ fi
"""
loaded_microagents: list[BaseMicroagent] = []
+ self.log(
+ 'debug',
+ f'Starting org-level microagent loading for repository: {selected_repository}',
+ )
+
repo_parts = selected_repository.split('/')
+
if len(repo_parts) < 2:
+ self.log(
+ 'warning',
+ f'Repository path has insufficient parts ({len(repo_parts)} < 2), skipping org-level microagents',
+ )
return loaded_microagents
# Extract the domain and org/user name
org_name = repo_parts[-2]
+ self.log(
+ 'info',
+ f'Extracted org/user name: {org_name}',
+ )
# Determine if this is a GitLab repository
is_gitlab = self._is_gitlab_repository(selected_repository)
+ self.log(
+ 'debug',
+ f'Repository type detection - is_gitlab: {is_gitlab}',
+ )
# For GitLab, use openhands-config (since .openhands is not a valid repo name)
# For other providers, use .openhands
@@ -731,6 +759,10 @@ fi
try:
# Create a temporary directory for the org-level repo
org_repo_dir = self.workspace_root / f'org_openhands_{org_name}'
+ self.log(
+ 'debug',
+ f'Creating temporary directory for org repo: {org_repo_dir}',
+ )
# Get authenticated URL and do a shallow clone (--depth 1) for efficiency
try:
@@ -741,10 +773,19 @@ fi
self.git_provider_tokens,
)
except Exception as e:
+ self.log(
+ 'error',
+ f'Failed to get authenticated URL for {org_openhands_repo}: {str(e)}',
+ )
raise Exception(str(e))
+
clone_cmd = (
f'GIT_TERMINAL_PROMPT=0 git clone --depth 1 {remote_url} {org_repo_dir}'
)
+ self.log(
+ 'info',
+ 'Executing clone command for org-level repo',
+ )
action = CmdRunAction(command=clone_cmd)
obs = self.run_action(action)
@@ -757,17 +798,39 @@ fi
# Load microagents from the org-level repo
org_microagents_dir = org_repo_dir / 'microagents'
+ self.log(
+ 'info',
+ f'Looking for microagents in directory: {org_microagents_dir}',
+ )
+
loaded_microagents = self._load_microagents_from_directory(
org_microagents_dir, 'org-level'
)
+ self.log(
+ 'info',
+ f'Loaded {len(loaded_microagents)} microagents from org-level repository {org_openhands_repo}',
+ )
+
# Clean up the org repo directory
action = CmdRunAction(f'rm -rf {org_repo_dir}')
self.run_action(action)
else:
+ clone_error_msg = (
+ obs.content
+ if isinstance(obs, CmdOutputObservation)
+ else 'Unknown error'
+ )
+ exit_code = (
+ obs.exit_code if isinstance(obs, CmdOutputObservation) else 'N/A'
+ )
self.log(
'info',
- f'No org-level microagents found at {org_openhands_repo}',
+ f'No org-level microagents found at {org_openhands_repo} (exit_code: {exit_code})',
+ )
+ self.log(
+ 'debug',
+ f'Clone command output: {clone_error_msg}',
)
except Exception as e: