The Commonplace
Home Papers Evidence Explore Trends Syntheses Digests References Docs 🎲 Workforce Futures
← Papers
Direction, evidence grade, and study type are AI-generated labels (gpt-5-mini), not human-verified. Syntheses are LLM-written. "Tensions" are machine-detected candidates, not confirmed contradictions. A research-acceleration tool, not peer review. How this is built →

Combining deterministic post-condition checks with retries and informed backtracking cuts LLM code-generation failures by up to 66 percentage points at modest extra cost, but recovery mechanics alone cannot yet substitute for plan synthesis—autonomous software engineering remains out of reach.

The Dual-State Architecture for Reliable LLM Agents
Matthew Thompson · December 18, 2025
arxiv descriptive medium evidence 7/10 relevance Full text usable extracted full text Source PDF

Structured author observations

Linked only from stored provider relations; the raw author line above is never matched by name.

Arxiv

Latest observation:

  1. Matthew Thompson unresolved corpus identity

Semantic Scholar

Latest observation:

  1. M. Thompson provider ID
Formalizing a Dual-State Action Pair with guard-based verification plus a three-level recovery hierarchy substantially reduces stochastic failure rates of code-generation LLM agents across multiple models, but execution-level recovery alone does not achieve end-to-end autonomous patch production.

Citation observations

Cumulative provider counts captured on specific dates; providers are never combined.

Large Language Models deployed as code generation agents exhibit stochastic behavior incompatible with the deterministic guarantees required by software engineering. We formalize the Dual-State Action Pair (DSAP), an execution primitive that couples stochastic generation with deterministic post-condition verification. Guard functions act as sensing actions that project opaque LLM outputs onto observable workflow state, enabling a dual-state decomposition: finite, deterministic S_workflow paired with infinite, stochastic S_env. We prove that for epsilon-capable generators, failure probability P(fail) <= (1-epsilon)^R_max -> 0. To prevent naive O(R^K) retry explosion across multi-step workflows, we introduce a three-level recovery hierarchy: context refinement (retry within step), informed backtracking (stagnation detection with cascade invalidation and context injection to upstream steps), and human escalation. Experimental validation across 13 LLMs (1.3B-15B parameters) on three diagnostic probes demonstrates reliability gains of up to 66 percentage points at 1.2-2.1x baseline cost. Recovery mechanism evaluation on 99 SWE-Bench Pro instance-arm pairs (Qwen3-Coder-Next) demonstrates 100% context injection effectiveness (upstream output changed in all 71 escalation events) with step-specific recovery asymmetry -- 37.5% for test generation vs. 0% for patch generation -- and 0% end-to-end patch production, establishing the boundary between execution architecture and plan synthesis: execution recovery is necessary but not sufficient for autonomous software engineering.

Summary

Main Finding

The paper proposes the Dual-State Action Pair (DSAP) execution primitive and a three-level recovery hierarchy to make LLM-based code-generation agents reliably usable within human-authored software engineering workflows. DSAP separates a finite, deterministic workflow state (guard verdicts) from an opaque, stochastic environment (generated artifacts and context), coupling each generation step to a deterministic post-condition Guard that yields a tri-state verdict (⊤, ⊥retry, ⊥fatal). Theoretical bounds show that for an ϵ-capable generator, the probability of persistent failure falls as P(fail) ≤ (1−ϵ)Rmax → 0 as Rmax increases. Experiments across 13 models and SWE-Bench Pro validate large reliability gains (up to +66 percentage points) at modest extra compute (1.2–2.1× baseline), demonstrate effective context-injection recovery, and identify clear boundaries where execution-level recovery cannot substitute for plan synthesis (0% end-to-end patch production in the SWE-Bench recovery experiments).

Key Points

  • Dual-state decomposition: execution state S = Sworkflow × Senv, where Sworkflow is finite (guard verdicts: ⊥, ⊤, ⊥fatal) and Senv contains artifacts and opaque context. This enables deterministic control logic outside the stochastic generator.
  • DSAP primitive: each step = (precondition ρ, generator agen, tri-state guard G). Guards act as post-condition verifiers that produce feedback used for retry or escalation.
  • Tri-state guards distinguish recoverable failures (⊥retry → refine context) from unrecoverable (⊥fatal → human escalation).
  • Three-level recovery hierarchy:
    • Level 1: Context refinement (local retries, augment context with guard feedback).
    • Level 2: Informed backtracking (stagnation detection, cascade invalidation, context injection upstream).
    • Level 3: Human escalation (budget exhausted or ⊥fatal).
  • Formal guarantees:
    • Assumption: generator is ϵ-capable (nonzero chance of satisfying guard under valid context).
    • Proposition 1: P(fail) ≤ (1−ϵ)Rmax; thus failure probability →0 with large Rmax.
    • Corollary: Rmax required for target global reliability δ over K steps: Rmax ≥ ln(1 − δ^{1/K}) / ln(1 − ϵ).
    • Recovery hierarchy bounds total attempts to O(K × Rmax × emax), preventing naive O(RKmax) retry explosion.
  • Experimental highlights:
    • Diagnostic probes (LRU Cache, Template Engine, Password Validator) across 13 models (1.3B–15B) show up to +66 percentage points improvement; qualified-model overhead 1.2–2.1× compute vs baseline single attempt; Pass@5 comparison costs 5×.
    • SWE-Bench Pro (99 instance-arm pairs, Qwen3-Coder-Next): 100% effectiveness of context injection (upstream outputs changed in all 71 injection events), asymmetry in recovery success (37.5% recovery for test generation vs 0% for patch generation), and 0% end-to-end automatic patch production—showing execution recovery alone cannot replace plan synthesis.
  • Practical constraints: workflow topology and escalation routing are human-authored; the system is an execution architecture, not an automatic planner.

Data & Methods

  • Formal framework: Definitions for state decomposition, scoped context, action pair with tri-state guard, system dynamics, stagnation detection, cascade invalidation, and context injection. Algorithms:
    • Algorithm 1: EXECUTE-PLAN (basic DSAP loop with context refinement).
    • Algorithm 2: EXECUTE-PLAN-WITH-RECOVERY (adds Level 2/3 recovery).
  • Theoretical results: Proposition 1 (asymptotic soundness), Corollary 1 (Rmax reliability bound), Propositions 2–3 (termination and prevention of O(RK) explosion).
  • Empirical evaluation:
    • Diagnostic probes: three targeted tasks (LRU Cache, Template Engine, Password Validator) designed to isolate failure modes (drift, structural gaps, calculation gaps).
    • Models: 13 LLMs across 6 families (parameter counts 1.3B–15B). Local inference via Ollama, temperature T = 0.7.
    • Trial design: 50 independent trials per model–task cell, context isolation between trials. Baseline (single attempt) vs Guarded (Rmax = 3).
    • Statistical testing: Fisher’s exact test for significance; effect sizes (Cohen’s h).
    • Recovery validation: SWE-Bench Pro subset (99 instance-arm pairs, Python, Qwen3-Coder-Next via Open-Router). Two TDD workflow variants (analysis → gen_test → gen_patch). Step-level parameters: Rmax=6; ap_gen_test (rpatience=2, emax=1 → escalates to analysis); ap_gen_patch (rpatience=3, emax=2 → escalates to analysis and gen_test). Metrics recorded: stagnation events, escalation cycles, cascade depth, injection effectiveness, recovery rates per step.
  • Limitations in evaluation: models with negligible baseline capability (ϵ≈0) were excluded from gain analysis; Docker-based end-to-end SWE-Bench evaluation was not performed; escalation routing is human-configured; generalizability to other model families or cloud LLM APIs requires further study.

Implications for AI Economics

  • Reliability vs compute trade-offs are quantifiable and favorable: guarded execution yields large reliability gains at modest extra cost (1.2–2.1×). For many engineering tasks, adding verification and retry control is more cost-effective than naive sampling (Pass@5 at 5×).
  • Marginal value of verification layers: DSAP shows architectures that add deterministic verification and structured recovery can increase effective utility of mid-sized models. This implies firms can extract more value from smaller/cheaper models by investing in execution architecture rather than only increasing model scale.
  • Capability thresholds and market segmentation:
    • There exists a capability threshold (ϵ > 0) below which verification cannot compensate. Products and services should profile tasks by model qualification (task-specific ϵ) to decide whether execution-layer investment is worthwhile.
    • Commercial offerings may tier services: (a) lightweight verification + retry for qualified tasks (low-cost, high-automation), (b) hybrid with human-in-the-loop for borderline tasks, (c) planner/synthesis investments for tasks requiring plan-level reasoning.
  • Cost accounting and pricing models:
    • Providers can offer pay-per-retry or subscription pricing where Rmax/emax budgets and escalation rates are monetized. Economic models must include expected retry counts conditioned on ϵ and workflow K.
    • Enterprises should evaluate ROI comparing (i) larger model compute cost vs (ii) development cost of guard engineering + modest retry budget.
  • Labor and task allocation:
    • Level 3 human escalation remains necessary in many cases; DSAP reduces but does not eliminate human oversight. This predicts continued demand for human engineers for complex plan-level failures, shifting their role toward handling escalations and designing robust workflows/guards.
    • As execution reliability improves, labor shifts from routine patch application to higher-level synthesis and exception resolution—impacting wages and demand composition.
  • Product design and competitive strategy:
    • Vendors of developer tooling can differentiate by offering robust guard libraries, stagnation detectors, and context-injection mechanisms—these have outsized value relative to raw model size.
    • Market entrants should focus on modular workflows and auditable versioned artifacts (paper’s artifact DAG) to support learning from failure histories and regulatory/compliance demands.
  • Regulatory and safety economics:
    • DSAP’s deterministic guard verdicts and artifact provenance (append-only DAG) enhance auditability and can lower compliance costs for safety-critical software development (finance, healthcare, infrastructure), making LLM-assisted development more acceptable under regulation.
  • Open economic questions for research and practitioners:
    • How to estimate task-specific ϵ in deployed settings to price retry budgets and human oversight?
    • What is the cost-optimal split between investing in larger models versus engineering robust guard/recovery systems?
    • How do escalation labor costs scale with workflow complexity and with improvements in guard design?
    • Can automated plan-synthesis (needed beyond execution recovery) be made cost-effective, or will human-in-the-loop remain the cheaper path for many classes of software tasks?

Actionable takeaway for AI economists and product teams: evaluate candidate developer-automation products by (i) measuring task-specific model qualification (ϵ), (ii) estimating expected retries under DSAP parameters (Rmax, rpatience, emax), and (iii) comparing the incremental cost and human-escalation risk against the cost of larger models or manual labor—DSAP-style execution control often yields superior reliability-per-dollar for tasks above the capability threshold but does not obviate investment in planning/synthesis capabilities for full autonomy.

Assessment

Paper Typedescriptive Evidence Strengthmedium — The paper combines a formal theoretical bound (for an assumed class of 'epsilon-capable' generators) with empirical experiments across 13 LLMs and two benchmark sets; this provides plausible internal validity for claims about reliability gains. However, the empirical evaluation is limited to diagnostic probes and a modest set of SWE-Bench instances, lacks causal inference about downstream productivity or economic outcomes, and depends on assumptions (epsilon-capability, guard-function design) that are not independently validated across broad real-world deployments. Methods Rigormedium — Rigor is supported by a clear formalization (DSAP), provable failure bounds, and cross-model experiments; but the experimental design appears narrow (three diagnostic probes, 99 instance-arm pairs for recovery), details on statistical testing, robustness checks, ablations, and reproducibility artifacts are not described in the summary, and some important design choices (guard functions, context-injection heuristics, cost accounting) may be task- and implementation-specific. SampleExperiments evaluate 13 LLMs ranging from 1.3B to 15B parameters on three diagnostic probes; recovery mechanism evaluation uses 99 SWE-Bench Pro instance-arm pairs with Qwen3-Coder-Next models, reporting 71 escalation events and step-level recovery outcomes (e.g., 37.5% recovery for test generation, 0% for patch generation). Performance improvements reported as up to 66 percentage points reliability gain at 1.2–2.1x baseline computational cost. Themesproductivity human_ai_collab GeneralizabilityLimited model range: no evaluation of very large models (e.g., multi-100B or proprietary models) so results may not hold at other scale regimes, Task specificity: focused on code-generation/workflow probes and SWE-Bench; findings may not extend to other domains or more complex, messy real-world software tasks, Synthetic/diagnostic benchmarks: probes may not capture full variability of production engineering problems and developer workflows, Assumption sensitivity: theoretical guarantees rely on 'epsilon-capable' generator assumption and on guard function design, which may be hard to verify or implement generally, Operational constraints: cost estimates and retry/backtracking heuristics may change with different latency/cost tradeoffs in deployment environments, Human factors: escalation effectiveness and developer acceptance are not measured, limiting conclusions about real-world productivity gains

Claims (10)

ClaimDirectionOutcomeConfidence & EvidenceDetails
Large Language Models deployed as code generation agents exhibit stochastic behavior incompatible with the deterministic guarantees required by software engineering. Other negative stochasticity vs. deterministic guarantees
Reading fidelity high
Study strength speculative
not reported
0.03
We formalize the Dual-State Action Pair (DSAP), an execution primitive that couples stochastic generation with deterministic post-condition verification, and introduce guard functions that project opaque LLM outputs onto observable workflow state enabling a dual-state decomposition (finite deterministic S_workflow paired with infinite stochastic S_env). Other positive existence and formal properties of DSAP and guard functions
Reading fidelity high
Study strength high
not reported
0.3
For epsilon-capable generators, failure probability satisfies P(fail) <= (1 - epsilon)^R_max, which tends to 0 as R_max increases. Other positive probability of failure under retry bound
Reading fidelity high
Study strength high
P(fail) <= (1-epsilon)^R_max -> 0
0.3
To prevent naive O(R^K) retry explosion across multi-step workflows, we introduce a three-level recovery hierarchy: context refinement (retry within step), informed backtracking (stagnation detection with cascade invalidation and context injection to upstream steps), and human escalation. Other positive retry explosion mitigation in multi-step workflows
Reading fidelity high
Study strength medium
not reported
0.18
Experimental validation across 13 LLMs (1.3B–15B parameters) on three diagnostic probes demonstrates reliability gains of up to 66 percentage points. Error Rate positive reliability (failure/success rate) on diagnostic probes
Reading fidelity high
Study strength medium
n=13
up to 66 percentage points
0.18
The reliability gains come at a cost of 1.2–2.1x baseline cost. Organizational Efficiency negative computational / operation cost relative to baseline
Reading fidelity high
Study strength medium
n=13
1.2-2.1x baseline cost
0.18
Recovery mechanism evaluation on 99 SWE-Bench Pro instance-arm pairs (Qwen3-Coder-Next) demonstrates 100% context injection effectiveness: upstream output changed in all 71 escalation events. Task Allocation positive context injection effectiveness (upstream output change after escalation)
Reading fidelity high
Study strength medium
n=99
100% context injection effectiveness (upstream output changed in all 71 escalation events)
0.18
Step-specific recovery asymmetry: recovery success was 37.5% for test generation. Task Allocation positive step-level recovery success rate (test generation)
Reading fidelity high
Study strength medium
37.5% for test generation
0.18
Step-specific recovery asymmetry: recovery success was 0% for patch generation. Task Allocation null_result step-level recovery success rate (patch generation)
Reading fidelity high
Study strength medium
0% for patch generation
0.18
End-to-end patch production was 0%, establishing the boundary between execution architecture and plan synthesis: execution recovery is necessary but not sufficient for autonomous software engineering. Task Allocation null_result end-to-end patch production success rate
Reading fidelity high
Study strength medium
n=99
0% end-to-end patch production
0.18

Notes