Skip to content

Fix Agent warnings#310

Merged
dangusev merged 8 commits intomainfrom
fix/fix-various-warnings
Jan 23, 2026
Merged

Fix Agent warnings#310
dangusev merged 8 commits intomainfrom
fix/fix-various-warnings

Conversation

@dangusev
Copy link
Contributor

@dangusev dangusev commented Jan 23, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Agents now always close after warmup failures, preventing resource leaks
    • Event system shutdown improved to ensure clean termination (event manager can be stopped)
  • Behavior Changes

    • Public event surface adjusted: several plugin/connection events removed and core event types consolidated
    • TTS plugin no longer emits plugin-closed events on shutdown
    • Video processor detection events include an explicit event type field
  • New Features

    • Added debug flag to serve for development-time asyncio debugging

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Ensures agents are closed on warmup failure; EventManager gains stop() and is invoked during agent shutdown; many legacy event classes removed and exports reordered; runner switches to session-driven agent flow and adds a debug flag; TTS.close no longer emits PluginClosedEvent.

Changes

Cohort / File(s) Summary
Agent Launcher & Agent Shutdown
agents-core/vision_agents/core/agents/agent_launcher.py, agents-core/vision_agents/core/agents/agents.py
Warmup wrapped in try/finally to always close created agent on warmup failure; _close now calls events.stop() after clearing call context to halt the event bus.
Event System Core
agents-core/vision_agents/core/events/__init__.py, agents-core/vision_agents/core/events/base.py, agents-core/vision_agents/core/events/manager.py
Removed multiple plugin/connection/health event classes; added/expanded base event types and EventManager/ConnectionState exports; VideoProcessorDetectionEvent now includes explicit type field; EventManager adds stop() and no longer auto-registers removed events; manager.merge uses em.stop().
Runner / CLI
agents-core/vision_agents/core/runner/runner.py
Replaced immediate agent creation with session-based workflow (start_session, session.agent, session.wait()); serve()/serve_cmd() accept debug: bool to enable asyncio debug; added return annotations.
TTS Plugin
agents-core/vision_agents/core/tts/tts.py
Removed PluginClosedEvent import and its emission from TTS.close(); close no longer emits that event.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI
  participant Launcher as Launcher
  participant Session as Session
  participant Agent as Agent
  participant EventMgr as EventManager
  participant DemoUI as DemoUI

  CLI->>Launcher: warmup()
  Launcher->>Agent: create()
  Launcher->>Agent: warmup()
  alt warmup succeeds
    Launcher->>Session: start_session(call_id, call_type)
    Session->>Agent: expose session.agent
    CLI->>DemoUI: open if requested (session.agent)
    Session->>Agent: session.wait()/operate
    Agent->>EventMgr: events.stop() on _close
  else warmup fails
    Launcher->>Agent: finally -> close()
    Agent->>EventMgr: events.stop()
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Nash0x7E2
  • maxkahan
  • d3xvn

Poem

I slit the warmup open, finding wire and quiet—
the agent folded, a small moth in a palm;
the event bus exhales like a stopped clock,
and the runner learns to seat itself in session.
Close the plugin; let the dark be tidy.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix Agent warnings' is vague and generic, failing to convey what specific warnings are being addressed or which aspects of the codebase are affected. Replace with a more specific title that describes the primary change, such as 'Add resource cleanup and event manager shutdown' or 'Ensure agent and event manager proper cleanup on shutdown.'
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
agents-core/vision_agents/core/runner/runner.py (1)

168-202: Use environment variable or uvicorn config to enable asyncio debug mode, not set_debug() before loop creation.

asyncio.get_event_loop().set_debug(debug) called in a synchronous context before uvicorn starts is unreliable. The loop returned may not be the one uvicorn uses, and in newer Python versions this can raise when no loop is set. Per asyncio docs, enable debug mode via PYTHONASYNCIODEBUG=1 environment variable before the loop is created, or use uvicorn's loop selection (--loop asyncio) with the environment variable. Alternatively, set debug in a startup hook using asyncio.get_running_loop() after the loop is running.

🛠️ Environment variable approach (recommended)
+import os
@@
-        # Get the policy's loop and enable debug
-        asyncio.get_event_loop().set_debug(debug)
+        # Enable asyncio debug via environment variable before uvicorn creates its loop
+        if debug:
+            os.environ.setdefault("PYTHONASYNCIODEBUG", "1")
🤖 Fix all issues with AI agents
In `@agents-core/vision_agents/core/events/__init__.py`:
- Around line 56-64: The __all__ export list still includes
PluginInitializedEvent, PluginClosedEvent, and PluginErrorEvent even though they
are no longer imported from .base; update the module exports by either
re-introducing those classes in base.py and adding them to the import list in
__init__.py (so PluginInitializedEvent, PluginClosedEvent, PluginErrorEvent are
defined and imported), or remove those three symbols from the __all__ list in
__init__.py so it only exposes currently imported names like AudioFormat,
BaseEvent, ConnectionState, PluginBaseEvent, VideoProcessorDetectionEvent, and
EventManager.

In `@agents-core/vision_agents/core/events/manager.py`:
- Around line 185-188: The merge method calls em.stop() but does not wait for
the background processing task to finish, creating a race where em._queue can be
drained concurrently or the task may be pending/destroyed; change
EventManager.stop to cancel the processing Task and await its completion (or
return an awaitable that awaits the task), and update EventManager.merge to
await em.stop() (e.g., await em.stop()) before accessing or transferring
em._queue and other shared state so the background task is guaranteed to be
finished.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
agents-core/vision_agents/core/runner/runner.py (1)

175-203: Make --debug always take effect.

Using os.environ.setdefault means an existing PYTHONASYNCIODEBUG=0 will bypass the flag. If a user passes --debug, it should force-enable the setting.

🔧 Proposed change
-        if debug:
-            os.environ.setdefault("PYTHONASYNCIODEBUG", "1")
+        if debug:
+            os.environ["PYTHONASYNCIODEBUG"] = "1"
🤖 Fix all issues with AI agents
In `@agents-core/vision_agents/core/runner/runner.py`:
- Around line 129-135: The comment is stale—this path no longer calls a separate
join_call function but always starts a session—so update the comment above the
logger.info and start_session calls to reflect a session-based flow;
specifically, change the mention of “join_call function” to something like
“start a session and join the call” near the logger.info(f"📞 Joining call:
{call_type}/{call_id}") and the self._launcher.start_session(...) invocation,
making it clear that session = await self._launcher.start_session(...) creates
the session and provides session.agent for the demo UI.

@dangusev dangusev merged commit efeca6a into main Jan 23, 2026
10 checks passed
@dangusev dangusev deleted the fix/fix-various-warnings branch January 23, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants