Skip to content

fix(backend): align pytest async loop scope - #14267

Merged
ntindle merged 2 commits into
devfrom
codex/fix-async-redis-loop-lifecycle-v2
Sep 2, 2026
Merged

fix(backend): align pytest async loop scope#14267
ntindle merged 2 commits into
devfrom
codex/fix-async-redis-loop-lifecycle-v2

Conversation

@ntindle

@ntindle ntindle commented Sep 2, 2026

Copy link
Copy Markdown
Member

Why / What / How

The full backend suite still reused process-global Prisma and async Redis pools across pytest event loops after #14259. The backend already ran session-scoped async fixtures, but unscoped async tests ran on function-scoped loops by default. Stack PR #14078 added enough async coverage to reproduce the mismatch consistently: later session-scoped Copilot tests saw Prisma and Redis connections created on loops that pytest had closed.

This aligns ordinary async backend tests with the existing session-scoped fixture loop. The Graphiti subtree keeps function-scoped loops for tests backed by its explicitly function-scoped FalkorDB fixtures and per-loop ingestion state. Tests that explicitly request another loop scope retain that behavior.

Changes 🏗️

  • Set asyncio_default_test_loop_scope to session in the backend pytest configuration.
  • Preserve Graphiti's intentional function-loop isolation for unscoped async tests in its local conftest.py.
  • Keep explicit test loop scopes and the existing session-scoped async fixture configuration unchanged.

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:

For configuration changes:

  • .env.default is already compatible with my changes
  • docker-compose.yml is already compatible with my changes
  • The pytest configuration change is listed under Changes

@ntindle
ntindle requested a review from a team as a code owner September 2, 2026 03:18
@ntindle
ntindle requested review from Abhi1992002 and Pwuts and removed request for a team September 2, 2026 03:18
@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Sep 2, 2026
@github-actions github-actions Bot added cla: signed CLA signed by all contributors platform/backend AutoGPT Platform - Back end size/xs labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Overlap Detection

This check compares your PR against all other open PRs targeting the same branch to detect potential merge conflicts early.

🟢 Low Risk — File Overlap Only

These PRs touch the same files but different sections (click to expand)

Summary: 0 conflict(s), 0 medium risk, 10 low risk (out of 10 PRs with file overlap)


Auto-generated on push. Ignores: openapi.json, lock files.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 47e0df2f-9c33-4e6c-9b0b-d43c6d2fc2d7

📥 Commits

Reviewing files that changed from the base of the PR and between 61c8ff0 and 4bca86f.

📒 Files selected for processing (1)
  • autogpt_platform/backend/backend/copilot/graphiti/conftest.py

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: check API types
  • GitHub Check: Build, smoke, and scan (linux/amd64)
  • GitHub Check: Build, smoke, and scan (linux/arm64)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: Seer Code Review
  • GitHub Check: type-check (3.13)
  • GitHub Check: test (3.11)
  • GitHub Check: type-check (3.12)
  • GitHub Check: lint
  • GitHub Check: test (3.13)
  • GitHub Check: Analyze (python)
  • GitHub Check: type-check (3.11)
  • GitHub Check: test (3.12)
  • GitHub Check: end-to-end tests
  • GitHub Check: Check PR Status
  • GitHub Check: Analyze (typescript)
🧰 Additional context used
📓 Path-based instructions (1)
Format Python code with `poetry run format`

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • autogpt_platform/backend/backend/copilot/graphiti/conftest.py
🔇 Additional comments (1)
autogpt_platform/backend/backend/copilot/graphiti/conftest.py (1)

37-37: LGTM!

Also applies to: 55-65


Walkthrough

The backend pytest configuration now uses session-scoped test loops by default. A graphiti collection hook assigns function-scoped loops to unscoped async tests in that directory.

Changes

Pytest event loop configuration

Layer / File(s) Summary
Session-scoped test loop
autogpt_platform/backend/pyproject.toml
Adds asyncio_default_test_loop_scope = "session" to the pytest configuration.
Graphiti function-scoped loop override
autogpt_platform/backend/backend/copilot/graphiti/conftest.py
Adds a collection hook that applies loop_scope="function" to eligible async tests without an explicit loop scope.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 4bca8

This change aligns backend async tests with session-scoped fixtures while preserving explicit loop scopes and the graphiti function-scope exception; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: pwuts, abhi1992002

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: aligning the backend pytest asynchronous loop scope.
Description check ✅ Passed The description directly explains the loop-scope mismatch, the configuration and Graphiti changes, and the validation performed.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-async-redis-loop-lifecycle-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 61c8ff0. Configure here.

Comment thread autogpt_platform/backend/pyproject.toml
Comment thread autogpt_platform/backend/pyproject.toml
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.30%. Comparing base (4ef8d07) to head (4bca86f).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #14267      +/-   ##
==========================================
- Coverage   80.31%   80.30%   -0.01%     
==========================================
  Files        3333     3333              
  Lines      253614   253625      +11     
  Branches    23532    23537       +5     
==========================================
- Hits       203698   203683      -15     
- Misses      44636    44659      +23     
- Partials     5280     5283       +3     
Flag Coverage Δ
platform-backend 85.54% <83.33%> (-0.01%) ⬇️
platform-frontend-e2e 28.72% <ø> (-0.21%) ⬇️

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

Components Coverage Δ
Platform Backend 85.54% <83.33%> (-0.01%) ⬇️
Platform Frontend 60.41% <ø> (-0.06%) ⬇️
AutoGPT Libs ∅ <ø> (∅)
Classic AutoGPT 28.43% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added size/m cla: pending CLA not yet signed by all contributors and removed size/xs cla: signed CLA signed by all contributors labels Sep 2, 2026
@ntindle
ntindle merged commit bc51a00 into dev Sep 2, 2026
48 checks passed
@ntindle
ntindle deleted the codex/fix-async-redis-loop-lifecycle-v2 branch September 2, 2026 04:24
@github-project-automation github-project-automation Bot moved this from 🆕 Needs initial review to ✅ Done in AutoGPT development kanban Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: pending CLA not yet signed by all contributors platform/backend AutoGPT Platform - Back end size/m

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant