arXiv:2610.13421cs.SEOct 2026

Manuscript Offprint

arXiv:2610.13421

REINS: Agent-guided Thread Scheduling for Concurrency Bug Detection and Reproduction

Yu Zhang, Corina S. Pasareanu, Guowei Yang

ABSTRACT

Concurrency bugs manifest only under specific thread interleavings, making them hard to detect and reproduce. Existing controlled concurrency testing techniques take over thread scheduling to explore the interleaving space. As the space grows rapidly with program scale, finding interleavings that can trigger bugs within a limited budget remains challenging. The program's concurrency semantics can reveal which variable accesses and synchronization operations under specific interleavings lead to unexpected program behavior, and thus help focus the exploration on bug-relevant interleavings. However, prior techniques have not fully exploited such semantic information. In this paper, we present REINS, an agentic approach for detecting and reproducing concurrency bugs. At its core, REINS guides thread scheduling with the agent's reasoning about the concurrency semantics and known concurrency bug patterns. REINS starts with runtime observations and combines them with static information to reason about the program's concurrency behavior and formulate hypotheses about potential bugs. A hypothesis translates into a set of constraints on event orders and variable states, guiding a controlled scheduler toward interleavings likely to trigger the bug. REINS draws conclusions from the execution results and keeps refining the constraints until the bug is triggered or the hypothesis is refuted. Compared with existing techniques on three public benchmarks, REINS detects more bugs within the same time budget. Furthermore, REINS found six previously unknown concurrency bugs in real-world projects, three of which have been confirmed by the developers.

Keywords Concurrency Testing, LLM Agent, Detection, Reproduction

1 Introduction

Concurrency bugs are notoriously difficult to detect and reproduce [34, 44]. Due to the non-determinism of thread scheduling, they may manifest only under specific thread interleavings, making them difficult to expose during testing. Once triggered in production, they can lead to severe consequences, such as program crashes, data corruption, and security vulnerabilities [27]. Traditional stress testing, which relies on massive repeated executions and random perturbations, struggles to expose concurrency bugs in the vast thread-interleaving space [13, 34]. Controlled concurrency testing (CCT) takes over thread scheduling to make the exploration and reproduction of interleavings controllable, and has therefore become one of the prevailing approaches to concurrency bug detection and reproduction. CCT mainly proceeds through systematic enumeration [33, 34, 14] or randomized sampling with probabilistic guarantees [4, 54]. Recent work further improves the scheduling strategies, such as periodical scheduling [48] and selectively uniform sampling [55], or introduces ideas from reinforcement learning [32] and greybox fuzzing [49] to guide scheduling decisions. Despite these advances, bugs with narrow triggering windows and specific state preconditions remain difficult to expose within a limited budget. A key limitation of existing approaches is their insufficient exploitation of concurrency semantics of the program, e.g., which combinations of accesses are dangerous under the program logic, and in what state the program must be for a bug to be triggered. Such information is hard to obtain at the schedule level where these approaches operate. Recently, LLM-based agents have been applied to a wide range of software testing tasks [46, 56, 37, 47, 6], demonstrating strong capabilities in program comprehension and reasoning. These advances motivate us to investigate whether an agent's reasoning about concurrency semantics can guide thread scheduling to more effectively trigger concurrency bugs.

However, effectively applying LLM agents to concurrency testing presents several key challenges, which we summarize as follows. C1: Incomplete understanding of concurrency semantics. LLM agents struggle to comprehend the concurrency semantics [19, 8], especially in large programs where a concurrency bug often spans multiple threads, functions, and files. Constrained by their context, the agents may not be able to piece together a reliable global view and locate bug-relevant operations in massive code bases. C2: The gap between concurrency semantics and thread scheduling. The agent reasons at the level of program semantics, focusing on the roles of variables and operations and on which thread interactions may lead to unexpected behavior. On the other hand, the scheduler must decide which thread to run next at every scheduling point during execution, and a single run may involve thousands of such points. Requiring the agent to make every scheduling decision is impractical, while its high-level semantic reasoning cannot be directly translated into concrete thread choices at individual scheduling points. C3: Unreliable agent output. The agent may produce plausible yet incorrect reasoning [45, 20], and may even hallucinate variables and code locations that do not exist, so its claims do not directly constitute evidence.

In this paper, we propose REINS, an agentic approach that addresses the above challenges for detecting and reproducing concurrency bugs in shared-memory multithreaded programs. The key insight of REINS is to turn the agent's reasoning about the concurrency semantics into constraints that the scheduler recognizes and enforces, thereby guiding thread scheduling toward the interleavings that are likely to trigger bugs, while the results of the controlled executions in turn serve as the evidence to refine the agent's hypotheses. Specifically, REINS introduces the following features to address the three challenges. For C1, REINS starts from the shared-variable accesses observed in real executions. They reflect the actual interactions between threads and, although covering limited execution behavior, they help the agent to initially locate the key variables and operations. Starting from runtime information, the agent selectively examines relevant source code and queries the corresponding calling contexts and path conditions through static analysis to supplement information not captured by runtime observations. This enables the agent to reason about concurrency semantics without exhaustively exploring a large codebase. Based on this reasoning, the agent formulates bug hypotheses, each characterizing the program interactions that may lead to a specific concurrency bug pattern and its resulting failure. For C2, REINS bridges the agent's reasoning and the scheduler's execution with the schedule plan. A schedule plan is a set of constraints on event orders and variable states, involving only the few key events and variables required to trigger a bug, which is the granularity the agent can express precisely at the semantic level. The agent derives the constraints from a hypothesis and writes them into a plan for the scheduler to execute. The scheduler controls the execution according to the plan at the scheduling points relevant to the constraints, and decides the rest at random. For C3, REINS checks the agent's output and takes execution results as evidence. The events and variables in a plan proposed by the agent are validated against the program before the plan is executed by the controlled scheduler. The conclusions of REINS rest on real executions. For an execution that triggers the bug, its scheduling trace is recorded so that the bug can be deterministically replayed. For the executions that do not trigger the bug, the results distinguish whether the interleaving did not happen as planned or happened without the expected failure, and the agent then revises the plan or the hypothesis accordingly and iterates with subsequent executions.

REINS proceeds iteratively through three phases: comprehend, attempt, and assess. The comprehend phase builds the understanding of the concurrency semantics of the program and proposes a set of bug hypotheses as candidates. The attempt phase derives schedule plans for the candidates and executes them to trigger the hypothesized bugs. The assess phase analyzes the results, propagates conclusions to related candidates, and decides whether the next iteration returns to the comprehend phase for further collection or moves on to the attempt phase for the remaining candidates. REINS continues until all candidates are settled or the time budget is exhausted.

We evaluate REINS on three public benchmarks [43, 5, 26], and compare it with representative controlled scheduling techniques [49, 55, 4, 44]. REINS detected more bugs than all baselines across the three benchmarks. In particular, on the largest benchmark, RaceBench [26], REINS detected 38 more bugs than the best-performing baseline [55] within the same time budget. In addition, on two real-world projects, REINS detected six previously unknown concurrency bugs, three of which have been confirmed by their developers.

In summary, this paper makes the following contributions:

• We propose agent-guided thread scheduling, an approach that leverages the agent’s reasoning about the concurrency semantics to guide controlled scheduling toward bug-relevant schedules.

• We design and implement REINS, an agentic system for detecting and reproducing concurrency bugs, which integrates agent reasoning with controlled scheduling and iterates through the comprehend, attempt, and assess phases.

• We evaluate REINS against existing techniques on public benchmarks, where it detects more bugs within the same time budget, demonstrating its effectiveness. REINS further identifies six previously unknown bugs in real-world projects.

Mutex mutatorsMutex_; ThreadSafeCodeBlockMap map; mozilla::Atomic<bool> CodeExists(false); bool RegisterCodeBlock(const CodeBlock* cs) { bool result; { LockGuard<Mutex> lock(mutatorsMutex_); result = map.insert(cs); } if (result) CodeExists = true; return result; }

void UnregisterCodeBlock(const CodeBlock* cs) { size_t newCount; { LockGuard<Mutex> lock(mutatorsMutex_); map.remove(cs); newCount = map.length(); } if (newCount == 0) CodeExists = false; }

T MemoryRead(uintptr_t addr) { if (CodeExists) { // an out-of-bounds wasm access must trap if (IsWasmOutOfBounds(addr)) throw RuntimeError(); } return (T)addr; }

(a)

Thread main loop { m = compile(); // calls RegisterCodeBlock ... drop(m); gc(); // calls UnregisterCodeBlock }

Thread worker loop { w = compile(); // calls RegisterCodeBlock ... loop { try { w.load(oob); } // calls MemoryRead catch (RuntimeError) {...} } }

main worker map CodeExists

gc() → UnregisterCodeBlock(X) when X is the only block left in map e1 (main, W(map)@£17) e2 (main, R(map)@£18) newCount = 0; unlocked at £19; £20 pending

compile() → RegisterCodeBlock(Y) insert Y into map, then set CodeExists e3 (worker, W(map)@£8) e4 (worker, W(CodeExists)@£10)

w.load(oob) → MemoryRead(a) e5 (worker, R(CodeExists)@£23) reads true → £25 trap, caught ✓

writes false from the old newCount e6 (main, W(CodeExists)@£20)

w.load(oob) → MemoryRead(a) e7 (worker, R(CodeExists)@£23) reads false → £27 raw read → SIGSEGV X

(b)

Figure 1: An atomicity violation from Mozilla SpiderMonkey that ends in a crash on an out-of-bounds access. CodeExists caches whether map is non-empty, but the two are not updated atomically. (a) The simplified key code snippet. (b) The thread interleaving that triggers the bug, with red marking the states where map and CodeExists disagree.

References (48)