OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

[Bug]: Logs are not printed out in headless command line mode

Open neubig opened this issue 1 year ago • 7 comments

Is there an existing issue for the same bug?

  • [X] I have checked the existing issues.

Describe the bug and reproduction steps

Currently, in headless command line mode, logs of what the agents are doing is not printed out. This should be fixed.

To do so, it'd be good to first look at the documentation for headless mode, and then find a good place to add a subscription to the event stream like the following:

    async def on_event(evt):
        logger.info(evt)
    runtime.event_stream.subscribe(EventStreamSubscriber.MAIN, on_event, str(uuid4()))

OpenHands Installation

Development workflow

OpenHands Version

No response

Operating System

None

Logs, Errors, Screenshots, and Additional Context

No response

neubig avatar Nov 07 '24 13:11 neubig

OpenHands started fixing the issue! You can monitor the progress here.

github-actions[bot] avatar Nov 07 '24 13:11 github-actions[bot]

A potential fix has been generated and a draft PR #4821 has been created. Please review the changes.

github-actions[bot] avatar Nov 07 '24 14:11 github-actions[bot]

Can you please tell, is this fixed by https://github.com/All-Hands-AI/OpenHands/pull/4729 for a regular run and https://github.com/All-Hands-AI/OpenHands/pull/4710 for the resolver?

enyst avatar Nov 12 '24 23:11 enyst

Hey @enyst , sorry, I forgot about this but I'll take a look.

neubig avatar Nov 12 '24 23:11 neubig

I think I'm still having this issue, i didn't have output logs either in my command line run: https://github.com/All-Hands-AI/OpenHands/issues/5015

ryx2 avatar Nov 15 '24 04:11 ryx2

OpenHands started fixing the issue! You can monitor the progress here.

github-actions[bot] avatar Nov 27 '24 23:11 github-actions[bot]

An attempt was made to automatically fix this issue, but it was unsuccessful. A branch named 'openhands-fix-issue-4819-try2' has been created with the attempted changes. You can view the branch here. Manual intervention may be required.

github-actions[bot] avatar Nov 28 '24 00:11 github-actions[bot]

@neubig what are the logs we are looking for here? Tested a simple prompt for headless and seeing this:

15:48:27 - openhands:INFO: agent_controller.py:204 - [Agent Controller default] Starting step loop...
15:48:27 - USER_ACTION
[Agent Controller default] **MessageAction** (source=EventSource.USER)
CONTENT: write a bash script that prints hi
15:48:27 - openhands:INFO: agent_controller.py:347 - [Agent Controller default] Setting agent(CodeActAgent) state from AgentState.LOADING to AgentState.RUNNING
15:48:27 - OBSERVATION
[Agent Controller default] AgentStateChangedObservation(content='', agent_state=<AgentState.RUNNING: 'running'>, observation='agent_state_changed')
15:48:27 - OBSERVATION
[Agent Controller default] NullObservation(content='', observation='null')


==============
[Agent Controller default] LEVEL 0 LOCAL STEP 0 GLOBAL STEP 0

15:48:35 - ACTION
[Agent Controller default] **FileEditAction**
Thought: I'll help you create a simple bash script that prints "hi". I'll use the str_replace_editor to create this script.
Range: [L1:L-1]
Path: [/workspace/print_hi.sh]
Content:

15:48:35 - OBSERVATION
[Agent Controller default] File created successfully at: /workspace/print_hi.sh


==============
[Agent Controller default] LEVEL 0 LOCAL STEP 1 GLOBAL STEP 1

15:48:42 - ACTION
[Agent Controller default] **CmdRunAction (source=None)**
THOUGHT: Now, let's make the script executable and run it to test:
COMMAND:
chmod +x /workspace/print_hi.sh && ./print_hi.sh
15:48:42 - OBSERVATION
[Agent Controller default] **CmdOutputObservation (source=EventSource.AGENT, exit code=0)**
chmod +x /workspace/print_hi.sh && ./print_hi.sh
hi


==============
[Agent Controller default] LEVEL 0 LOCAL STEP 2 GLOBAL STEP 2

15:48:50 - ACTION
[Agent Controller default] **MessageAction** (source=None)
CONTENT: I've created a bash script called `print_hi.sh` that:
1. Has the proper shebang line (`#!/bin/bash`)
2. Uses the `echo` command to print "hi"
3. Has been made executable using `chmod +x`

The script is now ready to use and you can run it anytime by executing `./print_hi.sh` from the directory where it's located.
15:48:50 - openhands:INFO: agent_controller.py:347 - [Agent Controller default] Setting agent(CodeActAgent) state from AgentState.RUNNING to AgentState.AWAITING_USER_INPUT
15:48:50 - OBSERVATION
[Agent Controller default] AgentStateChangedObservation(content='', agent_state=<AgentState.AWAITING_USER_INPUT: 'awaiting_user_input'>, observation='agent_state_changed')

Has the issue been resolved or are there other logs we are looking for?

mamoodi avatar Dec 31 '24 15:12 mamoodi

Nevermind. Using python directly does not print the logs (it does with docker). I understand the issue now.

mamoodi avatar Dec 31 '24 16:12 mamoodi

Nevermind. Using python directly does not print the logs (it does with docker).

Even with LOG_ALL_EVENTS env var?

enyst avatar Dec 31 '24 17:12 enyst

How do you set that when you run it like this: poetry run python -m openhands.core.main -t "write a bash script that prints hi"

do you just export LOG_ALL_EVENTS=true?

mamoodi avatar Dec 31 '24 17:12 mamoodi

Yes

enyst avatar Dec 31 '24 17:12 enyst

Ah yep! Works if you have that env set....going to queue this up for adding to the headless doc. Thank you again for all your help! 🙏

mamoodi avatar Dec 31 '24 18:12 mamoodi

This is now documented https://docs.all-hands.dev/modules/usage/how-to/headless-mode#additional-logs

mamoodi avatar Jan 02 '25 18:01 mamoodi