Source-linked AI summary

Spine: Compiling Subtask Trees into Structured Context for Long-Horizon Coding Agents

Jiahong Xiang, Kunqiu Chen, Lingming Zhang, Yuqun Zhang

arXiv:2610.37224v1cs.SEcs.AI

TL;DR

Long-horizon coding agents need context that preserves unfinished subtask information without losing the distinctions between completed and pending work or requiring delegation for every boundary. Spine represents subtasks as work scopes in a persistent tree and compiles that structure into context; its integrations improve benchmark results across Codex and Pi.

  • Problem

    Interaction histories do not explicitly represent subtask boundaries or completion, although parents need completed subtasks’ results and unfinished subtasks’ interactions to continue work.

    Source: §1 · p. 2
  • Method

    Spine records agent-declared work scopes in a persistent SpineTree and compiles it just in time, retaining unfinished interactions and replacing completed scopes’ details with results.

    Source: §1 · p. 2, §4 · p. 7, §4.1 · p. 7
  • Results

    Spine improves benchmark outcomes across Codex and Pi; on SWE-Milestone, SpineCodex Score rises 11.8% while total cost falls 32.4% versus native Codex.

    Source: §1 · p. 3, §7 · pp. 18–19
  • Takeaways & Limitations

    Spine demonstrates that coding agents can sustain complex, long-horizon engineering tasks effectively and economically by compiling context around hierarchical work structures.

    Source: §7 · p. 19

    Findings’ generalizability may depend on the tasks, models, and agent harnesses selected for evaluation.

    Source: §6 · p. 18

Abstract

from arXiv · show

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.

1 Introduction

Long-horizon coding tasks contain nested subtasks, but interaction histories do not explicitly represent their boundaries or completion. Spine uses work scopes and a persistent execution tree to align context with unfinished and completed work, and its integrations improve benchmark outcomes across Codex and Pi.

1 Introduction

  • Interaction histories lack explicit subtask boundaries and completion states, while compression can lose pending-work context and delegation adds execution and coordination overhead.Parents need completed subtasks’ results but unfinished subtasks’ interactions.Source: §1 · p. 2
  • Spine work scopes mark subtask entry, parent, and result, allowing the current agent to execute nested work inline while delegating independent subtasks.SpineTree records nesting, interactions, completion states, and returned results; just-in-time compilation retains unfinished scopes’ interactions and replaces completed scopes’ details with results.Source: §1 · pp. 2–3
  • 11.8% higher SWE-Milestone Score and 32.4% lower total cost than native Codex; ProgramBench test-pass rate improves 17.3%, and FrontierSWE Mean@5 improves on eight of ten tasks.SpineCodex achieves comparable SWE-Milestone Score to Recursive Subagent at 73.7% lower total cost; SpinePi improves SWE-Milestone Score by 9.5–17.5% and average ProgramBench test-pass rate by 4.3–8.7%.Source: §1 · p. 3
  • Spine’s Codex and Pi integrations evaluate the approach across three long-horizon benchmarks, four models, and two agent harnesses.On SWE-Milestone, SpineCodex resolves 19 of 98 milestones, compared with 14 for native Codex and 17 for Recursive Subagent.Source: §1 · p. 3

2 Motivating Example

The Nushell migration example illustrates the context challenge in nested work: a completed compilation check should return its result while the parser update remains unfinished. Spine’s explicit boundaries let the same agent resume that parent without retaining every completed interaction.

2 Motivating Example

  • A parser update can contain a targeted compilation check; the check’s result is needed to continue the update, but its intermediate interactions need not all remain.The migration also has other changes and workspace validation still pending.Source: §2 · p. 3
  • History compression can be followed by repeated rereading of already inspected files while implementation remains unfinished.In the illustrated trace, nine files are inspected, then overlapping ranges from seven files are reread twice.Source: §2 · p. 4, Figure 2 · p. 4
  • Delegating nested work adds handoffs and coordination; in the illustrated milestone, the parent makes twelve wait calls and fourteen child-agent creation attempts.Three creation attempts are blocked by the thread limit, and sequential dependencies can leave the parent waiting for results.Source: §2 · pp. 4–5
  • With explicit boundaries, the same agent can replace a completed check’s interactions with its result while retaining the unfinished parser context.After the parser update completes, its result returns to the migration while other changes and validation remain pending.Source: §2 · p. 5, Figure 3 · p. 5

3 Background and Related Work

Long-horizon coding agents repeatedly use tools and model calls to complete interdependent development steps, often with nested subtasks. Related work manages context through selection, compression, or delegation, each with distinct tradeoffs for preserving work state and limiting overhead.

3.1 Long-Horizon Coding Agents and Tasks

  • Long-horizon agents perform interdependent development steps, with nested subtasks that return results to unfinished parent tasks across a sequence of model and tool interactions.The harness records these interactions chronologically, but that order alone does not mark subtask boundaries or what unfinished parents need.Source: §3.1 · pp. 5–6

3.2 Context-Management Approaches

  • Context-management approaches select or condense history, while HiAgent and Context Folding use completed subgoals or branches to replace detailed interactions with summaries or results.Without explicit work structure, models must reconstruct relations, completion, and pending work; reported problems include repeated reading and searching, difficulty recovering progress, and premature completion.Source: §3.2 · pp. 6–7

3.3 Recursive Subagent Systems

  • Recursive subagent systems isolate child work in separate contexts, but finer task boundaries require more agent executions and communication.Different context prefixes can also prevent ordinary prefix caching from reusing shared content’s computation.Source: §3.3 · p. 7

4 Spine Approach

Spine aligns model context with subtask nesting and completion through explicit work scopes, a persistent SpineTree, and just-in-time context compilation. It supports inline work and delegation while retaining unfinished interactions and replacing completed-scope details with results.

4 Spine Approach

  • Spine aligns context with subtask nesting and completion by combining explicit boundaries, inline or delegated execution, and just-in-time compilation.The runtime resumes parent tasks with submitted results while preserving prefix caches.Source: §4 · p. 7

4.1 Work Scopes and SpineTree

  • Work scopes mark agent-declared subtasks, while SpineTree records their ordered interactions, active path, completed branches, and returned results.Completed inline scopes retain their contents in the tree even when later context uses only their results.Source: §4.1 · pp. 7–8

4.2 Interface Operations

  • Open and Close let the same agent execute nested scopes inline; Next opens a sibling, while Spawn delegates independent work in parallel.On completion, a child’s result returns to the parent’s model context.Source: §4.2 · p. 9

4.3 Just-In-Time Context Compilation

  • Before each model call, the backend assembles context from work records, retaining active work and substituting completed-scope results for their detailed interactions.The illustrative diagnostic check returns its result to the parent while its test details remain in SpineTree.Source: §4.3 · p. 9, §4.3.2 · p. 11

4.3.1 Compilation frontend.

  • The frontend incrementally parses terminal streams into an ordered tree, retaining unmatched Open markers so work can continue across turns.Its LR(0) parser reduces a matching Open, body, and Close into a completed branch.Source: §4.3.1 · p. 10

4.3.2 Compilation backend.

  • The backend replaces a completed inline scope’s projection with its result while preserving the preceding context prefix for potential KV-cache reuse.Reuse requires identical token serialization and compatible cache settings, and depends on cache availability.Source: §4.3.2 · p. 11

5 Evaluation

The evaluation covers repository evolution, whole-program reconstruction, and open-ended engineering, using each benchmark’s official metrics. It also tracks monetary cost and token usage.

5.1 Benchmarks and Evaluation Metrics

  • SWE-Milestone evaluates dependent milestones in persistent repositories while preserving existing behavior.Its official Score (%) is the harmonic mean of test recall and precision; # Resolved counts milestones passing all required tests.Source: §5.1 · pp. 11–12
  • ProgramBench tests whether agents can reconstruct programs from documentation and an execute-only reference implementation.It reports # Resolved, # Almost (at least 95% of tests, including fully resolved tasks), and Avg. pass (%).Source: §5.1 · pp. 11–12
  • FrontierSWE measures progress on open-ended engineering tasks, reporting Mean@5 and Best@5 scores over five trials per task.Its tasks include building a PostgreSQL-compatible server backed by SQLite, implementing Git in Zig, and optimizing libswscale.Source: §5.1 · p. 12
  • The evaluation also reports monetary cost, total token usage, and average input tokens per main-model request.Table 2 summarizes the evaluated tasks and metrics.Source: §5.1 · pp. 11–12, Table 2 · p. 11

5.2 Evaluation Harness Systems and Models

The study integrates Spine with Codex and Pi, compares context-management baselines within Codex, and evaluates several models across the two harnesses.

5.2 Evaluation Harness Systems and Models

  • SpineCodex connects Spine to Codex’s native session lifecycle, while SpinePi loads Spine through Pi’s extension interface.The systems support work scopes and context provision within their respective harnesses.Source: §5.2 · p. 12
  • Codex comparisons include native Codex, AgentDiet, Context Folding, and Recursive Subagent as context-management baselines.The baselines cover compaction, trajectory reduction, context folding, and recursive delegation, and all run within Codex.Source: §5.2 · p. 12
  • Codex experiments use GPT-5.6 Sol and Grok 4.6, while Pi experiments use Gemini 3.8 Flash and Qwen 3.8 27B.Qwen 3.8 27B runs locally with vLLM on NVIDIA A100 GPUs; the other models are accessed through provider APIs.Source: §5.2 · p. 12

5.3 Evaluation Setup

Comparisons use matched models, harnesses, task subsets, and budgets in isolated containers. Benchmark sampling and runtime limits vary by benchmark.

5.3 Evaluation Setup

  • Each comparison uses the same model, harness, task subset, and budget across approaches, with runs in isolated containers.The default benchmark is SWE-Milestone and the default model is GPT-5.6 Sol unless otherwise noted.Source: §5.3 · p. 13
  • ProgramBench evaluation samples 50 of 200 tasks and retains the benchmark’s six-hour and 1,000-step limits.SWE-Milestone follows its official protocol, resuming runs until all milestones are submitted for evaluation.Source: §5.3 · p. 13
  • FrontierSWE evaluation covers ten available V1 tasks, with five trials per task and a 20-hour budget per trial.Seven of its 17 tasks were unavailable in the environment, including tasks requiring an H100 GPU or external Tinker API and network access.Source: §5.3 · p. 13

5.4 Research Questions

The evaluation asks whether Spine is effective with Codex, generalizes to Pi, and changes how agents organize work and carry context forward.

5.4 Research Questions

  • RQ1 compares Codex and SpineCodex across three benchmarks, then compares SpineCodex with other context-management approaches on SWE-Milestone.Source: §5.4 · p. 13
  • RQ2 compares Pi and SpinePi on SWE-Milestone and ProgramBench using Gemini 3.8 Flash and Qwen 3.8 27B.Source: §5.4 · p. 13
  • RQ3 analyzes scope use, input changes, an execution trace, and ablations of subtask nesting and boundary maintenance.Source: §5.4 · p. 13

5.5 Result Analysis

Spine improves coding-agent effectiveness across repository evolution, whole-program reconstruction, and open-ended engineering, with lower cost in most evaluated settings. Its results also show how nested scopes affect context use and how the approach generalizes to Pi.

5.5.1 RQ1: Effectiveness of Spine.

  • 11.8% higher SWE-Milestone Score and 17.3% higher ProgramBench average test-pass rate with GPT-5.6 Sol; Mean@5 improves on eight of ten FrontierSWE tasks.For SWE-Milestone, SpineCodex resolves 19 milestones versus Codex’s 14; ProgramBench with GPT-5.6 Sol is the cost exception, with a 5.4% increase.Source: §5.5.1 · p. 13, Table 3 · p. 14, Table 4 · p. 14
  • SpineCodex improves effectiveness across all three benchmarks while reducing monetary cost by 6.7–37.9% in five of six evaluated benchmark–model settings.The SWE-Milestone comparison covers SpineCodex and Codex; FrontierSWE results are reported per task.Source: §5.5.1 · p. 13, Table 3 · p. 14, Table 4 · p. 14
  • On SWE-Milestone with GPT-5.6 Sol, SpineCodex achieves the highest Score among five approaches at the lowest cost; Recursive Subagent has a comparable Score but costs more.AgentDiet rereads source after reducing history, while Recursive Subagent assigns every boundary to delegation; SpineCodex resolves 19 milestones for $460.77 versus 17 for $1,749.73.Source: §5.5.1 · pp. 14–15, Table 5 · p. 15, Figure 7 · p. 15

5.5.2 RQ2: Generalizability to Pi.

  • SpinePi improves SWE-Milestone Score by 9.5–17.5% and ProgramBench average test-pass rate by 4.3–8.7% over native Pi with Gemini 3.8 Flash and Qwen 3.8 27B.With Gemini 3.8 Flash, average input tokens fall 67.8% on SWE-Milestone and cost falls 45.4%; Qwen’s SWE-Milestone token total instead increases while resolving six additional milestones.Source: §5.5.2 · pp. 15–16, Table 6 · p. 16

5.5.3 RQ3: Behavioral Characteristics of Spine.

  • 72.6% of scoped requests occur below depth one, and post-return inputs are shorter after 223 of 224 Close calls and 77 of 80 Next calls.Median input decreases are 23,045 tokens after Close and 35,627 after Next, consistent with replacing completed local interactions with returned results.Source: §5.5.3 · p. 16, Figure 8 · p. 17
  • In the Nushell case study, input falls 70.8% at the language/parser return while pending subtasks remain in context.The agent closes an inner scope after targeted tests pass, then continues the unfinished local-variable work; the outer return preserves PipelineData migration and workspace validation as pending work.Source: §5.5.3 · pp. 16–17, Figure 9 · p. 17
  • Across three projects, SpineCodex improves Score by 7.7–27.3% over both ablations; removing boundary cues raises input by 64–97% and cost by 30–42%.Limiting scopes to depth one also raises average input per request from 59.8K–78.1K to 82.8K–99.5K.Source: §5.5.3 · p. 18, Table 7 · p. 18

6 Threats to Validity

The evaluation addresses internal, external, and construct validity threats through controlled comparisons, broader benchmark and system coverage, and multiple outcome measures.

Internal validity

  • Comparisons may be affected by differing experimental settings and implementation choices; the authors align model, harness, task set, and budget within comparisons and use isolated containers.Ablations are used to isolate scope nesting and explicit boundary representation.Source: §6 · p. 18

External validity

  • Findings may depend on the selected tasks, models, and harnesses, despite evaluation across three benchmarks and integrations with Codex and Pi using multiple models.The model set includes an open-weight model.Source: §6 · p. 18

Construct validity

  • A single metric may not capture both task completion and execution cost, so the study uses benchmark-native measures alongside token use and monetary cost.Source: §6 · p. 18

7 Conclusion

Spine lets agents declare subtask boundaries and constructs context around nested work, separating those boundaries from delegation. Evaluations report gains across coding benchmarks and integrations, with lower costs in the stated comparisons.

  • Spine enables explicit subtask boundaries and uses SpineTree to retain unfinished interactions while replacing completed subtasks’ details with submitted results.The interface separates subtask boundaries from delegation.Source: §7 · p. 18
  • With GPT-5.6 Sol, SpineCodex improves SWE-Milestone Score by 11.8% while reducing total cost by 32.4% versus native Codex.The Pi integration also improves SWE-Milestone Score and ProgramBench average test-pass rate under both evaluated models, including an open-weight model.Source: §7 · pp. 18–19
  • The reported results support Spine’s use for sustaining long-horizon engineering tasks effectively and economically in the evaluated settings.Source: §7 · p. 19

Data Availability

SpineCodex and SpinePi are available as open-source software and published on npm.

  • SpineCodex and SpinePi are open source on GitHub and published on npm for installation.The passage provides separate npm installation commands for each.Source: Data Availability · p. 19
Loading 2610.37224v1…