Compare commits

...

6 Commits

Author SHA1 Message Date
373f3aaa79 Merge branch 'main' into feature/activity-pane-enhancements 2026-02-08 22:23:40 +00:00
66b2baf510 Merge pull request 'fix: SSE reconnect with exponential backoff and terminal state' (#7) from fix/sse-reconnect into main
Reviewed-on: #7
2026-02-08 22:23:23 +00:00
35f33f2079 Merge branch 'main' into fix/sse-reconnect 2026-02-08 22:23:16 +00:00
Zoe Forbes
d26bb6da2d feat: enhance Database Activity pane with comments, interaction, and badges
Enhance the Database Activity panel in SiloAuthDockWidget:

- Show latest revision number and comment inline per activity entry
- Truncate long descriptions with ellipsis, full text in tooltip
- Mark locally checked-out items with green color and "local" badge
- Double-click opens local file or triggers checkout from server
- Right-click context menu: Open in Create, Open in Browser,
  Copy Part Number, View Revisions

Closes #9
2026-02-08 16:23:06 -06:00
Zoe Forbes
e5126c913d fix: SSE reconnect with exponential backoff and terminal state
Replace the infinite fixed-delay retry loop with exponential backoff
(1s, 2s, 4s, ... capped at 60s) and a max retry limit of 10.

Changes to SiloEventListener:
- Expand connection_status signal to (status, retry_count, error_message)
- Add exponential backoff: min(BASE_DELAY * 2^retries, MAX_DELAY)
- Add terminal "gave_up" state after MAX_RETRIES exhausted
- Capture and forward error messages from failed connection attempts

Changes to SiloAuthDockWidget._on_sse_status:
- Show retry count: "Reconnecting (3/10)..."
- Show "Disconnected" (red) on gave_up state
- Log each attempt to FreeCAD console (PrintWarning/PrintError)
- Set tooltip with last error message on the status label

Closes #2
2026-02-08 16:22:55 -06:00
76973aaae0 Merge pull request 'feat: add Silo_Diag connection diagnostics command' (#6) from feature/silo-diag into main
Reviewed-on: #6
2026-02-08 22:22:51 +00:00

View File

@@ -2366,13 +2366,13 @@ class SiloEventListener(QtCore.QThread):
item_updated = QtCore.Signal(str) # part_number
revision_created = QtCore.Signal(str, int) # part_number, revision
connection_status = QtCore.Signal(
str
) # "connected" / "disconnected" / "unsupported"
str, int, str
) # (status, retry_count, error_message)
server_mode_changed = QtCore.Signal(str) # "normal" / "read-only" / "degraded"
_MAX_FAST_RETRIES = 3
_FAST_RETRY_SECS = 5
_SLOW_RETRY_SECS = 30
_MAX_RETRIES = 10
_BASE_DELAY = 1 # seconds, doubles each retry
_MAX_DELAY = 60 # seconds, backoff cap
def __init__(self, parent=None):
super().__init__(parent)
@@ -2395,6 +2395,7 @@ class SiloEventListener(QtCore.QThread):
def run(self):
retries = 0
last_error = ""
while not self._stop_flag:
try:
self._listen()
@@ -2402,21 +2403,24 @@ class SiloEventListener(QtCore.QThread):
if self._stop_flag:
return
retries += 1
last_error = "connection closed"
except _SSEUnsupported:
self.connection_status.emit("unsupported")
self.connection_status.emit("unsupported", 0, "")
return
except Exception:
except Exception as exc:
retries += 1
last_error = str(exc) or "unknown error"
self.connection_status.emit("disconnected")
if retries > self._MAX_RETRIES:
self.connection_status.emit("gave_up", retries - 1, last_error)
return
if retries <= self._MAX_FAST_RETRIES:
delay = self._FAST_RETRY_SECS
else:
delay = self._SLOW_RETRY_SECS
self.connection_status.emit("disconnected", retries, last_error)
delay = min(self._BASE_DELAY * (2 ** (retries - 1)), self._MAX_DELAY)
# Interruptible sleep
for _ in range(delay):
for _ in range(int(delay)):
if self._stop_flag:
return
self.msleep(1000)
@@ -2440,7 +2444,7 @@ class SiloEventListener(QtCore.QThread):
except urllib.error.URLError:
raise
self.connection_status.emit("connected")
self.connection_status.emit("connected", 0, "")
event_type = ""
data_buf = ""
@@ -2706,13 +2710,28 @@ class SiloAuthDockWidget:
self._event_listener.stop()
self._sse_label.setText("")
def _on_sse_status(self, status):
def _on_sse_status(self, status, retry, error):
if status == "connected":
self._sse_label.setText("Listening")
self._sse_label.setStyleSheet("font-size: 11px; color: #4CAF50;")
self._sse_label.setToolTip("")
FreeCAD.Console.PrintMessage("Silo: SSE connected\n")
elif status == "disconnected":
self._sse_label.setText("Reconnecting...")
self._sse_label.setText(
f"Reconnecting ({retry}/{SiloEventListener._MAX_RETRIES})..."
)
self._sse_label.setStyleSheet("font-size: 11px; color: #FF9800;")
self._sse_label.setToolTip(error or "Connection lost")
FreeCAD.Console.PrintWarning(
f"Silo: SSE reconnecting ({retry}/{SiloEventListener._MAX_RETRIES}): {error}\n"
)
elif status == "gave_up":
self._sse_label.setText("Disconnected")
self._sse_label.setStyleSheet("font-size: 11px; color: #F44336;")
self._sse_label.setToolTip(error or "Max retries reached")
FreeCAD.Console.PrintError(
f"Silo: SSE gave up after {retry} retries: {error}\n"
)
elif status == "unsupported":
self._sse_label.setText("Not available")
self._sse_label.setStyleSheet("font-size: 11px; color: #888;")
@@ -2766,7 +2785,7 @@ class SiloAuthDockWidget:
def _refresh_activity_panel(self):
"""Refresh the Database Activity panel if it exists."""
from PySide import QtWidgets
from PySide import QtCore, QtGui, QtWidgets
mw = FreeCADGui.getMainWindow()
if mw is None:
@@ -2778,6 +2797,24 @@ class SiloAuthDockWidget:
if activity_list is None:
return
activity_list.clear()
# Connect interaction signals (once)
if not getattr(activity_list, "_silo_connected", False):
activity_list.itemDoubleClicked.connect(self._on_activity_double_click)
activity_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
activity_list.customContextMenuRequested.connect(
lambda pos: self._on_activity_context_menu(activity_list, pos)
)
activity_list._silo_connected = True
# Collect local part numbers for badge
local_pns = set()
try:
for lf in search_local_files():
local_pns.add(lf.get("part_number", ""))
except Exception:
pass
try:
items = _client.list_items()
if isinstance(items, list):
@@ -2787,12 +2824,96 @@ class SiloAuthDockWidget:
updated = item.get("updated_at", "")
if updated:
updated = updated[:10]
activity_list.addItem(f"{pn} - {desc} - {updated}")
# Fetch latest revision info
rev_num = ""
comment = ""
try:
revs = _client.get_revisions(pn)
if revs:
latest = revs[0] if isinstance(revs, list) else revs
rev_num = str(latest.get("revision_number", ""))
comment = latest.get("comment", "") or ""
except Exception:
pass
# Truncate long descriptions
desc_display = desc
if len(desc_display) > 40:
desc_display = desc_display[:37] + "..."
# Build display text
rev_part = f" \u2013 Rev {rev_num}" if rev_num else ""
date_part = f" \u2013 {updated}" if updated else ""
local_badge = " \u25cf local" if pn in local_pns else ""
line1 = (
f"{pn} \u2013 {desc_display}{rev_part}{date_part}{local_badge}"
)
if comment:
line1 += f'\n "{comment}"'
else:
line1 += "\n (no comment)"
list_item = QtWidgets.QListWidgetItem(line1)
list_item.setData(QtCore.Qt.UserRole, pn)
if desc and len(desc) > 40:
list_item.setToolTip(desc)
if pn in local_pns:
list_item.setForeground(QtGui.QColor("#4CAF50"))
activity_list.addItem(list_item)
if activity_list.count() == 0:
activity_list.addItem("(No items in database)")
except Exception:
activity_list.addItem("(Unable to refresh activity)")
def _on_activity_double_click(self, item):
"""Open/checkout item from activity pane."""
pn = item.data(256) # Qt.UserRole
if not pn:
return
local_path = find_file_by_part_number(pn)
if local_path and local_path.exists():
FreeCAD.openDocument(str(local_path))
else:
_sync.open_item(pn)
def _on_activity_context_menu(self, activity_list, pos):
"""Show context menu for activity pane items."""
from PySide import QtCore, QtGui
item = activity_list.itemAt(pos)
if item is None:
return
pn = item.data(QtCore.Qt.UserRole)
if not pn:
return
menu = QtGui.QMenu()
open_action = menu.addAction("Open in Create")
browser_action = menu.addAction("Open in Browser")
copy_action = menu.addAction("Copy Part Number")
revisions_action = menu.addAction("View Revisions")
action = menu.exec_(activity_list.mapToGlobal(pos))
if action == open_action:
local_path = find_file_by_part_number(pn)
if local_path and local_path.exists():
FreeCAD.openDocument(str(local_path))
else:
_sync.open_item(pn)
elif action == browser_action:
import webbrowser
api_url = _get_api_url().rstrip("/")
base_url = api_url[:-4] if api_url.endswith("/api") else api_url
webbrowser.open(f"{base_url}/items/{pn}")
elif action == copy_action:
QtGui.QApplication.clipboard().setText(pn)
elif action == revisions_action:
FreeCADGui.runCommand("Silo_Info", 0)
# -- Actions ------------------------------------------------------------
def _on_login_clicked(self):