Skip to content

Refactor SSE client with timeout support and listen_until_clear()#13

Open
surafelfikru wants to merge 6 commits intotrueagi-io:serverfrom
surafelfikru:server
Open

Refactor SSE client with timeout support and listen_until_clear()#13
surafelfikru wants to merge 6 commits intotrueagi-io:serverfrom
surafelfikru:server

Conversation

@surafelfikru
Copy link
Copy Markdown

  • Refactored listen()
    • Now supports a timeout parameter (default: 300s).
    • Cleans up legacy code and yields parsed SSE events directly.
  • Added listen_until_clear(timeout)
    • Waits until a pathClear status is received or timeout is reached.
    • Tries to replicate the behaviour of block().
  • Replaced .listen() calls with .listen_until_clear()

- changed listen method to a generic generator the yields the status
sent by the server stream.
- implemented listen_until_clear that simulates what block() does but
for server streams insteam of polling.
@luketpeterson
Copy link
Copy Markdown
Collaborator

When I try to run these changes I get:
ModuleNotFoundError: No module named 'requests_sse'

Obviously I can fetch the module myself, but there must be a way to add the package to some manifest so python knows to fetch it automatically.

@luketpeterson luketpeterson self-requested a review July 13, 2025 07:28
Copy link
Copy Markdown
Collaborator

@luketpeterson luketpeterson left a comment

Choose a reason for hiding this comment

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

I raised mainly style stuff. I think Adam had opinions on more substantive things in the API design.

Comment thread python/client.py

def on_error():
raise Exception("error")
print("event stream closed")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we want to be this chatty, by default. It's handy for debugging, and maybe if we support a "verbose" switch. But otherwise we probably want operations at this level to be silent on the client side. Just my opinion.

Comment thread python/client.py Outdated

status = msg.get("status")
if status == "pathClear":
print("path cleared")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See above about status chatter

Comment thread python/client.py Outdated
print("path cleared")
return ""
elif status == "pathForbiddenTemporary":
print("waiting for path to clear")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See above about status chatter

Comment thread python/client.py Outdated
# _main()
_main_mm2()
# test_sse_status()
# _main_mm2()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's restore the functionality of the client.py main to running MM2 tests.

Perhaps we want to move all tests outside of client.py, so client.py is just a "library" module, and the tests are in another file. That would be what I would do, but I don't come from the Python world so I don't know all the Python standard practices.

Comment thread python/client.py Outdated
_main_mm2()
# test_sse_status()
# _main_mm2()
test_sse_status()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Even if we keep this test in this file, it probably ought to start with '_' so it doesn't look like a public API.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i will resolve the above comments

@surafelfikru
Copy link
Copy Markdown
Author

When I try to run these changes I get: ModuleNotFoundError: No module named 'requests_sse'

Obviously I can fetch the module myself, but there must be a way to add the package to some manifest so python knows to fetch it automatically.

I have added a requirements.txt file for the required dependencies. you can start a virtual environment for a separate python environment.

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

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