Fix session endpoint errors causing 'Error refreshing Manx' toast#54
Open
Fix session endpoint errors causing 'Error refreshing Manx' toast#54
Conversation
Wrap tcp_handler.refresh() and session list comprehensions in try/except blocks so that transient TCP errors (e.g. deprecated socket API) do not crash the page load or return HTTP 500 from the sessions endpoint. On failure, an empty session list is returned instead, keeping the UI functional. Fixes #52
There was a problem hiding this comment.
Pull request overview
This PR improves the Manx UI’s resilience to backend TCP/session refresh failures by preventing exceptions from breaking the initial page render and by ensuring session-refresh endpoints return a successful empty payload instead of HTTP 500.
Changes:
- Wrap
tcp_handler.refresh()intry/exceptfor the Manx splash page so template rendering always receives a list forsessions. - Add
try/excepthandling to the GET/POST sessions endpoints to return empty session results on refresh errors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/term_api.py
Outdated
Comment on lines
25
to
29
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| sessions = [dict(id=s.id, info=a.paw, platform=a.platform, executors=a.executors) | ||
| for s in self.term_svc.socket_conn.tcp_handler.sessions | ||
| for a in await self.data_svc.locate('agents', match=dict(paw=s.paw))] |
app/term_api.py
Outdated
Comment on lines
+30
to
+32
| except Exception as e: | ||
| print(e) | ||
| sessions = [] |
app/term_api.py
Outdated
Comment on lines
+36
to
+43
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| sessions = [dict(id=s.id, info=a.paw, platform=a.platform, executors=a.executors) | ||
| for s in self.term_svc.socket_conn.tcp_handler.sessions | ||
| for a in await self.data_svc.locate('agents', match=dict(paw=s.paw))] | ||
| except Exception as e: | ||
| print(e) | ||
| sessions = [] |
app/term_api.py
Outdated
Comment on lines
+47
to
+52
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| sessions = [dict(id=s.id, info=s.paw) for s in self.term_svc.socket_conn.tcp_handler.sessions] | ||
| except Exception as e: | ||
| print(e) | ||
| sessions = [] |
- Wrap only tcp_handler.refresh() in try/except (not the agent lookup) - Replace print(e) with log.error() using module-level logger - get_sessions and sessions now raise HTTPInternalServerError on refresh failure instead of silently returning 200 with empty list
There was a problem hiding this comment.
Pull request overview
Fixes the Manx UI “Error refreshing Manx” behavior by adding error handling around TCP handler refresh so session endpoints/pages don’t crash when refresh fails.
Changes:
- Added module logger and replaced
print()with structured logging. - Wrapped
tcp_handler.refresh()intry/exceptinsplash(),get_sessions(), andsessions().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+39
to
+43
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| except Exception as e: | ||
| log.error('Failed to refresh TCP handler: %s', e) | ||
| raise web.HTTPInternalServerError(reason='Failed to refresh sessions') |
Comment on lines
+50
to
+54
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| except Exception as e: | ||
| log.error('Failed to refresh TCP handler: %s', e) | ||
| raise web.HTTPInternalServerError(reason='Failed to refresh sessions') |
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| except Exception as e: | ||
| print(e) | ||
| log.error('Failed to refresh TCP handler: %s', e) |
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| except Exception as e: | ||
| log.error('Failed to refresh TCP handler: %s', e) |
| try: | ||
| await self.term_svc.socket_conn.tcp_handler.refresh() | ||
| except Exception as e: | ||
| log.error('Failed to refresh TCP handler: %s', e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #52 — Addresses "Error refreshing Manx" toast and broken Manx page load when the underlying TCP handler encounters errors (e.g. deprecated socket API, connection issues).
Changes
splash(): Movedtcp_handler.refresh()inside thetry/exceptblock so that any exception during page load gracefully returns an empty sessions list rather than returningNoneto the template (which causedJSON.parse('null')in the UI, leading to immediate refresh failures).get_sessions()andsessions(): Addedtry/excepterror handling so transient TCP errors return an empty list with HTTP 200 rather than propagating a 500 error that triggers the "Error refreshing Manx" toast on the frontend.Root Cause
The
splash()method calledtcp_handler.refresh()before thetryblock, so any exception there was unhandled and caused the template renderer to receiveNoneas the context. Thesessions()andget_sessions()endpoints had no error handling at all, so TCP errors returned HTTP 500, which the frontendrefreshManx()JS function caught and displayed as "Error refreshing Manx".Type of change
Checklist