Skip to content

SyntaxWarning: return in finally block in _voice_process_recording (Python 3.14+) #21088

@rayncc

Description

@rayncc

Description

On Python 3.14+, cli.py raises a SyntaxWarning at startup due to a return statement inside a finally block in the _voice_process_recording method (line 8700). This is a known pitfall since Python 3.8 — return in a finally block suppresses any exception that was propagating through the finally clause, and Python 3.14 now emits a SyntaxWarning for it.

Location

cli.py, method _voice_process_recording, around line 8681–8716

The Problem

The finally block (line 8681) contains business logic that includes a return statement (line 8700), which triggers the warning:

finally:
    with self._voice_lock:
        self._voice_processing = False
    if hasattr(self, "_app") and self._app:
        self._app.invalidate()
    try:
        if wav_path and os.path.isfile(wav_path):
            os.unlink(wav_path)
    except Exception:
        pass

    if not submitted:
        self._no_speech_count = getattr(self, "_no_speech_count", 0) + 1
        if self._no_speech_count >= 3:
            self._voice_continuous = False
            self._no_speech_count = 0
            _cprint(f"{_DIM}No speech detected 3 times, continuous mode stopped.{_RST}")
            return  # <--- SyntaxWarning here
    else:
        self._no_speech_count = 0

    if self._voice_continuous and not submitted and not self._voice_recording:
        ...

The Fix

Move the business logic out of the finally block:

finally:
    with self._voice_lock:
        self._voice_processing = False
    if hasattr(self, "_app") and self._app:
        self._app.invalidate()
    try:
        if wav_path and os.path.isfile(wav_path):
            os.unlink(wav_path)
    except Exception:
        pass

# Business logic outside finally:
if not submitted:
    ...
else:
    ...
if self._voice_continuous and not submitted and not self._voice_recording:
    ...

Environment

  • Python 3.14.4
  • Hermes Agent v0.12.0
  • Ubuntu 26.04 (WSL2)
  • Warning: SyntaxWarning: return in a finally block

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/cliCLI entry point, hermes_cli/, setup wizardtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions