Skip to content

Add /pause command to toggle the runtime loop#2605

Open
dgageot wants to merge 2 commits intodocker:mainfrom
dgageot:board/add-pause-command-to-toggle-runtime-loop-32c58d2e
Open

Add /pause command to toggle the runtime loop#2605
dgageot wants to merge 2 commits intodocker:mainfrom
dgageot:board/add-pause-command-to-toggle-runtime-loop-32c58d2e

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 30, 2026

What

Adds a /pause slash command that pauses the agent runtime loop at iteration boundaries — i.e. as soon as the in-flight LLM request and any tool calls for the current turn complete. Running /pause again resumes the loop.

How

  • pkg/runtime/pause.go (new): LocalRuntime.TogglePause() and waitIfPaused(ctx). The pause state is a single channel that is open while paused and closed on resume; closing broadcasts the wake-up to every blocked caller in O(1).
  • pkg/runtime/loop.go: runStreamLoop calls r.waitIfPaused(ctx) at the top of its iteration loop. Respects context cancellation (returns ctx.Err() if cancelled while paused).
  • pkg/app/app.go: App.TogglePause() returns (paused, supported bool); the second return is false for runtimes that don't expose the method (e.g. remote runtimes), letting the TUI render an explicit "not supported" message.
  • TUI: New TogglePauseMsg, /pause command in the palette, and handleTogglePause showing a notification on each toggle ("Runtime paused — /pause again to resume" / "Runtime resumed" / "Pause is not supported with remote runtimes").

Tests

pkg/runtime/pause_test.go covers:

  • toggle state cycles
  • not-paused fast path
  • block-until-resumed
  • ctx cancellation while paused
  • broadcast to multiple waiters (single resume wakes all)
  • concurrent togglers + waiters under -race

All pass under go test -race -count=5 -run Pause ./pkg/runtime/. Full mise lint and mise test are green.


Assisted-By: docker-agent

dgageot added 2 commits April 30, 2026 10:54
Adds a /pause slash command that pauses the agent loop at iteration

boundaries — i.e. as soon as the in-flight LLM request and its tool

calls complete. Running /pause again resumes the loop.

The pause is implemented in LocalRuntime as a single channel that is

open while paused and closed on resume; runStreamLoop calls

waitIfPaused at the top of each iteration.

Assisted-By: docker-agent
App.TogglePause now returns (paused, supported) so the TUI can show a

clear "Pause is not supported with remote runtimes" message instead of

the misleading "Runtime resumed" toast that the silent fallback used to

produce.

Adds pause_test.go covering the toggle cycle, the not-paused fast path,

block-until-resumed, ctx cancellation while paused, broadcast to multiple

waiters, and a -race stress run with concurrent togglers and waiters.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 30, 2026 10:29
Copy link
Copy Markdown

@docker-agent docker-agent Bot left a comment

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

The pause/resume implementation is clean and correct. The channel-based broadcast design (close channel to wake all waiters in O(1)) is idiomatic Go. The mutex correctly guards the channel pointer without holding it during the blocking select, avoiding potential deadlocks. Context cancellation is properly handled. Test coverage is thorough, including race detection.

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.

1 participant