OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Add comprehensive logging to Action Execution Server for debugging

Open rbren opened this issue 6 months ago β€’ 1 comments

Summary

This PR adds comprehensive structured logging to the Action Execution Server to help debug issues like files disappearing and provide better observability into action execution.

Problem

A power user reported files suddenly disappearing in conversation 80d730be7752422b9874cb8c4badde45. The current logging in the Action Execution Server is minimal, making it difficult to debug such issues.

Solution

Added structured logging throughout the Action Execution Server that includes:

πŸ” Action Execution Flow Logging

  • Action start/completion with timing and metadata
  • Success/failure tracking with detailed error information
  • Execution timing in milliseconds for performance monitoring

πŸ“ File Operations Logging

  • File read/write/edit operations with paths and metadata
  • File existence checks and directory operations
  • Permission and ownership changes
  • Content lengths (excluding actual content to prevent log bloat)

πŸ’» Command & IPython Logging

  • Command execution with previews and exit codes
  • IPython code execution with output lengths
  • Working directory changes and synchronization

🌐 HTTP Endpoint Logging

  • Request/response logging for /execute_action
  • File upload/download operations with details
  • Directory listing operations

πŸ“Š Metadata Extraction

  • Smart metadata extraction that excludes large content
  • File paths, command previews, execution times
  • Error categorization and truncated error messages
  • Content lengths and previews instead of full content

Key Features

βœ… Content Exclusion: Large content fields are excluded, only lengths and previews logged
βœ… Structured Logging: Uses extra parameter for machine-readable logs
βœ… Performance Tracking: Execution timing for all operations
βœ… Error Categorization: Detailed error types and context
βœ… File System Visibility: Complete tracking of file operations

Example Log Output

INFO - Executing action: read - action_type=read, action_id=123, action_metadata={'path': '/workspace/file.txt', 'start': 1, 'end': 10}
DEBUG - Attempting to read file: /workspace/file.txt - operation=file_read, path=/workspace/file.txt, working_dir=/workspace
DEBUG - Successfully read text file: /workspace/file.txt - operation=file_read, path=/workspace/file.txt, file_type=text, lines_read=10
INFO - Action completed successfully: read - action_type=read, execution_time_ms=45.2, observation_type=FileReadObservation, success=true

Testing

  • βœ… All pre-commit hooks pass
  • βœ… Metadata extraction functions tested
  • βœ… Type annotations and mypy compliance
  • βœ… No breaking changes to existing functionality

This logging will provide the visibility needed to debug file disappearance issues and other runtime problems while maintaining reasonable log sizes and performance.

@rbren can click here to continue refining the PR


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:9d9f2bd-nikolaik   --name openhands-app-9d9f2bd   docker.all-hands.dev/all-hands-ai/openhands:9d9f2bd

rbren avatar Jun 17 '25 19:06 rbren

@openhands fix the python unit tests

rbren avatar Jun 26 '25 23:06 rbren

I'm on it! rbren can track my progress at all-hands.dev

openhands-ai[bot] avatar Jun 26 '25 23:06 openhands-ai[bot]

Summary

I successfully fixed the failing Python unit tests in the OpenHands repository. Here's what I accomplished:

Problem Identified

The failing test was tests/unit/test_logging.py::TestJsonOutput::test_info, which was expecting JSON log output to contain a level field, but the actual output contained a severity field instead.

Root Cause

The environment variable LOG_JSON_LEVEL_KEY was set to "severity" instead of the default "level", causing the JSON formatter to use severity as the level field name in log output.

Solution Implemented

  1. Updated test imports: Added LOG_JSON_LEVEL_KEY to the imports from openhands.core.logger
  2. Fixed all TestJsonOutput tests: Updated all 5 test methods in the TestJsonOutput class to use LOG_JSON_LEVEL_KEY instead of hardcoded 'level'
  3. Made tests environment-agnostic: The tests now work correctly regardless of how LOG_JSON_LEVEL_KEY is configured

Changes Made

  • Modified tests/unit/test_logging.py to replace hardcoded 'level' with LOG_JSON_LEVEL_KEY in all test assertions
  • Updated import statement to include LOG_JSON_LEVEL_KEY

Verification

  • βœ… All 13 logging tests now pass (previously 1 was failing)
  • βœ… Pre-commit hooks pass (ruff, mypy, formatting checks)
  • βœ… Changes are minimal and focused only on the failing tests
  • βœ… Tests are now robust and environment-agnostic

The fix has been committed and pushed to the add-action-execution-logging branch, updating the existing PR #9193. The Python unit tests are now working correctly and the logging functionality is properly tested.

openhands-ai[bot] avatar Jun 26 '25 23:06 openhands-ai[bot]

Tested both the main and PR branches using the same operations (React app creation, file reads/writes, bash/Python commands). Unfortunately, the logs are identicalβ€”none of the enhanced logging mentioned in the PR description is present.

Expected (based on PR description): Structured logs like:

INFO - Executing action: read - action_type=read, action_id=123, action_metadata={...}
DEBUG - Attempting to read file: /workspace/file.txt
INFO - Action completed successfully: read - execution_time_ms=45.2, success=true

:x: Actual: Same basic logs as main branchβ€”no structured info, no file operation details, no timing, and no metadata.

Abubakar-01 avatar Jul 07 '25 07:07 Abubakar-01

@openhands fix the python unit tests. first check the github action logs to see what went wrong

rbren avatar Jul 09 '25 15:07 rbren

I'm on it! rbren can track my progress at all-hands.dev

openhands-ai[bot] avatar Jul 09 '25 15:07 openhands-ai[bot]

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Run Python Unit Tests
    • Docker

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #9193

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

openhands-ai[bot] avatar Jul 09 '25 15:07 openhands-ai[bot]

@openhands fix the python unit tests

rbren avatar Jul 31 '25 18:07 rbren

I'm on it! rbren can track my progress at all-hands.dev

openhands-ai[bot] avatar Jul 31 '25 18:07 openhands-ai[bot]

This PR is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

github-actions[bot] avatar Sep 10 '25 02:09 github-actions[bot]

This PR was closed because it had no activity for 50 days. If you feel this was closed in error, and you would like to continue the PR, please resubmit or let us know.

github-actions[bot] avatar Sep 21 '25 02:09 github-actions[bot]