Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: "Failed to parse PS1 metadata" on empty command #6826

Open
1 task done
neubig opened this issue Feb 19, 2025 · 1 comment · May be fixed by #6831
Open
1 task done

[Bug]: "Failed to parse PS1 metadata" on empty command #6826

neubig opened this issue Feb 19, 2025 · 1 comment · May be fixed by #6831
Labels
bug Something isn't working openhands Have Openhands attempt to fix the issue (via GH App) terminal/commands Related to the terminal or OpenHands running commands

Comments

@neubig
Copy link
Contributor

neubig commented Feb 19, 2025

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Describe the bug and reproduction steps

I got an error when OpenHands tried to send an empty command:

Image

Here is the log that I got:

2025-02-19T11:58:43.975319525Z �[92m11:58:43 - openhands:WARNING�[0m: commands.py:62 - Failed to parse PS1 metadata: 
2025-02-19T11:58:43.975365215Z {
2025-02-19T11:58:43.975370405Z   \"pid\": \"$!\",
2025-02-19T11:58:43.975374395Z   \"exit_code\": \"$?\",
2025-02-19T11:58:43.975378095Z   \"username\": \"\\u\",
2025-02-19T11:58:43.975382285Z   \"hostname\": \"\\h\",
2025-02-19T11:58:43.975386975Z   \"working_dir\": \"$(pwd)\",
2025-02-19T11:58:43.975391545Z   \"py_interpreter_path\": \"$(which python 2>/dev/null || echo \\"\\")\"
2025-02-19T11:58:43.975396725Z }
2025-02-19T11:58:43.975403165Z . Skipping.Traceback (most recent call last):
2025-02-19T11:58:43.975408875Z   File "/openhands/code/openhands/events/observation/commands.py", line 59, in matches_ps1_metadata
2025-02-19T11:58:43.975414715Z     json.loads(match.group(1).strip())  # Try to parse as JSON
2025-02-19T11:58:43.975419535Z     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-02-19T11:58:43.975424075Z   File "/openhands/micromamba/envs/openhands/lib/python3.12/json/__init__.py", line 346, in loads
2025-02-19T11:58:43.975428765Z     return _default_decoder.decode(s)
2025-02-19T11:58:43.975433355Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-02-19T11:58:43.975438505Z   File "/openhands/micromamba/envs/openhands/lib/python3.12/json/decoder.py", line 338, in decode
2025-02-19T11:58:43.975442385Z     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
2025-02-19T11:58:43.975446185Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-02-19T11:58:43.975450045Z   File "/openhands/micromamba/envs/openhands/lib/python3.12/json/decoder.py", line 354, in raw_decode
2025-02-19T11:58:43.975453775Z     obj, end = self.scan_once(s, idx)
2025-02-19T11:58:43.975457605Z                ^^^^^^^^^^^^^^^^^^^^^^
2025-02-19T11:58:43.975475875Z json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)
2025-02-19T11:58:43.975480195Z 

It would be good if we could write a test to check if this parsing works when OpenHands sends an empty command.

OpenHands Installation

app.all-hands.dev

OpenHands Version

0.24.0

Operating System

None

Logs, Errors, Screenshots, and Additional Context

No response

@neubig neubig added bug Something isn't working openhands Have Openhands attempt to fix the issue (via GH App) labels Feb 19, 2025
Copy link

openhands-ai bot commented Feb 19, 2025

I'm working on a fix! neubig can track my progress at all-hands.dev

neubig pushed a commit that referenced this issue Feb 19, 2025
- Add .replace(r'"', '"') to unescape quotes before parsing JSON in matches_ps1_metadata and from_ps1_match
- Add test to verify PS1 metadata parsing works correctly
- Fixes #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
The issue was not with escaped quotes, but with backslashes in the JSON values
being treated as literal backslashes. Fixed by properly escaping them with
double backslashes.

Fixes #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
- Rename test to test_empty_command_ps1_metadata to reflect its purpose
- Add test case with empty command to match the actual issue
- Add better assertions for backslash handling
- Add docstring explaining the test's purpose

Part of #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
- Rename test to test_empty_command_ps1_metadata to reflect its purpose
- Add test case with empty command to match the actual issue
- Add better assertions for backslash handling
- Add docstring explaining the test's purpose

Part of #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
- Rename test to test_empty_command_ps1_metadata to reflect its purpose
- Add test case with empty command to match the actual issue
- Add better assertions for backslash handling
- Add docstring explaining the test's purpose

Part of #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
- Rename test to test_empty_command_ps1_metadata to reflect its purpose
- Add test case with empty command to match the actual issue
- Add better assertions for backslash handling
- Add docstring explaining the test's purpose

Part of #6826
neubig pushed a commit that referenced this issue Feb 19, 2025
- Use raw strings for backslash sequences in PS1 metadata
- Remove unnecessary quote escaping since json.dumps already handles it
- Add tests to verify PS1 metadata parsing works correctly
- Fixes #6826
@neubig neubig linked a pull request Feb 19, 2025 that will close this issue
@mamoodi mamoodi added the terminal/commands Related to the terminal or OpenHands running commands label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openhands Have Openhands attempt to fix the issue (via GH App) terminal/commands Related to the terminal or OpenHands running commands
Projects
None yet
2 participants