Skip to content

bug: crash hook installs twice (duplicate UNCAUGHT_EXCEPTION entries) and background-thread crashes are never captured #216

Open

Description

@falbany

Description

Two telemetry gaps in crash capture:

1. The crash hook is installed twice, so uncaught exceptions are logged twice. ProFilesApp.run calls self._setup_logging(...) twice (src/profiles/app.py:268 for the temporary logger and :279 after reconfiguration), and _setup_logging calls install_crash_hook each time. install_crash_hook (src/profiles/core/telemetry/diagnostics.py:121-141) unconditionally chains the previous sys.excepthook — so on a crash, hook #2 logs UNCAUGHT_EXCEPTION and then calls hook #1, which logs it again: duplicate CRITICAL blocks in profiles.log, potentially interleaved/confusing in the log viewer.

2. Background-thread crashes are never captured. Only sys.excepthook is installed. Exceptions in the uvicorn server thread, workflow command threads, or the rebind worker (_schedule_rebind) never reach it, and threading.excepthook is not installed — a dying background thread is invisible in profiles.log (the crash hook exists precisely to leave a diagnostic trail, #43-era diagnostics).

Steps to reproduce

  • Trigger an uncaught exception in the main thread → two UNCAUGHT_EXCEPTION blocks are appended to profiles.log.
  • Raise inside a threading.Thread(daemon=True) started by the app (e.g. rebind worker) → nothing is logged.

Suggested fix

  • Make install_crash_hook idempotent (guard on a module-level installed flag, or check getattr(sys.excepthook, "_profiles_crash_hook", False)) so double _setup_logging doesn't chain duplicates.
  • Also wrap threading.excepthook the same way, routing thread crashes through the same CRITICAL event with the thread name.

Activity

  1. added
    bug
    code-quality
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcode-quality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions