Contract Before Code: Failure-Compiled Contracts for Long-Horizon Coding Agents

Jiangnan YU, Kisson Songqi Lin


Abstract
Long-horizon coding agents can make many edits before testing a task-wide assumption about an API, authentication mode, environment, or persistent state. A late verifier then exposes that the implementation rests on a false premise. We call the missing step contract acquisition and propose Contract Before Code (CBC), harness-level middleware that compiles historical failures into executable preflight gates. CBC normalizes trajectories, extracts recurring failure signatures, and compiles contracts containing an applicability condition, a probe template, and a planning consequence. At inference time, it retrieves applicable contracts and runs instantiated probes before broad implementation work. Among 1,421 parsed failed SWE-Marathon trajectories, weak labels identify candidate rates of 2.6% overall and 17.5% on stripe-clone; these are not root-cause prevalence estimates. A 120-trajectory human audit reports 76.3% contract precision and 71.4% executable-probe synthesis. Across four service/API-clone tasks and 32 runs per method, CBC achieves 31.3% success (95% CI 18.0–48.6), an observed 21.9-percentage-point increase over vanilla, with 55.6% fewer pre-verification edits at 1.11× normalized token cost. The small end-to-end study supports preliminary within-family benefits; broader transfer and the stability of these gains remain unestablished.
Anthology ID:
2026.realm-1.72
Volume:
Proceedings of the Second Workshop for REsearch on Agent Language Models (REALM 2026)
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Ehsan Kamalloo, Nicolas Gontier, Nikolai Rozanov, Maryam Hashemzadeh, Akhil Arora
Venues:
REALM | WS
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
1032–1041
Language:
URL:
https://aclanthology.org/2026.realm-1.72/
DOI:
Bibkey:
Cite (ACL):
Jiangnan YU and Kisson Songqi Lin. 2026. Contract Before Code: Failure-Compiled Contracts for Long-Horizon Coding Agents. In Proceedings of the Second Workshop for REsearch on Agent Language Models (REALM 2026), pages 1032–1041, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
Contract Before Code: Failure-Compiled Contracts for Long-Horizon Coding Agents (YU & Lin, REALM 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.realm-1.72.pdf