Dissecting AI
From the paper: Priming Base Models for Agentic Post-Training: An Open Midtraining Recipe

Natural Software-Engineering Data for Long-Context Midtraining

Short-context pretraining leaves a gap before agent post-training; a 256K-context midtraining stage uses natural software-engineering artifacts to build project-level knowledge.

Read the paper ↗
The short version

What it is

  • Long-context midtraining A training stage between pretraining and post-training that gives the model room to read large software projects as connected sequences.
  • Natural software-engineering data Real project artifacts such as repository code, issue and pull-request records, code changes, and build logs form most of the training mix.

Why it matters

An agent works across files and project history, not just isolated snippets. Training on natural software work in a long context gives the model project-level exposure before final tuning.

Before we get into the details, here is the short version: put a long-context training stage between general pretraining and the final agent-focused tuning, and feed it the kinds of records software projects naturally produce. The point is to let the model encounter a project as a connected whole before it has to act on one.

  1. Context: Pretraining often presents code as individual files, and short windows may hold only a small part of a repository. An agent, by contrast, may need code defined far from the file it is changing. Midtraining gives the model long sequences in which those pieces can appear together.

  2. Timing: This stage sits between pretraining and post-training. Think of it as adding project familiarity before teaching the model the final interaction behavior. It is not a replacement for post-training; it changes what the model has seen before it gets there.

  3. Data: The canonical example is a repository surrounded by its ordinary engineering context: issue and pull-request material, code, changes, and build output. The blend is mostly natural software-engineering data, with other sources such as pretraining replay and a bounded share of agent traces. That is the important distinction: it is not all converted into chat-style examples.

What does the long window actually buy? Imagine a notebook where one page refers to a definition written much earlier. If the window is too short, the model cannot read both pages in one training example; with a long context, it can encounter the relationship. The analogy breaks because a model is predicting tokens, not consciously browsing a notebook, but it captures why context length matters.

The recipe uses a 256K context for this stage. In the 500B-token blend, issue–PR data makes up 40.8%, repository data 20%, agentic traces 10%, diff data 3%, build and CI logs 1.2%, pretraining replay 20%, and long-context data 5%. These are blend shares, so read them as a composition, not as a universal law for every run. Issue–PR records give examples of requested and submitted changes; repository data gives project context; diffs show changes; logs show system output. Together they show software work from more than one angle.

So the real question is not simply whether longer context is better. It is whether the training material uses that context to show meaningful project-level relationships. The recipe's natural artifacts are meant to do that, while a separate module covers how agent traces are curated and masked. I like this separation: project familiarity and interaction behavior are related, but they are not the same training problem.

Read the deep dive

Why People Wanted It

A model can learn to write code without learning how a real project hangs together. Pretraining often presents code as individual files, while an agent must work across a repository and its history. The question is how to give the model that project-level experience before post-training, without making the middle stage mostly resemble the later supervised examples.

The move is a dedicated midtraining stage: train at 256K context on a blend dominated by natural software-engineering artifacts. This sits between pretraining and post-training, where the model can encounter whole repositories and long code changes before final tuning. The recipe also includes a bounded share of agent traces, but the focus here is the natural-data foundation.

The Core Move

Use long-context midtraining to expose the model to naturally occurring software work at project scale, rather than relying on isolated code files alone. The central setting is a 256K context; no mathematical formula is given for this recipe.

Quiz
What is the main role of long-context midtraining in this recipe?
To expose the model to whole repositories and related software artifacts before post-training.
To shorten context so each training example contains only one file.
To replace post-training with a single pass over agent conversations.

Why Long Context Changes What the Model Can Read

Now the version for readers who want more of the machinery: context length matters because repository knowledge is distributed across files, and a long window lets training examples place those dependencies within one sequence. In short-context pretraining, only a small part of a repository may fit; at 256K, the recipe can pack whole repositories, and the model can predict code that depends on files tens of thousands of tokens earlier. This is not a claim that context alone teaches every relationship: the training sequence still has to contain useful project structure.

The timing matters too. Midtraining comes after pretraining and before post-training. Its role is to bridge the gap between general language-and-code exposure and the later agent-oriented tuning, so the model can acquire project-level knowledge in a stage built for long sequences.

Why Natural Artifacts Form the Main Blend

Here is the part that gets technical about the data mix: the blend is led by natural software-engineering records, rather than being formatted entirely as conversations. In the 500B-token blend, issue–PR data is 40.8%, repository data 20.0%, diff data 3.0%, build and CI logs 1.2%, and long-context data 5.0%; pretraining replay contributes 20.0%. Agentic traces contribute 10.0% in the table. These are shares of training tokens, not a claim that every training run must use identical proportions.

The natural sources cover different views of work: issue–PR records connect requests and code changes; repositories expose code in project context; diff data captures changes; logs show system responses; and long-context data supports the long-window stage. The model sees more than polished answers: it sees artifacts produced while software is built, changed, and debugged. The recipe keeps non-trace sources in natural formats rather than applying chat templates to everything.

Quiz
Which statement best describes the midtraining data blend?
It consists only of chat-formatted agent traces.
It is dominated by natural software-engineering artifacts, with replay, long-context data, and a smaller trace share also included.
It uses repository snapshots alone and excludes other software artifacts.

Minimal Causal Code

A plain loop makes the stage boundary visible. The model reads a long-context example, predicts its next token, and updates its weights; the next example comes from the data blend. This pseudocode shows the training idea, not the paper's full data pipeline.

for example in midtraining_stream:
    tokens = example.token_ids  # may contain repository-scale context
    logits = model(tokens[:-1])
    loss = cross_entropy(logits, tokens[1:])
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()

The key choice is what examples enter midtraining_stream: natural software-engineering artifacts make up most of the blend, with replay, long-context data, and a bounded trace share also represented.

What You Gain, and What You Lose

You gain a stage explicitly aimed at project-level exposure: the model can read whole repositories and code histories in context, rather than seeing only disconnected files. The blend also gives it varied natural evidence of software work, not just agent conversations.

You pay for a long-context training stage and for building a diverse corpus whose sources need filtering and formatting. The recipe does not make post-training unnecessary; it prepares the model before that stage. Nor does a long window guarantee that every dependency will be learned: what the model can use depends on the examples and the structure they preserve. The trace-specific masking details belong to the separate module on curated agent traces.

Core Takeaway

Long-context midtraining gives a model room to learn software as a connected project, using the natural artifacts engineers leave behind.