Skip to content

feature: add Stop() for graceful Start() loop shutdown#56

Merged
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/add-graceful-shutdown
Mar 22, 2026
Merged

feature: add Stop() for graceful Start() loop shutdown#56
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/add-graceful-shutdown

Conversation

@toddr-bot
Copy link
Collaborator

@toddr-bot toddr-bot commented Mar 21, 2026

Summary

  • Adds Stop() public method to signal the Start() event loop to exit gracefully
  • Start() now returns the loop iteration count instead of running forever
  • Start() can be called again after Stop() — the flag resets on entry

Why

Start() ran while(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 _running Bool 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

  • 14 new tests in t/08-test_start_stop.t covering:
    • Stop() from background_function after N iterations
    • Stop() from message_function callback
    • Re-calling Start() after Stop()
    • Prior Stop() doesn't prevent subsequent Start()
    • Return value (iteration count)
  • Full suite passes: 341 tests, 15 files

🤖 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

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>
@toddr-bot toddr-bot force-pushed the koan.toddr.bot/add-graceful-shutdown branch from 30ff5b5 to 5ca601a Compare March 22, 2026 02:36
@toddr toddr marked this pull request as ready for review March 22, 2026 02:45
@toddr-bot
Copy link
Collaborator Author

Rebase: feature: add Stop() for graceful Start() loop shutdown

Branch koan.toddr.bot/add-graceful-shutdown rebased onto main and force-pushed.

Diff: 2 files changed, 235 insertions(+), 3 deletions(-)

Actions

  • Resolved merge conflicts (1 round(s))
  • Rebased koan.toddr.bot/add-graceful-shutdown onto upstream/main
  • Force-pushed koan.toddr.bot/add-graceful-shutdown to origin
  • CI polling timed out

CI

CI still running (timed out waiting).


Automated by Kōan

@toddr toddr merged commit 0f36393 into cpan-authors:main Mar 22, 2026
21 checks passed
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.

2 participants