Skip to content

Fix NoneType error in get_conversation and other typesafety #8915

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

Closed
wants to merge 1 commit into from

Conversation

raymyers
Copy link
Contributor

@raymyers raymyers commented Jun 5, 2025

  • This change is worth documenting at https://docs.all-hands.dev/
  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

End-user friendly description of the problem this fixes or functionality this introduces.


Summarize what the PR does, explaining any non-trivial design decisions.

Adding the type annotation to conversation_manager in shared.py makes it so mypy catches the missing None check behind this recent runtime exception:

openhands/server/conversation_manager/standalone_conversation_manager.py", line 136, in detach_from_conversation
    sid = conversation.sid
          ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'sid'

It also appears to have flagged a missing async. It's possible that these constants have left a larger hole in our type-checking. I originally tried to solve this by forcing return type annotations in #8911 (maybe still a good idea), but this turned out to me enough.


Link of any specific issues this addresses:


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:d2c5c00-nikolaik   --name openhands-app-d2c5c00   docker.all-hands.dev/all-hands-ai/openhands:d2c5c00

agent_state_changed = event
else:
await sio.emit('oh_event', event_to_dict(event), to=connection_id)
if agent_loop_info.event_store:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will silently do nothing if agent_loop_info.event_store is None, is that the proper behavior? Or is the proper behavior to throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question, I don't know enough about the scenario it could be None in. My thinking was "Well we're looking over all the events so if there's no store there are definitely no events to loop over".

But I can equally argue that AsyncEventStoreWrapper would have exploded before so we should preserve the behavior unless we know we want different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tofarr @malhotra5 Would you know more about the desired behavior here?

@@ -27,4 +27,5 @@ async def get_conversation(
try:
yield conversation
finally:
await conversation_manager.detach_from_conversation(conversation)
if conversation:
await conversation_manager.detach_from_conversation(conversation)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one from the prod error.

@@ -145,5 +145,5 @@ async def search_events(
@app.post('/events')
async def add_event(request: Request, conversation: ServerConversation = Depends(get_conversation)):
data = request.json()
conversation_manager.send_to_event_stream(conversation.sid, data)
await conversation_manager.send_to_event_stream(conversation.sid, data)
return JSONResponse({'success': True})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this was a hidden performance bug.

@raymyers raymyers force-pushed the ray/get-convo-none branch from 7be24b4 to d2c5c00 Compare June 5, 2025 15:15
Copy link

openhands-ai bot commented Jun 5, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Docker
    • Run Python Unit Tests

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #8915

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@raymyers
Copy link
Contributor Author

raymyers commented Jun 5, 2025

Partially done in #8927, going to do the rest later.

@raymyers raymyers closed this Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants