Skip to content

Commit

Permalink
Hotfix 2 for 10609
Browse files Browse the repository at this point in the history
  • Loading branch information
Domiii committed Dec 8, 2024
1 parent 3a5d090 commit ce4e90f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
20 changes: 20 additions & 0 deletions openhands/core/logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import copy
import copyreg
import logging
import os
import re
import sys
import traceback
from datetime import datetime
from types import TracebackType
from typing import Literal, Mapping

from termcolor import colored
Expand Down Expand Up @@ -48,6 +50,24 @@
}


# Handle pickling of tracebacks and other non-serializables:
def pickle_traceback(tb):
# Extract a summary of the traceback
extracted = traceback.extract_tb(tb)
# Return the function for reconstruction (unpickle_traceback) and the args
return (unpickle_traceback, (extracted,))


def unpickle_traceback(extracted):
# We cannot reconstruct a real traceback object easily, but we return the summary.
# The returned object now is a list of traceback.FrameSummary instances.
return extracted


# Register our custom handler
copyreg.pickle(TracebackType, pickle_traceback)


class NoColorFormatter(logging.Formatter):
"""Formatter for non-colored logging in files."""

Expand Down
8 changes: 3 additions & 5 deletions openhands/events/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ def command_annotate_execution_points(
) -> ReplayCmdRunAction:
# NOTE: For the resolver, the workdir path is the repo path.
# In that case, we should not append the repo name to the path.
isWorkspaceRepoPath = ' -i' if is_workspace_repo else ''
is_repo_flag = ' -i' if is_workspace_repo else ''
# If the workspace is the repo, it should already have been hard reset.
forceDelete = ' -f' if not is_workspace_repo else ''
command = (
f'"annotate-execution-points" -w "$(pwd)"{forceDelete}{isWorkspaceRepoPath}'
)
force_flag = ' -f' if not is_workspace_repo else ''
command = f'"annotate-execution-points" -w "$(pwd)"{is_repo_flag}{force_flag}'
action = ReplayCmdRunAction(
thought=thought,
command=command,
Expand Down
9 changes: 4 additions & 5 deletions openhands/runtime/action_execution_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import shutil
import tempfile
import time
import traceback
from contextlib import asynccontextmanager
from pathlib import Path
from zipfile import ZipFile
Expand Down Expand Up @@ -447,17 +448,15 @@ async def execute_action(action_request: ActionRequest):
if not isinstance(action, Action):
raise HTTPException(status_code=400, detail='Invalid action type')
client.last_execution_time = time.time()
# TODO: This log entry never appears.
logger.warning('DDBG Executing action A')
observation = await client.run_action(action)
return event_to_dict(observation)
except Exception as e:
logger.warning('DDBG Executing action ERROR')
# TODO: This code never seems to get executed.
# TODO: This log entry never appears.
logger.error(
f'Error processing command: {str(e)}', exc_info=True, stack_info=True
)
raise HTTPException(status_code=500, detail=str(e))
detail = f'{type(e).__name__}: {str(e)}\n STACK: {''.join(traceback.format_tb(e.__traceback__))}'
raise HTTPException(status_code=500, detail=detail)

@app.post('/upload_file')
async def upload_file(
Expand Down
13 changes: 13 additions & 0 deletions openhands/runtime/impl/eventstream/eventstream_runtime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import atexit
import json
import os
import tempfile
import threading
Expand Down Expand Up @@ -548,6 +549,18 @@ def run_action(self, action: Action) -> Observation:
raise RuntimeError(
f'Runtime failed to return execute_action before the requested timeout of {action.timeout}s'
)
# New:
except requests.exceptions.HTTPError as e:
try:
# NOTE: `detail` gets sent in the body, inside the `message` field.
detail = json.dumps(e.response.json().get('message'), indent=2)
except (ValueError, AttributeError):
# Use `text` as fallback, if JSON parsing fails.
detail = e.response.text if hasattr(e.response, 'text') else str(e)

raise RuntimeError(
f'Runtime execute_action ERROR: {str(e)}\n' f' detail=\n{detail}'
)
self._refresh_logs()
return obs

Expand Down

0 comments on commit ce4e90f

Please sign in to comment.