Skip to content

Refactor Bot Lifecycle and Event Synchronization#39

Merged
PenguinBoi12 merged 1 commit intomainfrom
improved-on-ready-trigger
Apr 7, 2026
Merged

Refactor Bot Lifecycle and Event Synchronization#39
PenguinBoi12 merged 1 commit intomainfrom
improved-on-ready-trigger

Conversation

@PenguinBoi12
Copy link
Copy Markdown
Contributor

This PR refactors the Bot lifecycle to clearly separate synchronization and readiness:

Previously, scheduled tasks or extensions could attempt to access bot state before rooms were available, leading to crashes. The new lifecycle ensures predictable ordering: sync → ready → scheduler, improving reliability and making asynchronous tests non-blocking.

  • Adds _synced (asyncio.Event) to track when the client has completed initial syncing.
  • _wait_until_synced now waits for the first sync before firing on_ready.
  • on_ready is guaranteed to run once, after the bot is fully synchronized, before scheduled tasks are started.
  • Scheduler start is now explicitly after on_ready, ensuring jobs can safely access bot state and rooms.
  • get_room updated to return None instead of raising, preventing crashes during startup.
  • Tests updated to avoid blocking on sync_forever, by setting _synced manually and mocking long-running tasks.

@PenguinBoi12 PenguinBoi12 requested a review from chrisdedman April 7, 2026 03:59
chrisdedman
chrisdedman previously approved these changes Apr 7, 2026
Copy link
Copy Markdown
Contributor

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

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

Nice refactor. LGTM

Copy link
Copy Markdown
Contributor

@chrisdedman chrisdedman left a comment

Choose a reason for hiding this comment

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

LGTM

@PenguinBoi12 PenguinBoi12 merged commit aaee53b into main Apr 7, 2026
4 checks passed
@PenguinBoi12 PenguinBoi12 deleted the improved-on-ready-trigger branch April 7, 2026 04:34
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