feature: add Stop() for graceful Start() loop shutdown#56
Merged
toddr merged 1 commit intocpan-authors:mainfrom Mar 22, 2026
Merged
Conversation
toddr
approved these changes
Mar 22, 2026
Start() previously ran an infinite while(1) loop with no way to exit gracefully. Users had to kill the process to stop the bot. Now Start() uses an internal _running flag and returns the loop iteration count. Stop() can be called from background_function or message_function callbacks to signal the loop to exit after the current iteration. Start() can be called again after Stop() — the flag is reset on entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30ff5b5 to
5ca601a
Compare
Collaborator
Author
Rebase: feature: add Stop() for graceful Start() loop shutdownBranch Diff: 2 files changed, 235 insertions(+), 3 deletions(-) Actions
CICI still running (timed out waiting). Automated by Kōan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stop()public method to signal theStart()event loop to exit gracefullyStart()now returns the loop iteration count instead of running foreverStart()can be called again afterStop()— the flag resets on entryWhy
Start()ranwhile(1)with no exit mechanism. The only way to stop a bot was to kill the process. This made it impossible to write bots that shut down cleanly (e.g., on signal, after a condition, or from a background check).How
Added a private
_runningBool attribute.Start()sets it to 1 on entry and loops on it.Stop()sets it to 0. The loop exits after the current iteration completes (Process + background + sleep), so all in-flight work finishes cleanly.Testing
t/08-test_start_stop.tcovering:🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 236 insertions(+), 4 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline