Skip to content

πŸ™Œ OpenHands: AI-Driven Development

opendevin/core/main.py: Graceful shutdown (#1731)

Boxuan Li49de2625774c
diff --git a/opendevin/core/main.py b/opendevin/core/main.py
index 886b7bf20b..678fc55638 100644
--- a/opendevin/core/main.py
+++ b/opendevin/core/main.py
@@ -25,8 +25,11 @@ def read_task_from_stdin() -> str:
return sys.stdin.read()
-async def main(task_str: str = ''):
- """Main coroutine to run the agent controller with task input flexibility."""
+async def main(task_str: str = '') -> None:
+ """
+ Main coroutine to run the agent controller with task input flexibility.
+ It's only used when you launch opendevin backend directly via cmdline.
+ """
# Determine the task source
if task_str:
@@ -94,7 +97,7 @@ async def main(task_str: str = ''):
]:
await asyncio.sleep(1) # Give back control for a tick, so the agent can run
- return controller
+ await controller.close()
if __name__ == '__main__':
diff --git a/tests/integration/test_agent.py b/tests/integration/test_agent.py
index f99dab1220..ed2800f1f5 100644
--- a/tests/integration/test_agent.py
+++ b/tests/integration/test_agent.py
@@ -17,8 +17,7 @@ workspace_base = os.getenv('WORKSPACE_BASE')
)
def test_write_simple_script():
task = "Write a shell script 'hello.sh' that prints 'hello'. Do not ask me for confirmation at any point."
- controller = asyncio.run(main(task))
- asyncio.run(controller.close())
+ asyncio.run(main(task))
# Verify the script file exists
script_path = os.path.join(workspace_base, 'hello.sh')
@@ -58,8 +57,7 @@ def test_edits():
# Execute the task
task = 'Fix typos in bad.txt. Do not ask me for confirmation at any point.'
- controller = asyncio.run(main(task))
- asyncio.run(controller.close())
+ asyncio.run(main(task))
# Verify bad.txt has been fixed
text = """This is a stupid typo.