Manuscript Offprint

arXiv:2610.37224

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

Jiahong Xiang, Kunqiu Chen, Lingming Zhang, Yuqun Zhang

JIAHONG XIANG, Southern University of Science and Technology, China

KUNQIU CHEN, Southern University of Science and Technology, China

LINGMING ZHANG, University of Illinois at Urbana-Champaign, USA

YUQUN ZHANG, Southern University of Science and Technology, China

Long-horizon coding tasks contain nested subtasks. Typically, agents record interactions sequentially into a growing history as model context, causing severe context inflation and performance degradation. One group of existing context-management approaches compresses or trims the history without explicit subtask boundaries, such that context reduction can discard information needed by unfinished subtasks, leading to repeated exploration and disrupted task progress. On the other hand, recursive subagent delegation isolates completed subtasks through child agents via assigning every subtask boundary to delegation, which conflates subtask granularity with executing agent choice, adding execution and coordination overhead. This raises a question: how can model context align with subtask nesting and completion without incurring the high overhead of additional agents? To answer this question, we introduce SPINE, an interface and runtime that align model context with subtask nesting and completion in a just-in-time manner. Specifically, an agent declares explicit subtask boundaries through work scopes, allowing the same agent to execute nested subtasks inline without multi-agent overhead, while reserving delegation for independent parallel tasks. The runtime organizes execution in SpineTree, a persistent tree that serves as the structural spine recording subtask relations, local interactions, completion states, and returned results. Before each model call, the runtime compiles the tree into model context just in time, retaining unfinished subtasks' interactions and replacing completed subtasks' details with their submitted results, while preserving prefix-cache reuse.

We integrate SPINE into Codex, OpenAI's popular coding-agent harness, to build SPINECODEX. We evaluate it on three widely-adopted long-horizon benchmarks: SWE-Milestone for repository evolution, ProgramBench for whole-program reconstruction, and FrontierSWE for open-ended engineering. With GPT-5.6 Sol, SPINECODEX improves SWE-Milestone Score by 11.8% while reducing total cost by 32.4%, compared with native Codex. It also achieves a comparable Score to RECURSIVE SUBAGENT at 73.7% lower total cost. With the same model, it improves the average ProgramBench test-pass rate by 17.3% compared with native Codex and improves Mean@5, i.e., the mean score over five trials per task, on eight of the ten evaluated FrontierSWE tasks. To evaluate generalizability, we integrate SPINE into Pi, a popular open-source coding-agent harness with an extensible architecture, through a reusable software package. With Gemini 3.8 Flash and the open-weight Qwen 3.8 27B, this integration 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.

CCS Concepts: • Software and its engineering → Automatic programming; • Computing methodologies → Artificial intelligence.

Additional Key Words and Phrases: Coding agents, context management, large language models

1 Introduction

Coding agents are increasingly used for complex, long-horizon software-engineering tasks [3, 22]. For example, in May 2026, roughly one in four sampled active individual users of Codex, OpenAI's coding agent, had submitted a request estimated to require at least eight hours of human work [22]. These tasks contain nested subtasks, i.e., subtasks themselves containing further subtasks. When a subtask completes, the agent uses its result to resume its parent task, i.e., the task that directly

Authors' Contact Information: Jiahong Xiang, Southern University of Science and Technology, Shenzhen, China, xiangjh2022@mail.sustech.edu.cn; Kunqiu Chen, Southern University of Science and Technology, Shenzhen, China, 11911626@mail.sustech.edu.cn; Lingming Zhang, University of Illinois at Urbana-Champaign, Urbana, IL, USA, lingming@illinois.edu; Yuqun Zhang, Southern University of Science and Technology, Shenzhen, China, zhangyq@sustech.edu.cn.

Jiahong Xiang, Kunqiu Chen, Lingming Zhang, and Yuqun Zhang

contains it. To complete such tasks, a coding agent iteratively reasons, invokes tools, and uses the resulting observations to guide subsequent interactions [53]. The agent harness, i.e., the software that runs tools and prepares model inputs, encapsulates these interactions into subsequent model calls as a growing interaction history [45], which forms part of the model context as the input information supplied to each model call. However, simply recording interactions in turn as history is impractical, since it could easily inflate the context and reduce agent effectiveness, making it essential to select which interactions to encapsulate. Intuitively, for completed subtasks, only their returned results are likely needed by their parent task rather than detailed original interactions, which are in fact essential for proceeding with unfinished subtasks [49].

Existing approaches manage context by compressing or trimming the interaction history, or by assigning subtasks to child agents. History compression and trimming reduce the information encapsulated into later calls. For instance, AGENTDIET removes redundant or expired content [49], while AGENTFOLD lets the agent summarize selected parts of the history at different granular levels [55]. CONTEXT FOLDING uses a plan–branch–return workflow trained with FOLDGRPO, in which the returned result of a completed branch replaces its intermediate interactions [43]. However, reducing interaction history does not by itself maintain subtask relations, completion status, or where unfinished work should resume. When this information must be recovered from reduced context, the model may lose track of progress, repeat exploration [13], or declare completion while work remains unfinished [56]. These failures add execution cost and disrupt continued progress.

Recursive subagent delegation instead assigns subtasks to child agents with separate contexts, which can in turn delegate further subtasks and return their results. For example, RECURSIVE AGENT HARNESSES gives each child a complete tool-using harness with its own workspace and context [28]. These calls represent subtask nesting and isolate completed work through returned results, but using them to establish every subtask boundary forces delegation and adds execution and coordination overhead, even when the current agent could perform the work itself. Studies of multi-agent systems show that communication inflation and redundant messages can directly degrade task performance [58, 62], while divergent context prefixes force shared information to be repeatedly reprocessed without KV-cache reuse [54]. Crucially, whether a subtask is delegated to another agent or executed locally by the current agent, the agent still makes decisions about when the subtask starts, completes, and returns. However, existing interaction histories lack an explicit representation of these boundaries and completion states.

To summarize, these observations lead to three issues in context management: (1) the lack of an explicit representation of subtask boundaries and completion status in the interaction history; (2) the lack of separation between subtask granularity and executing agent choice; and (3) the lack of a history representation distinguishing between completed and unfinished subtasks for parent tasks.

This raises a question: how can model context align with subtask nesting and completion without incurring the high overhead of additional agents? Ideally, the same agent should be able to complete a subtask and resume its parent task with the result, while retaining information needed by other unfinished subtasks with explicit subtask boundaries.

To answer this question, we introduce SPINE, an interface and runtime that align model context with subtask nesting and completion while supporting both local execution and delegation in a just-in-time manner. Specifically, SPINE addresses the aforementioned issues through three key designs. (1) To provide an explicit representation of subtask boundaries and completion status, the agent declares a work scope, i.e., a subtask with an explicit entry, a parent task, and a result submitted on completion. (2) To separate subtask granularity from executing agent choice, a work scope can span multiple model calls and tool interactions, where the current agent can open nested scopes within it, complete each scope by submitting a result, and resume the parent task.

locally, while independent subtasks can be delegated to other agents for parallel execution so that subtask boundaries do not determine which agent executes the work. (3) To distinguish completed subtasks and unfinished subtasks for parent tasks, the runtime maintains a persistent execution tree, namely SpineTree, and compiles it into model context just in time before each model call, retaining unfinished work scopes' interactions and replacing completed scopes' details with their submitted results. More specifically, SpineTree serves as the structural spine recording the current agent's scopes, their nesting, interactions, and completion status, together with submitted results and results returned by delegated agents. Completing a work scope therefore both resumes its parent with the submitted result and changes the context supplied to the next call. Notably, the detailed interactions remain preserved in SpineTree, while the unchanged context preceding the scope remains eligible for prefix-cache reuse.

We integrate SPINE into the agent harness of Codex, OpenAI's widely used coding product [30, 31], to build SPINECODEX. We evaluate effectiveness and cost using GPT-5.6 Sol [33] and Grok 4.6 [48] on three widely-adopted long-horizon coding benchmarks: SWE-Milestone [13], ProgramBench [52], and FrontierSWE [6]. On SWE-Milestone with GPT-5.6 Sol, SPINECODEX improves Score by 11.8%, 16.7%, and 14.8% while reducing total cost by 32.4%, 58.1%, and 22.7%, compared with native Codex, AGENTDIET, and CONTEXT FOLDING, respectively. It also achieves a comparable Score to RECURSIVE SUBAGENT at 73.7% lower total cost. With the same model, it improves the average ProgramBench test-pass rate by 17.3% compared with native Codex, and FrontierSWE's Mean@5, i.e., the mean score over five trials per task, on eight of ten evaluated tasks. To evaluate generalizability, we integrate SPINE as a plugin into Pi [15], a popular open-source coding-agent harness with an extensible architecture [14], through its official extension interface [16]. Using Gemini 3.8 Flash [20] and the open-weight Qwen 3.8 27B [41], this integration 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.

This paper makes the following contributions:

• SPINE. We propose an interface that aligns model context with subtask nesting and completion while supporting both local execution and delegation for agents. It combines explicit subtask declarations with context construction from a persistent execution tree, namely SpineTree, allowing the current agent to execute nested subtasks with a structurally aligned interaction history.

• System Implementation. We integrate SPINE with the existing mechanisms of Codex and Pi, yielding SPINECODEX and a loadable SPINEPi plugin, respectively. The implementation involves approximately 17K lines of Rust code and 9K lines of TypeScript/Rust code, which are ready to use out of the box.

• Extensive Study. We conduct an extensive study across three long-horizon coding benchmarks, four models, and two agent harnesses. On SWE-Milestone with GPT-5.6 Sol, SPINECODEX resolves 19 of 98 milestones, compared with 14 for native Codex and 17 for RECURSIVE SUBAGENT, at 32.4% and 73.7% lower total cost, respectively. In the Pi integration, SPINE improves SWE-Milestone Score by 9.5–17.5% and the average ProgramBench test-pass rate by 4.3–8.7% across the evaluated models.

References (15)