Skip to content

CLI-29: Robust Interruption in Agent Mode + Various Fixes#523

Merged
dwash96 merged 2 commits into
cecli-dev:v0.100.0from
szmania:cli-29-fix-hang
May 24, 2026
Merged

CLI-29: Robust Interruption in Agent Mode + Various Fixes#523
dwash96 merged 2 commits into
cecli-dev:v0.100.0from
szmania:cli-29-fix-hang

Conversation

@szmania
Copy link
Copy Markdown

@szmania szmania commented May 23, 2026

Summary

This PR addresses CLI-29: making interruption in agent mode more robust, along with several related fixes and improvements discovered during investigation.

Changes

Core Interruption Fixes

  • cecli/helpers/coroutines.py: Removed try/finally wrapper from interruptible_async_generator to prevent CancelledError from being swallowed during cleanup. Removed None check for interrupt_event (always required).
  • cecli/coders/base_coder.py: Changed interrupted exception from asyncio.CancelledError back to KeyboardInterrupt for proper propagation. Removed stale interrupt_event.clear() before formatting to avoid re-catching previous interrupts.
  • cecli/tui/worker.py: Added KeyboardInterrupt handler to CoderWorker to prevent thread crashes when interruption occurs during TUI operation.

Coder Switching & MCP Lifecycle Fixes

  • cecli/coders/base_coder.py:
    • Removed UsageMeta metaclass, simplified to plain Coder class with instance-level token/cost tracking
    • Fixed edit_format resolution logic (no longer overrides with main_model.edit_format for "code" format)
    • Moved "Local" MCP server disconnection logic from Coder.create() to main.py where coder switching occurs
    • Properly transfers mcp_manager, tui, context_management_enabled, and token/cost accumulators between coders
  • cecli/main.py: Disconnects "Local" MCP server when switching from agent to non-agent coder at the switch point rather than during coder creation

Sub-Agent & Delegation Changes

  • cecli/coders/agent_coder.py: Removed allow_nested_delegation config option - sub-agents always have Delegate tool excluded
  • cecli/coders/sub_agent_coder.py: Always excludes Delegate tool from sub-agents
  • cecli/helpers/conversation/integration.py: Sub-agents context block only shown for primary coders (no parent_uuid)
  • cecli/commands/spawn_agent.py: Simplified switch hint text
  • Documentation: Updated agent-mode.md and subagents.md to reflect removal of allow_nested_delegation

Linter Fixes

  • cecli/commands/lint.py: Changed linter.lint() from await to synchronous call (linter is no longer async)
  • tests/basic/test_linter.py: Updated tests to match synchronous linter API

Minor Fixes

  • cecli/helpers/skills.py: Removed unnecessary Path() wrapping
  • cecli/coders/base_coder.py: Changed usage report separator from space to newline for better readability
  • cecli/prompts/agent.yml, cecli/prompts/subagent.yml: Fixed typo "allows you too" → "allows you to"
  • Removed tests/coders/test_coder_switching.py: Test was fragile and tightly coupled to implementation details that changed

Testing

  • All existing tests pass
  • Manual testing of Ctrl+C interruption during agent mode processing
  • Verified coder switching between agent and non-agent modes
  • Verified sub-agent delegation restrictions

@szmania szmania force-pushed the cli-29-fix-hang branch from d9666fd to b8cdf94 Compare May 24, 2026 08:15
@szmania szmania force-pushed the cli-29-fix-hang branch from b8cdf94 to a24e530 Compare May 24, 2026 08:27
@tomjuggler
Copy link
Copy Markdown

Very cool thank you! Ctrl+C after seeing the AI go off the rails in console is an essential feature!

@dwash96 dwash96 merged commit 3982e61 into cecli-dev:v0.100.0 May 24, 2026
1 check passed
@dwash96 dwash96 mentioned this pull request May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants