Skip to content

Add race condition detection for multi-agent orchestration#452

Merged
sreerevanth merged 2 commits into
sreerevanth:mainfrom
Itsssaksham:feature/race-condition-detector
Jun 26, 2026
Merged

Add race condition detection for multi-agent orchestration#452
sreerevanth merged 2 commits into
sreerevanth:mainfrom
Itsssaksham:feature/race-condition-detector

Conversation

@Itsssaksham

@Itsssaksham Itsssaksham commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

closes #372
Adds race condition detection support for multi-agent orchestration.

Changes

  • Added RaceConditionDetector
  • Added access tracking models for agent resource usage
  • Detects overlapping write-write conflicts
  • Detects overlapping read-write conflicts
  • Ignores read-read access patterns
  • Handles overlapping windows across multiple agents
  • Validates invalid access windows

Tests

Added comprehensive tests covering:

  • Write-write race detection
  • Read-write race detection
  • Read-read non-conflicts
  • Same-agent overlap handling
  • Boundary-touching windows
  • Multiple overlapping agents
  • Invalid window validation

Validation

  • pytest tests/test_multiagent.py -v
  • Full test suite passes (520 passed, 2 skipped) ✅
  • mypy agentwatch/orchestration/race_condition.py

Summary by CodeRabbit

  • New Features

    • Added multi-agent race condition detection to analyze overlapping resource accesses across agents, including read/write conflict identification, strict boundary handling (touching windows aren’t treated as overlaps), and reporting of detected conflicts.
  • Tests

    • Expanded coverage with new scenarios for overlapping read/write and write/write access, same-agent overlaps, non-overlapping windows, exact boundary behavior, different-resource independence, multiple-conflict reporting, zero-duration accesses, and invalid time-window validation.

@coderabbitai

coderabbitai Bot commented Jun 21, 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: Pro Plus

Run ID: b11d5cf4-8e4c-4edb-9d3d-d0fc90db5131

📥 Commits

Reviewing files that changed from the base of the PR and between 036fb99 and f20bdec.

📒 Files selected for processing (2)
  • agentwatch/orchestration/race_condition.py
  • tests/test_multiagent.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_multiagent.py
  • agentwatch/orchestration/race_condition.py

📝 Walkthrough

Walkthrough

A new agentwatch/orchestration/race_condition.py module adds typed resource-access intervals and race scanning for overlapping write-involved accesses across agents. tests/test_multiagent.py adds MAG-009 coverage for overlap rules, boundary behavior, and invalid intervals.

Changes

Race Condition Detector

Layer / File(s) Summary
Data contracts and detector implementation
agentwatch/orchestration/race_condition.py
Defines AccessType, ResourceAccess with timestamp validation, RaceConflict, RaceReport, and RaceConditionDetector with per-resource recording, strict overlap checks, pairwise scanning, and public exports.
MAG-009 race detector tests
tests/test_multiagent.py
Updates the MAG range header, adds detector imports and a timestamp helper, and adds tests covering overlapping, non-overlapping, boundary-touching, same-agent, different-resource, multi-conflict, zero-duration, and invalid-window cases.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant RaceConditionDetector
  participant ResourceAccess
  participant RaceReport

  Caller->>RaceConditionDetector: record_access(agent_id, resource, access_type, start_ts, end_ts)
  RaceConditionDetector->>ResourceAccess: __post_init__ validates end_ts >= start_ts
  Caller->>RaceConditionDetector: scan()
  RaceConditionDetector->>RaceConditionDetector: iterate pairwise accesses per resource
  RaceConditionDetector->>RaceConditionDetector: _overlaps(a, b)
  RaceConditionDetector->>RaceConditionDetector: skip same-agent and read/read pairs
  RaceConditionDetector->>RaceReport: build RaceConflict entries
  RaceConditionDetector-->>Caller: RaceReport(has_race, conflicts)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, the agents race by night,
The detector trims the overlaps just right.
Write meets write? It rings a bell,
Read with read? All is well.
Touching edges softly stay apart—
A tidy little race-guard rabbit’s art.

🚥 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 accurately summarizes the main change: adding race condition detection to multi-agent orchestration.
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 unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

🧪 PR Test Results

Check Result
Tests (pytest tests/) ✅ success
Lint (ruff check .) ❌ failure
Coverage (agentwatch) 74.84%

Python 3.12 · commit f20bdec

@sreerevanth

Copy link
Copy Markdown
Owner

@Itsssaksham please adress code rabbit's comments and do make sure the ci is green

@Itsssaksham

Copy link
Copy Markdown
Contributor Author

@sreerevanth got it.

@Itsssaksham

Copy link
Copy Markdown
Contributor Author

@sreerevanth check now

@Itsssaksham Itsssaksham force-pushed the feature/race-condition-detector branch from 036fb99 to f20bdec Compare June 25, 2026 20:10
@sreerevanth sreerevanth merged commit 0ab8bca into sreerevanth:main Jun 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] [ELUSOC] Implement Async Multi-Agent Race Condition Detector

2 participants