Skip to content

Fix session endpoint errors causing 'Error refreshing Manx' toast#54

Open
deacon-mp wants to merge 2 commits intomasterfrom
fix/issue-52-sessions-error-handling
Open

Fix session endpoint errors causing 'Error refreshing Manx' toast#54
deacon-mp wants to merge 2 commits intomasterfrom
fix/issue-52-sessions-error-handling

Conversation

@deacon-mp
Copy link
Copy Markdown
Contributor

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(): Moved tcp_handler.refresh() inside the try/except block so that any exception during page load gracefully returns an empty sessions list rather than returning None to the template (which caused JSON.parse('null') in the UI, leading to immediate refresh failures).
  • get_sessions() and sessions(): Added try/except error 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 called tcp_handler.refresh() before the try block, so any exception there was unhandled and caused the template renderer to receive None as the context. The sessions() and get_sessions() endpoints had no error handling at all, so TCP errors returned HTTP 500, which the frontend refreshManx() JS function caught and displayed as "Error refreshing Manx".

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() in try/except for the Manx splash page so template rendering always receives a list for sessions.
  • Add try/except handling 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
@deacon-mp deacon-mp requested a review from Copilot March 16, 2026 04:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() in try/except in splash(), get_sessions(), and sessions().

💡 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)
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.

Unable to see Manx session

2 participants