SpecProbe: Probing Intent-Implementation Misalignments with Generated Executable Postconditions
Organizations: University of Massachusetts Amherst, USA · Rutgers University New Jersey, USA
Abstract
Ensuring that code faithfully reflects its documented intent is a fundamental challenge in software engineering, but the informal natural language specifications in real repositories cannot be automatically compiled into executable checks and run against implementations. We introduce behavioral probes: executable postconditions generated from natural language documentation, injected into programs, and checked during test execution to reveal where documented intent and implementation behavior align or diverge. We present SpecProbe, a repository-aware pipeline that generates behavioral probes and classifies each as non-executable, matched, or mismatched. A structured four-field schema (import, pre-ghost, post-ghost, condition) makes generated postconditions injectable and compilable in real repositories; reasoning supervised fine-tuning on 1.5K automatically curated examples enables a compact 7B model to generate probes without continued API access. On Defects4J, SpecProbe's 7B model achieves GPT-4o-comparable semantic consistency (Sem@1) at 141 lower inference cost. The pipeline reveals 80 of 726 historical bugs, and for 95% of them the original failing-test stack trace omits the method checked by the probe. On Python icontract generation, SpecProbe surpasses GPT-5-mini and GPT-o3, demonstrating transfer to a different language and contract format. These results show that behavioral probes complement failing-test stack traces with diagnostic evidence grounded in the selected method's documented intent.
Figures & tables
| Model | Size | #Ex. | #Bugs | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| GPT-4o | 200B | - | 44.0% | 77.7% | 86.2% | 82.1% | 96.2% | 96.8% | 11.8% | 86 /726 |
| GPT-4* | 200B | - | 32.0% | 57.0% | 66.0% | 65.0% | 86.0% | 89.0% | 6.7% | 35 /525 |
| Qwen2.5-Coder | 7B | - | 12.5% | 42.3% | 60.8% | 34.9% | 80.5% | 91.2% | 5.0% | 36 /726 |
| StarChat* | 16B | - | 11.0% | 38.0% | 55.0% | 25.0% | 68.0% | 83.0% | 3.6% | 19 /525 |
| Qwen2.5-Coder | 32B | - | 32.6% | 63.4% | 73.5% | 74.7% | 94.5% | 96.0% | 10.6% | 77 /726 |
| DeepSeek-R1-Distill | 32B | 800K | 39.7% | 71.6% | 80.2% | 67.3% | 94.0% | 95.9% | 12.7% | 92 /726 |
| Model | ||
|---|---|---|
| nl2postcond prompts | 32.0% | 65.0% |
| Our prompts | 36.6% | 70.5% |