Skip to content

Plugin session lifecycle features, fixes #104 - #106

Merged
TkTech merged 3 commits into
devfrom
plugin-sessions
Nov 4, 2026
Merged

TkTech merged 3 commits into
devfrom
plugin-sessions

Conversation

@TkTech

@TkTech TkTech commented Oct 31, 2026

Copy link
Copy Markdown
Owner

No description provided.

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61571% with 17 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev@73fd582). Learn more about missing BASE report.

Files with missing lines Patch % Lines
chancy/session.py 97.02% 5 Missing ⚠️
chancy/plugins/debug.py 0.00% 3 Missing ⚠️
chancy/plugins/workflow/__init__.py 95.12% 2 Missing ⚠️
chancy/utils.py 97.05% 2 Missing ⚠️
chancy/worker.py 98.78% 2 Missing ⚠️
chancy/cli/worker.py 94.73% 1 Missing ⚠️
chancy/hub.py 92.30% 1 Missing ⚠️
chancy/plugins/reprioritize.py 97.14% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##             dev     #106   +/-   ##
======================================
  Coverage       ?   85.82%           
======================================
  Files          ?       70           
  Lines          ?     4495           
  Branches       ?        0           
======================================
  Hits           ?     3858           
  Misses         ?      637           
  Partials       ?        0           
Flag Coverage Δ
unittests 85.82% <97.61%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Managed-task failures can leave startup blocked indefinitely, while interrupted rollback and ineffective metrics unsubscription can leave resources and subscriptions unreleased.

3 open issues
What changed in this PR

This PR introduces worker-owned plugin sessions and leadership leases to address transient PostgreSQL failures reported in #104. It centralizes retries, resource cleanup, and background-task supervision.

Changes:

  • Adds session-based plugin operations and retryable transactions, migrating built-in plugins.
  • Moves leadership into Worker, with lease validation, expiry, and transaction protection.
  • Expands lifecycle regression tests and migration documentation; updates the macOS release runner.
File Description
tests/​test_worker_supervision.py Tests failure reporting, shutdown, and startup cancellation.
tests/​test_task_manager.py Tests cancellation ownership and retained failures.
tests/​test_plugin_sessions.py Tests sessions, transaction retries, and leadership protection.
tests/​test_leadership.py Adds core leadership and lease regression tests.
tests/​test_cli.py Tests dashboard session cleanup and failures.
tests/​plugins/​test_workflow.py Migrates workflow tests to core leadership.
tests/​plugins/​test_workflow_scheduler.py Uses sessions and tests polling deadlines.
tests/​plugins/​test_reprioritization.py Removes the test leadership plugin.
tests/​plugins/​test_pruner.py Removes the test leadership plugin.
tests/​plugins/​test_metrics.py Tests transaction retries and updates cleanup calls.
tests/​plugins/​test_leadership.py Removes obsolete plugin leadership tests.
tests/​plugins/​test_api.py Adapts server tests to session setup.
examples/​demo.py Moves leadership configuration to Worker.
docs/​howto/​fastapi.rst Explains embedded worker failure handling.
docs/​design.rst Documents core leadership ownership.
docs/​conf.py Adds annotation cross-reference exclusions.
docs/​chancy.session.rst Documents sessions, leadership, and shutdown migration.
docs/​chancy.rst Adds the session documentation entry.
docs/​chancy.plugins.rst Removes the leadership plugin entry.
docs/​chancy.plugins.leadership.rst Removes obsolete leadership plugin documentation.
CHANGELOG.md Summarizes breaking APIs and lifecycle changes.
chancy/​worker.py Integrates sessions, leadership, and supervised teardown.
chancy/​utils.py Adds retained failures and handle-based task cancellation.
chancy/​session.py Implements plugin operations and resource ownership.
chancy/​retry.py Adds explicit retryable transaction conflicts.
chancy/​plugins/​workflow/​__init__.py Migrates scheduling and cleanup to sessions.
chancy/​plugins/​reprioritize.py Adds retry-safe priority updates.
chancy/​plugins/​recovery.py Uses protected, retryable recovery operations.
chancy/​plugins/​pruner.py Registers pruning and plugin cleanup operations.
chancy/​plugins/​metrics/​metrics.py Migrates collection, flushing, and subscriptions.
chancy/​plugins/​leadership.py Removes plugin-owned leadership implementations.
chancy/​plugins/​debug.py Uses session-owned event subscriptions.
chancy/​plugins/​cron/​__init__.py Uses periodic operations and transaction retries.
chancy/​plugins/​api/​core.py Reports unhealthy workers with HTTP 503.
chancy/​plugins/​api/​__init__.py Registers the server as a session service.
chancy/​plugins/​__init__.py Removes the leadership plugin description.
chancy/​plugin.py Defines session setup and transactional cleanup hooks.
chancy/​leadership.py Implements worker-owned leases and transaction guards.
chancy/​hub.py Adds optional handler-error isolation.
chancy/​errors.py Defines the leadership-loss exception.
chancy/​cli/​worker.py Runs dashboard infrastructure through sessions.
chancy/​app.py Updates defaults and excludes expired leadership leases.
.github/​workflows/​release.yml Switches the macOS runner to macos-26.

Review effort: Balanced

Comment thread chancy/worker.py
Comment on lines +276 to +279
def _on_task_failure(self) -> None:
self._failure_event.set()
if not self._starting and self._stop_task is None:
self._begin_stop(self.shutdown_timeout)
Comment on lines +300 to +303
self._workers[worker] = uuid4(), handler
session.callback(self._workers.pop, worker, None)
for kind in ("counter", "gauge", "histogram"):
session.subscribe(f"metrics.{kind}", handler)
Comment thread chancy/worker.py
Comment on lines +354 to +356
await self.manager.cancel_all(timeout=self.teardown_timeout)
await self._close_sessions()
except BaseException as cleanup_error:
@TkTech
TkTech merged commit 054121b into dev Nov 4, 2026
25 of 27 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