OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Failing to Save Trajectory from CLI Mode Run

Open ShoumikSaha opened this issue 6 months ago • 9 comments

I am running OpenHands using the CLI mode through docker.

docker run -it \
    --pull=always \
    -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.40-nikolaik \
    -e SANDBOX_USER_ID=$(id -u) \
    -e SANDBOX_VOLUMES=$SANDBOX_VOLUMES \
    -e LLM_MODEL=$LLM_MODEL \
    -e LLM_NUM_RETRIES=$LLM_NUM_RETRIES \
    -e LLM_RETRY_MIN_WAIT=$LLM_RETRY_MIN_WAIT \
    -e LLM_RETRY_MAX_WAIT=$LLM_RETRY_MAX_WAIT \
    -e LOG_ALL_EVENTS=$LOG_ALL_EVENTS \
    -e DEBUG_RUNTIME=$DEBUG_RUNTIME \
    -e LOG_TO_FILE=$LOG_TO_FILE \
    -e LOG_JSON=$LOG_JSON \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ~/.openhands-state:/.openhands-state \
    --add-host host.docker.internal:host-gateway \
    --name openhands-app-$(date +%Y%m%d%H%M%S) \
    docker.all-hands.dev/all-hands-ai/openhands:0.40 \
    python -m openhands.cli.main --override-cli-mode true

I am able to prompt and run the agent perfectly. However, no trajectory file is getting saved anywhere.

Here's the config.toml file:

[core]
workspace_base="./workspace"
save_trajectory_path="./trajectories"
run_as_openhands = true
cache_dir = "./tmp/cache"
debug = true

[llm]
model="bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0"
temperature = 0.0
aws_access_key_id = "xxx"
aws_region_name = "xxx"
aws_secret_access_key = "xxx"
num_retries = 5
retry_max_wait = 120
retry_min_wait = 30

[agent]
enable_browsing = true
enable_editor = true
enable_cmd = true

[security]
confirmation_mode = false

Am I missing something? Any direction would be helpful.

ShoumikSaha avatar Jun 05 '25 01:06 ShoumikSaha

@ShoumikSaha on your local machine, inside the ~/.openhands-state folder, there should be a sessions folder. Is that not the case?

mamoodi avatar Jun 05 '25 13:06 mamoodi

I am also experiencing this. I have checked the provided save_trajectory_path and the openhands-state folders but sessions are not saved. I am using -n sessionName and it is saving sessions correctly in headless mode but not in CLI mode.

saves session correctly at save_trajectory_path: python -m openhands.core.main -t "write a bash script that prints hi" --config config.toml -n S1 Doesn't save session: python -m openhands.cli.main --override-cli-mode True --config config.toml -n S1

rbrugaro avatar Jun 05 '25 17:06 rbrugaro

@rbren did something change on the CLI side here?

mamoodi avatar Jun 05 '25 17:06 mamoodi

@mamoodi No, there is no sessions folder under the ~/.openhands-state folder.

ShoumikSaha avatar Jun 05 '25 17:06 ShoumikSaha

Hmm can you try adding -e FILE_STORE_PATH=/.openhands-state?

rbren avatar Jun 05 '25 23:06 rbren

I think might be a permission error between the userid and the folder ownership. Setting FILE_STORE_PATH i get a permission error. An error occurred: [Errno 13] Permission denied: '/.openhands-state' In my config file I have:

#user_id = 1000   
run_as_openhands = false 

and from the runtime container /.openhands-state is owned by root. In my case I have a volume mount to this path which is also owned by root on the host. Maybe the writting of trajectories uses a userid despite the above configs?

I think this might be related to this issue also: https://github.com/All-Hands-AI/OpenHands/issues/7906

rbrugaro avatar Jun 09 '25 21:06 rbrugaro

I think I found where it gets saved in CLI. It's in ~/.openhands/sessions. Looks like the CLI looks in a different directory :/

CC @rbren

mamoodi avatar Jun 11 '25 15:06 mamoodi

I have a PR to update the docs: https://github.com/All-Hands-AI/OpenHands/pull/9074

mamoodi avatar Jun 11 '25 17:06 mamoodi

Thx @mamoodi, I found my prior sessions at /tmp/openhands_file_store/sessions That was the default setting up to 0.40 when there was still an app_config.py and switched in 0.41 to '~/.openhands/file_store'

rbrugaro avatar Jun 11 '25 18:06 rbrugaro

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 12 '25 02:07 github-actions[bot]

This issue was closed because it has been stalled for over 30 days with no activity.

github-actions[bot] avatar Jul 20 '25 02:07 github-actions[bot]