commaai / commaai/openpilot

interactive timeout callbacks are added but never removed

Open
#37,536 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
63.7k
Forks
11.4k
Avg merge
17h 53m
Merged PRs (30d)
171

Description

## Problem

`Device.add_interactive_timeout_callback()` appends to a list but there is no corresponding remove method. Once a callback is added, it stays forever.

**Definition:** `selfdrive/ui/ui_state.py:220-221`
```python
def add_interactive_timeout_callback(self, callback: Callable):
self._interactive_timeout_callbacks.append(callback)
```

**Invocation:** `selfdrive/ui/ui_state.py:270-271`
```python
for callback in self._interactive_timeout_callbacks:
callback()
```

## Call sites

| File | Context |
|------|---------|
| `selfdrive/ui/mici/layouts/onboarding.py:115` | `TrainingGuideDMTutorial.__init__()` — disables driver monitoring on timeout |
| `selfdrive/ui/mici/layouts/main.py:63` | `MiciMainLayout._setup_callbacks()` — handles UI transitions |
| `selfdrive/ui/mici/onroad/driver_camera_dialog.py:235` | `DriverCameraDialog.__init__()` — pops dialog on timeout |
| `selfdrive/ui/onroad/driver_camera_dialog.py:17` | `DriverCameraDialog.__init__()` — pops dialog on timeout |
| `selfdrive/ui/layouts/main.py:58` | `MainLayout._setup_callbacks()` — resets UI on timeout |

There is an existing TODO in `selfdrive/ui/onroad/driver_camera_dialog.py:16`:
```python
# TODO: this can grow unbounded, should be given some thought
```

## Impact

- Callbacks from short-lived widgets (e.g. `TrainingGuideDMTutorial`, `DriverCameraDialog`) persist after the widget is gone
- The callback list grows if widgets are created multiple times (e.g. opening driver camera dialog repeatedly)
- Stale callbacks may reference destroyed widgets or call `gui_app.pop_widget` at unexpected times

## Suggested fix

Add a `remove_interactive_timeout_callback` method, or switch to a pattern where callbacks are tied to widget lifecycle (e.g. registered in `show_event`, removed in `hide_event`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.