Skip to content

[Bug]: Cannot schedule new futures after interpreter has shutdown when OpenHands receives Ctrl + CΒ #11364

@lgnashold

Description

@lgnashold

Is there an existing issue for the same bug? (If one exists, thumbs up or comment on the issue instead).

  • I have checked the existing issues.

Describe the bug and reproduction steps

We are starting OpenHands in a subprocess via Python, with the command:

python -m openhands.core.main --config-file /path/to/config.yaml -t "<task>" 

It is running inside a docker sandbox environment using the base image FROM docker.all-hands.dev/all-hands-ai/runtime:0.58-nikolaik.

When we send a SIGINT to the OpenHands process, I would expect OpenHands to be able to handle this gracefully, including saving the trajectory to a file. Instead, we get the error cannot schedule new futures after shutdown.

This means we completely lose the trajectory JSON file.

OpenHands Installation

Docker command in README

OpenHands Version

main

Model Name

LiteLLM, sonnet-4.5

Operating System

Linux

Logs, Errors, Screenshots, and Additional Context

Error Message:

07:51:36 - openhands:ERROR: loop.py:24 - RuntimeError: There was an unexpected error while running the agent: RuntimeError. You can refresh the page or ask the agent to try again.
Traceback (most recent call last):
  File "/home/user/services/openhands/OpenHands/openhands/controller/agent_controller.py", line 371, in _step_with_exception_handling
    await self._step()
  File "/home/user/services/openhands/OpenHands/openhands/controller/agent_controller.py", line 878, in _step
    action = self.agent.step(self.state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/services/openhands/OpenHands/openhands/agenthub/codeact_agent/codeact_agent.py", line 219, in step
    response = self.llm.completion(**params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
    return copy(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
    self._add_action_func(lambda rs: rs.outcome.result())
                                     ^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/home/user/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/user/services/openhands/OpenHands/openhands/llm/llm.py", line 331, in wrapper
    resp: ModelResponse = self._completion_unwrapped(*args, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.venv/lib/python3.12/site-packages/litellm/utils.py", line 1356, in wrapper
    raise e
  File "/home/user/.venv/lib/python3.12/site-packages/litellm/utils.py", line 1287, in wrapper
    executor.submit(
  File "/home/user/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/concurrent/futures/thread.py", line 171, in submit
    raise RuntimeError('cannot schedule new futures after shutdown')

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingheadlessRelated to headless mode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions