AI Architect tops SWE-Bench Pro with 39% higher task success. See results

AI Architect tops SWE-Bench Pro

AI Architect Eliminated Deadlocks in a Concurrent Queue That Coding Agents Couldn’t Escape

AI Architect Eliminated Deadlocks in a Concurrent Queue That Coding Agents Couldn't Escape

Table of Contents

Summary 

Concurrency bugs are among the hardest problems in software engineering, not because writing concurrent code is difficult, but because coordinating multiple moving parts without unintended dependencies requires a deep understanding of the entire system. 

As part of SWE-Bench Pro evaluation, a benchmark designed to test how well AI coding agents solve real engineering problems in production-grade repositories, one task focused on implementing a reusable concurrent queue for Teleport. The queue needed to process tasks in parallel while preserving submission order, enforcing backpressure, and shutting down cleanly. 

The baseline coding agent, Claude Sonnet 4.5, produced a design that became stuck in a circular deadlock and never completed execution. Whereas the baseline agent augmented with deep codebase context from Bito’s AI Architect was able to rethink the system holistically and arrive at a simpler architecture that passed all backpressure and ordering tests without introducing deadlocks. 

The challenge 

Teleport needed a reusable concurrent queue utility with four strict guarantees: 

  • Process items in parallel using a configurable worker pool 
  • Return results in the exact order tasks were submitted 
  • Apply backpressure to block new submissions when capacity is exceeded 
  • Support graceful shutdown via Close() 

Each requirement individually is manageable. The difficulty arises when all must coexist in the same system. 

Parallel workers naturally complete tasks out of order. Backpressure requires blocking submission under specific conditions. Shutdown requires coordinating all active goroutines without leaving any stuck. 

This is a classic concurrency problem that combines parallel processing, order preservation, and resource management; three concerns that create complex synchronization requirements when combined. To ensure correctness, Teleport’s test suite included 6 backpressure scenarios specifically designed to trigger deadlocks in naive implementations. 

Why the baseline agent failed 

Claude Sonnet 4.5 designed an N+3 goroutine architecture: a main run() goroutine, a dedicated input goroutine, N workers, and a dedicated output goroutine. This created four coordination channels, multiple WaitGroups, and shared state between goroutines. 

At first glance, this separation appears logical. Each component had a clearly defined role. But the interactions between them created hidden dependencies. 

The result was a circular deadlock: Close() waits for run(), run() waits for the output goroutine, the output goroutine waits for workers, workers are blocked on a test channel, and close(done) can’t execute because Close() hasn’t returned. The test timed out at 2 minutes and was killed. 

⚠ ROOT CAUSE: The coding agent over-engineered the goroutine architecture (N+3 goroutines with 4+ coordination channels), creating a circular dependency chain that deadlocked when the backpressure test intentionally blocked workers.

How Bito’s AI Architect solved it 

Instead of adding more coordination logic, Bito’s AI Architect guided the agent to step back and analyze the entire execution model. 

Bito’s AI Architect builds a knowledge graph of the code and execution flow. This graph maps how data moves between components, where synchronization occurs, and which modules influence each other. 

Bito’s AI Architect’s iterative refinement methodology guided the agent through 6 architectural iterations, progressively simplifying from complex multi-goroutine designs to a minimal N+1 architecture. The final design eliminated separate input and output goroutines entirely. 

Input processing became the main loop (not a separate goroutine), backpressure came naturally from a buffered workCh channel, and output happened synchronously after all workers completed. The result: zero coordination channels, one WaitGroup, no shared state, no deadlock risk. 

KEY ARCHITECTURAL INSIGHT 

Fewer goroutines means fewer deadlocks. The buffered channel itself provides natural backpressure, no semaphores needed. And synchronous output after worker completion eliminates race conditions entirely. Simplification was the solution.

Head-to-head comparison 

 Claude Sonnet 4.5 (baseline agent) Bito’s AI Architect 
Code Exploration Built architecture from scratch without concurrency pattern guidance Iterative refinement through 6 architectures — guided by Bito’s methodology 
Architecture N+3 goroutines, 4+ coordination channels, multiple WaitGroups N+1 goroutines, 1 buffered channel, single WaitGroup 
Backpressure Complex semaphore mechanism — added coordination overhead Buffered channel capacity — natural blocking, zero overhead 
Deadlock Risk HIGH — circular dependency caused test timeout at 2 minutes ELIMINATED — linear flow with no circular waits 
Task Outcome FAILED (deadlock, exit code 124/143) PASSED — all 6 backpressure scenarios + ordering test 

Conclusion 

Complex concurrency problems tempt engineers toward complex solutions. But complexity in concurrent code is the enemy of correctness. 

Teleport needed a concurrent queue that could run tasks in parallel, keep them in order, handle backpressure, and shut down cleanly. The baseline agent overcomplicated things with extra goroutines and channels, which caused deadlocks and blocked shutdown. 

Bito’s AI Architect’s iterative methodology guided the agent to discover that simplification, not more synchronization primitives, was the path to a deadlock-free implementation. By understanding the full system, it simplified the design: a single main loop, one buffered channel to handle tasks and backpressure, and result ordering after workers finish. This removed all deadlocks while meeting all requirements. 

The key lesson: complex concurrency problems are best solved by simplifying the system, not adding more layers. With the right system-level context, Teleport’s queue became reliable, easy to maintain, and fully correct. 

Picture of Anand Das

Anand Das

Anand is Co-founder and CTO of Bito. He leads technical strategy and engineering, and is our biggest user! Formerly, Anand was CTO of Eyeota, a data company acquired by Dun & Bradstreet. He is co-founder of PubMatic, where he led the building of an ad exchange system that handles over 1 Trillion bids per day.

Picture of Amar Goel

Amar Goel

Amar is the Co-founder and CEO of Bito. With a background in software engineering and economics, Amar is a serial entrepreneur and has founded multiple companies including the publicly traded PubMatic and Komli Media.

Written by developers for developers red heart icon

This article is brought to you by the Bito team.

Latest posts

Why Coding Agents Get Lost in Your Codebase (Even After Indexing Everything) 

The TPUT Implementation Claude Code Got Wrong and AI Architect Got Right

How to Integrate Bito’s AI Architect with Claude Code

How to Integrate Bito’s AI Architect with Cursor

The 9-File Security Hardening That Coding Agents Missed and AI Architect Nailed

Top posts

Why Coding Agents Get Lost in Your Codebase (Even After Indexing Everything) 

The TPUT Implementation Claude Code Got Wrong and AI Architect Got Right

How to Integrate Bito’s AI Architect with Claude Code

How to Integrate Bito’s AI Architect with Cursor

The 9-File Security Hardening That Coding Agents Missed and AI Architect Nailed

From the blog

The latest industry news, interviews, technologies, and resources.

Code Indexing

Why Coding Agents Get Lost in Your Codebase (Even After Indexing Everything) 

arrow bito ai
The TPUT Implementation Claude Code Got Wrong and AI Architect Got Right

The TPUT Implementation Claude Code Got Wrong and AI Architect Got Right

arrow bito ai
How to Integrate Bito's AI Architect with Claude Code

How to Integrate Bito’s AI Architect with Claude Code

arrow bito ai