Skip to content

fix(tests): isolate BEADS bridge test from 3.11 writer-loop race#272

Open
jaylfc wants to merge 1 commit intomasterfrom
fix/beads-test-3.11-flake
Open

fix(tests): isolate BEADS bridge test from 3.11 writer-loop race#272
jaylfc wants to merge 1 commit intomasterfrom
fix/beads-test-3.11-flake

Conversation

@jaylfc
Copy link
Copy Markdown
Owner

@jaylfc jaylfc commented Apr 30, 2026

Diagnosis

test_create_task_marks_project_dirty asserts that project_id in bridge._dirty immediately after a POST that creates a task. The BeadsBridge writer loop runs every 0.2 s in the background. On CPython 3.11 the event loop schedules the writer task during the await points inside the ASGI HTTP round-trip (HTTP framing + aiosqlite writes). The writer fires, does pending = list(self._dirty); self._dirty.clear(), and empties the set before the test assertion runs — leaving _dirty empty and the assertion failing. The same commit passes on 3.13 where timing differs.

Fix

One line in the test: call await bridge.stop() before bridge._dirty.clear(). This tears down the background writer task so it cannot race the assertion. mark_dirty() is synchronous and still adds to _dirty normally; the only thing missing is the consumer that would clear it.

Verification

  • Ran tests/projects/test_routes_beads.py::test_create_task_marks_project_dirty 5× in a row on the local machine (Python 3.14): all green.
  • Ran full tests/projects/test_routes_beads.py (7 tests): all 7 green.
  • Fix is 6 lines, test file only, no production code touched.
  • Python 3.11 not available locally; CI on this PR will confirm the fix across all matrix versions.

Summary by CodeRabbit

  • Tests
    • Improved timing in a test case to ensure accurate verification of project state changes during task creation.

…1 flake

The background writer loop in BeadsBridge drains _dirty every 0.2 s. On
CPython 3.11 the event loop schedules the writer task during the awaits
inside the HTTP round-trip (HTTP processing + aiosqlite writes), so the
loop fires and calls _dirty.clear() after mark_dirty() but before the
test assertion, leaving an empty set. Fix: call bridge.stop() before the
clear+action+assert block so the writer task is torn down and cannot race
the assertion. The route still calls mark_dirty() normally; only the
background consumer is absent for the duration of the assertion.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 41bd705f-3ff3-4c45-b9de-40829e97f312

📥 Commits

Reviewing files that changed from the base of the PR and between 629c081 and 45b3f14.

📒 Files selected for processing (1)
  • tests/projects/test_routes_beads.py

📝 Walkthrough

Walkthrough

The test test_create_task_marks_project_dirty is fixed by stopping the Beads bridge's background writer immediately after project creation. This prevents the periodic writer loop from running during subsequent HTTP operations and draining the dirty set before the assertion is evaluated.

Changes

Cohort / File(s) Summary
Test Fix for Beads Bridge
tests/projects/test_routes_beads.py
Added await bridge.stop() call to halt the background writer early, preventing it from interfering with dirty set assertions during test execution.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🐰 The bridge was racing, oh what a sight,
Background writers running day and night,
But now we stop it, just in time,
Before assertions fall out of rhyme!
The dirty set stands pure and clean,
Test fixed and stable, pristine! ✨

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing a race condition in a BEADS bridge test related to Python 3.11's writer-loop behavior.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/beads-test-3.11-flake

Review rate limit: 2/3 reviews remaining, refill in 20 minutes.

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

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented Apr 30, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • tests/projects/test_routes_beads.py - 0 issues

Reviewed by grok-code-fast-1:optimized:free · 152,540 tokens

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.

1 participant