fix(runner): use export endpoint for get_session_events to prevent freeze#1019
fix(runner): use export endpoint for get_session_events to prevent freeze#1019Gkrumbach07 merged 2 commits intomainfrom
Conversation
…n_events The /agui/events endpoint is an SSE stream that never closes, causing urllib.request.urlopen to block indefinitely (30s timeout). Switch to the /export endpoint which returns historical events as regular JSON. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughSession events retrieval was changed to use the session Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/runners/ambient-runner/ambient_runner/tools/backend_api.py`:
- Around line 293-305: The current export call fetches the entire session
history which can be huge; modify the request to use a bounded contract (append
a limit query param to the path variable before calling _make_request, e.g.
"/projects/{self.project_name}/agentic-sessions/{session_name}/export?limit={MAX_EXPORT_EVENTS}")
and introduce a local cap constant (e.g. MAX_EXPORT_EVENTS) to guard
client-side; after receiving response in the current method, parse as before but
if events is a list or a decoded JSON string, trim/slice it to MAX_EXPORT_EVENTS
before returning to avoid full-history transfers and parses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7799a783-198f-493b-9f57-18604988ff32
📒 Files selected for processing (2)
components/runners/ambient-runner/ambient_runner/bridges/claude/backend_tools.pycomponents/runners/ambient-runner/ambient_runner/tools/backend_api.py
…essions Tail-slice events to last 200 (configurable via max_events param) to avoid fetching/parsing entire session histories. The export endpoint returns all events, which can be huge for long-running sessions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/runners/ambient-runner/ambient_runner/tools/backend_api.py`:
- Around line 277-278: The constant _MAX_EXPORT_EVENTS was lowered to 200, which
breaks the previous behavior of fetching limit=max_messages * 10 events; to fix
this, update the call in backend_tools.py that fetches exported events (the call
that currently only passes max_messages) to pass an explicit
max_events=max_messages * 10 (or alternatively restore _MAX_EXPORT_EVENTS to
500) so the event fetch retains the previous multiplier and sparse
TEXT_MESSAGE_CONTENT events don't drop messages.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 60b14e65-42a5-4d9a-b7e2-173c4231797a
📒 Files selected for processing (1)
components/runners/ambient-runner/ambient_runner/tools/backend_api.py
…eeze (ambient-code#1019) ## Summary - **Root cause**: `acp_get_session_status` was calling the `/agui/events` endpoint, which is an SSE (Server-Sent Events) stream that never closes. `urllib.request.urlopen` blocks waiting for the response to finish, causing the agent to freeze for 30 seconds (the timeout). - **Fix**: Switch to the `/export` endpoint which returns all historical AG-UI events as a regular JSON response, no streaming. Follows up on ambient-code#1006. ## Test plan - [x] 22 tests pass - [ ] Manual: call `acp_get_session_status` on a running session — should return immediately with status + recent messages 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Ambient Code Bot <bot@ambient-code.local> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
acp_get_session_statuswas calling the/agui/eventsendpoint, which is an SSE (Server-Sent Events) stream that never closes.urllib.request.urlopenblocks waiting for the response to finish, causing the agent to freeze for 30 seconds (the timeout)./exportendpoint which returns all historical AG-UI events as a regular JSON response, no streaming.Follows up on #1006.
Test plan
acp_get_session_statuson a running session — should return immediately with status + recent messages🤖 Generated with Claude Code