Long-horizon coding tasks contain nested subtasks. Typically, agents record interactions sequentially into a growing history, causing context inflation and performance degradation. Compressing or trimming the history without explicit subtask boundaries can discard information needed by unfinished subtasks. Conversely, recursive subagent delegation isolates completed subtasks through child agents by assigning every subtask boundary to delegation, which conflates subtask granularity with executing agent choice, adding execution and coordination overhead. We introduce Spine, an interface and runtime that align model context with subtask nesting and completion. An agent declares explicit subtask boundaries through work scopes, allowing the same agent to execute nested subtasks inline while reserving delegation for independent parallel tasks. The runtime organizes execution in SpineTree, a persistent tree recording subtask relations, local interactions, completion states, and returned results. Before each model call, it compiles the tree into model context just in time, retaining unfinished subtasks' interactions and replacing completed subtasks' details with their results, while preserving prefix-cache reuse. We integrate Spine into Codex to build SpineCodex. With GPT-5.6 Sol, compared with native Codex, SpineCodex improves SWE-Milestone Score by 11.8% while reducing total cost by 32.4%, improves the average ProgramBench test-pass rate by 17.3%, and improves Mean@5 on eight of the ten evaluated FrontierSWE tasks. On SWE-Milestone, it also achieves a comparable Score to Recursive Subagent at 73.7% lower total cost. We also integrate Spine into Pi through a reusable software package: with Gemini 3.8 Flash and Qwen 3.8 27B, it improves SWE-Milestone Score by 9.5-17.5% and the average ProgramBench test-pass rate by 4.3-8.7% compared with native Pi.
Figures & tables
Figure 1. Nested work within the Nushell migration. An illustrative decomposition of the migration contains a parser update with a nested compilation check, alongside other changes and workspace validation.
Figure 2. History compression and recursive delegation during the Nushell migration. The history-compression sequence inspects nine source files, reduces an inspection slice, then rereads overlapping ranges from seven of those files in each of two later responses. The recursive-delegation panel shows nested child executions and parent calls in one migration milestone: fourteen creation attempts, three blocked by the thread limit, eight status queries, twelve wait calls, eight messages, and six interrupts.
Figure 3. Returning nested results within the same agent. The compilation check completes inside the parser update. Its result replaces its details in subsequent context. The same agent continues the parser update, whose later result returns to the migration with other work still pending.
Figure 4. The coding-agent execution loop.
Figure 5. Overview of Spine . The Agent/Harness sends a turn stream and Open, Close, Next, and Spawn commands to the Compilation Frontend. Its SpineTree contains an open parent, a closed branch with retained task and child records plus a returned result, and an open child. The Compilation Backend maps these to parent continuation, returned result, and child instantiation, respectively, following the preceding context prefix. The resulting linear context goes to the Model API for the next turn. A dashed return path connects that turn to the Agent/Harness.
Command/event
Terminal stream ω
Work semantics
No command
P⋅O
Continue current work.
Open (d)
P⋅[Open(d)]⋅O
Enter inline child.
Close (μ)
P⋅[Close(μ)]⋅O
Complete child; return result.
Next (μ,d)
P⋅[Close(μ),Open(d)]⋅O
Close child; open sibling.
Spawn (tasks)
P⋅O⋅[SpawnNode(μi)]i=0k−1
Delegate tasks; collect results.
Table 1. Lifecycle commands and terminal streams. P and O encode preceding and current-turn messages; “ ⋅ ” denotes list concatenation; delegated results follow task order.
Figure 6. Context compilation for an illustrative diagnostic check. Three panels follow a parser update. The agent opens the parent work, records message m1, opens a diagnostic check, records a test call m2 and output m3, and closes the check with result mu before continuing with parent message m4. SpineTree retains m2 and m3 in the completed branch body F alongside mu. The next linear input contains the parent's task and identity D(p), m1, mu, and m4 in order.
Benchmark
Scope
Metrics
Target
SWE-Milestone ( Deng et al., 2026 )
7 tasks (98 milestones total)
Score (%) # Resolved
Continuous repository evolution
ProgramBench ( Yang et al., 2026a )
50 tasks randomly sampled from 200
# Resolved / # Almost Avg. pass (%)
Whole-program reconstruction
FrontierSWE ( Chu et al., 2026 )
10 tasks 5 trials/task
Mean@5 Best@5
Open-ended engineering
Table 2. Evaluation benchmarks and metrics.
SWE-Milestone
Model
Agent
Score (%)
# Resolved
Total tokens
Avg. input tokens/req.
Cost ($)
GPT-5.6 Sol
Codex
38.1
14/98
1,072.4M
131.2K
681.22
SpineCodex
42.6
19/98
640.5M
72.3K
460.77
Grok 4.6
Codex
35.5
12/98
713.8M
120.0K
505.57
SpineCodex
40.4
14/98
444.2M
60.3K
314.20
Table 3. Performance of SpineCodex and Codex on SWE-Milestone and ProgramBench.
GPT-5.6 Sol
Grok 4.6
Task
Codex
SpineCodex
Codex
SpineCodex
Mean@5
Best@5
Mean@5
Best@5
Mean@5
Best@5
Mean@5
Best@5
cranelift-codegen-opt
0
0
0
0
0.0164
0.0822
0
0
dart-style-haskell
0.1533
0.4029
0.4019
0.8136
0.0876
0.1595
0.4074
0.8505
dependent-type-checker
1.8420
3.6100
2.4750
3.7400
0
0
0
0
ffmpeg-swscale-rewrite
0.5472
1.6400
0.9488
1.7200
0.2140
0.6280
0.3910
0.6550
Table 4. Per-task performance of SpineCodex and Codex on FrontierSWE.
Agent
Score (%)
# Resolved
Total tokens
Avg. input tokens/req.
Cost ($)
Codex
38.1
14/98
1,072.4M
131.2K
681.22
AgentDiet
36.5
12/98
959.2M + 76.0M *
92.8K
1,057.08 + 41.44 *
Context Folding
37.1
13/98
765.2M
87.3K
596.25
Recursive Subagent
42.4
17/98
2,139.9M
65.3K
1,749.73
SpineCodex
42.6
19/98
640.5M
72.3K
460.77
Table 5. Comparison with context-management approaches on SWE-Milestone using GPT-5.6 Sol.
Figure 7. (a) Repeated source inspection with AgentDiet ; (b) delegation with Recursive Subagent .
SWE-Milestone
Model
Agent
Score (%)
# Resolved
Total tokens
Avg. input tokens/req.
Cost ($)
Gemini 3.8 Flash
Pi
35.8
13/98
6,950.27M
511.06K
644.21
SpinePi
39.2
15/98
3,126.11M
164.31K
351.55
Qwen 3.8 27B
Pi
30.9
8/98
1,996.97M
132.46K
—
SpinePi
36.3
14/98
2,252.80M
148.73K
—
Table 6. Performance of SpinePi and Pi on SWE-Milestone and ProgramBench.
Figure 8. Runtime behavior of SpineCodex : (a) lifecycle calls; (b) input-token changes at returns. Accepted Open, Close, Next, and Spawn calls across seven projects, and distributions of input-token changes at return boundaries.
Figure 9. Nested returns during the Nushell migration with SpineCodex . An inner scope returns to language/parser work, which later returns to the migration; each parent receives a result and continues pending work.
Configuration
Score (%)
Resolved
Tokens
Avg. input
Cost
Navidrome, 9 milestones
SpineCodex
36.4
3/9
60.46M
71.2K
$42.48
Depth 1
28.6
2.33/9
71.50M
99.5K
$52.60
No boundary maintenance
29.0
2.33/9
67.40M
124.2K
$60.50
ripgrep, 11 milestones
SpineCodex
72.4
5.667/11
48.22M
59.8K
$34.67
Table 7. Ablation of nesting and boundary maintenance on three SWE-Milestone tasks.