Summary: Quality, Not Just Outcome: A Structural Scoring Framework for Selecting Coding-Agent Trajectories for Supervised Fine-Tuning

Summary (Overview)

  • Core contribution: The paper introduces TQS (Trajectory Quality Score), a structural scoring framework for coding-agent trajectories that evaluates process quality rather than just final outcome, operating directly on trajectory structure in linear time without requiring LLM judges.
  • Key finding: Models trained on top-ranked trajectories (by TQS) achieve 27.6 pass@1 on SWE-Bench Verified, outperforming random selection (24.8) by 2.8 points and bottom-ranked selection (21.8) by 5.8 points, demonstrating that successful trajectories vary substantially in their value as supervision.
  • Framework design: TQS characterizes trajectory quality through three structural dimensions—information focus, intent–action alignment, and policy dynamics—operationalized via seven efficient, interpretable measures computed from event logs alone.
  • Scalability advantage: TQS processes trajectories at ~43 ms per trajectory (87.5 trajectories/second with 4 workers), making corpus-scale selection practical (~49 minutes for 258K trajectories at ~0.1–0.1–0.2 in cloud CPU costs), versus ~$18.6K estimated for GPT-4o judging on the same corpus.
  • Validation: TQS achieves 0.732 concordance in distinguishing successful from failed trajectories, 78.7% agreement with human evaluators and 75.4% with Claude Sonnet-5 on ordering successful trajectories, and monotonic resolution rate (54.1%→86.9%) across TQS deciles.

Introduction and Theoretical Foundation

Background and Motivation

Coding agents that interact with sandboxed environments to inspect repositories, execute tests, and edit files have achieved strong performance on software engineering benchmarks like SWE-Bench Verified. A critical ingredient is trajectory supervision: training on multi-turn agent demonstrations consisting of reasoning traces, tool calls, tool observations, and final patches. For medium-scale open-weight models, the common practice is to collect trajectories from more capable teacher agents and retain those whose final patches pass the benchmark test suite.

The Core Problem

The paper identifies a fundamental limitation of outcome-level filtering:

"Outcome-level correctness does not necessarily imply process-level quality."

Among successful trajectories, behavioral patterns vary substantially:

  • Some localize bugs quickly, maintain coherent search scope, and transition efficiently from exploration to modification
  • Others repeatedly inspect the same files, interrupt stalled shell commands, or postpone meaningful edits until late in the interaction budget

These differences matter because trajectory-level SFT exposes the student to the full interaction process. Inefficient or unstable interaction patterns become part of the training signal.

Theoretical Foundation: Structured Convergence

The paper proposes that high-quality trajectories exhibit structured convergence: as an agent approaches a solution, a strong trajectory becomes increasingly organized around the relevant fix. This organization manifests at three levels:

  1. Information focus: The agent focuses observations and file operations on task-relevant evidence
  2. Intent–action alignment: Stated intent (thoughts) aligns with tool actions
  3. Policy dynamics: The interaction policy moves from broad exploration toward productive edit, test, and recovery behavior

Limitations of Existing Approaches

  • Perplexity-style scores are confounded by length and tokenization
  • LLM-based judges are costly at scale (hundreds of thousands of trajectories, billions of tokens)
  • Neither approach characterizes how effectively an agent organizes its search process over time

Methodology

Trajectory Representation

A trajectory τ=(s0,s1,…,sn−1)\tau = (s_0, s_1, \ldots, s_{n-1}) is a sequence of nn steps, where each step is:

st=(at,mt,ot,Ft,εt),s_t = (a_t, m_t, o_t, F_t, \varepsilon_t),

where at∈Aa_t \in \mathcal{A} is an action type (think, read_file, write_file, execute_bash, search, submit, other); mtm_t is the free-text thought; oto_t is the tool observation; Ft⊆FF_t \subseteq \mathcal{F} is the set of file paths touched; and εt∈{0,1}\varepsilon_t \in \{0,1\} indicates whether oto_t matches a predefined error pattern.

The Seven TQS Components

(A1) Observation Entropy Collapse (OEC)

Character-level Shannon entropy of observations, measuring whether observations concentrate around a smaller body of evidence:

H(ot)=−∑cpt(c)log⁡2pt(c),H(o_t) = -\sum_c p_t(c) \log_2 p_t(c), sOEC=clamp⁡(1−min⁡trt,0,1),s_{\mathrm{OEC}} = \operatorname{clamp}\left(1 - \min_t r_t, 0, 1\right),

where rt=H~t/Hˉopenr_t = \tilde{H}_t / \bar{H}_{\mathrm{open}} is the ratio of the three-step moving average entropy to the mean entropy of the first observations.

(A2) Progressive Scope Narrowing (PSN)

Kendall's τK\tau_K between the distinct files touched in a five-step window and the step index over the second half of the trajectory:

scopet=∣⋃k=max⁡(0,t−4)tFk∣,\text{scope}_t = \left|\bigcup_{k=\max(0,t-4)}^{t} F_k\right|, sPSN=clamp(1−τK2,0,1).s_{\text{PSN}} = \text{clamp}\left(\frac{1-\tau_K}{2}, 0, 1\right).

A shrinking active file set gives negative τK\tau_K and a higher score.

(B1) Intent–Action Consistency (IAC)

A lexicon-based parser maps thoughts to coarse intended actions, measuring consistency between stated intent and actual action:

sIAC=1∣I∣∑t∈I1[a^t=at],s_{\mathrm{IAC}} = \frac{1}{|\mathcal{I}|} \sum_{t \in \mathcal{I}} \mathbf{1}[\hat{a}_t = a_t],

where I\mathcal{I} is the set of steps where the intended action is defined.

(C1) Tool Transition Entropy (TTE)

Normalized entropy of adjacent action transitions, penalizing long single-tool loops:

sTTE=−∑i,jp(i→j)log⁡2p(i→j)log⁡249.s_{\mathrm{TTE}} = \frac{-\sum_{i,j} p(i \rightarrow j) \log_2 p(i \rightarrow j)}{\log_2 49}.

(C2) Solution Commitment Point (SCP)

Gaussian-shaped score favoring the first substantive edit (error-free write_file) occurring between 20% and 50% of the trajectory:

sSCP={0,no substantive edit;exp⁡(−d(u)2/(2σ2)),otherwise,s_{\mathrm{SCP}} = \begin{cases} 0, & \text{no substantive edit;} \\ \exp\left(-d(u)^2/(2\sigma^2)\right), & \text{otherwise,} \end{cases}

where u=t∗/nu = t^*/n is the relative time of the first substantive edit, d(u)=max⁡(0,0.2−u,u−0.5)d(u) = \max(0, 0.2-u, u-0.5), and σ=0.2\sigma = 0.2.

(C3) Post-Error Diversity (PED)

Measures adaptation after errors by combining action-type change with Jaccard distance between successive file sets:

dt=12(1[at+1≠at]+Jacc(Ft+1,Ft)),d_t = \frac{1}{2}\left(\mathbf{1}[a_{t+1} \neq a_t] + \text{Jacc}(F_{t+1}, F_t)\right), sPED=1∣Eτ∣∑t∈Eτdt.s_{\mathrm{PED}} = \frac{1}{|\mathcal{E}_\tau|} \sum_{t \in \mathcal{E}_\tau} d_t.

(D1) Dirty Pattern Indicator (DPI)

Guardrail capturing categorical failures (early stopping, no substantive edit, repeated shell-command loops, repeated errors):

p=0.41[early]+0.41[no edit]+min⁡(0.3,3 lp)+min⁡(0.3,0.6 er),p = 0.4\mathbf{1}[\text{early}] + 0.4\mathbf{1}[\text{no edit}] + \min(0.3, 3\,\mathrm{lp}) + \min(0.3, 0.6\,\mathrm{er}), sDPI=1−min⁡(1,p).s_{\mathrm{DPI}} = 1 - \min(1, p).

Aggregation

Fixed, hand-set weights: wOEC=0.30w_{\mathrm{OEC}} = 0.30, wIAC=0.25w_{\mathrm{IAC}} = 0.25, wPSN=wTTE=wPED=wDPI=0.10w_{\mathrm{PSN}} = w_{\mathrm{TTE}} = w_{\mathrm{PED}} = w_{\mathrm{DPI}} = 0.10, and wSCP=0.05w_{\mathrm{SCP}} = 0.05. The final TQS is:

TQS(τ)=∑c∈C∗(τ)wc⋅sc(τ)∑c∈C∗(τ)wc,(1)\text{TQS}(\tau) = \frac{\sum_{c \in \mathcal{C}^*(\tau)} w_c \cdot s_c(\tau)}{\sum_{c \in \mathcal{C}^*(\tau)} w_c}, \tag{1}

where C∗(τ)\mathcal{C}^*(\tau) is the set of components defined on τ\tau. Trajectories with n<3n < 3 or component coverage below 4/74/7 are excluded.

Component Admission Protocol

Each component must pass three criteria:

  1. Concordance > 0.5: Rate at which the measure assigns a higher score to a passing trajectory than a paired failing trajectory from the same task
  2. Length correlation ∣ρ∣<0.25|\rho| < 0.25: Absolute Spearman correlation with trajectory length
  3. Behavioral diversity preservation: No mode collapse in selected subsets

Empirical Validation / Results

Discriminant Validity

| Measure | Conc. | ∣ρ∣|\rho| | Outcome | |---------|-------|---------|---------| | OEC | 0.640 | 0.103 | √ kept | | IAC | 0.612 | 0.087 | √ kept | | PSN | 0.585 | 0.142 | √ kept | | SCP | 0.598 | 0.058 | √ kept | | TTE | 0.563 | 0.218 | √ kept | | PED | 0.541 | 0.034 | √ kept | | DPI | 0.591 | 0.071 | √ guardrail | | TQS Composite | 0.732 | 0.092 | — | | HCR | 0.527 | 0.014 | × diversity | | BUS/TGCR/DCS-f. | ≤ 0.479 | < 0.25 | × conc. | | DCS-Jacc. | — | 0.729 | × length |

Main Results on SWE-Bench Verified

IDMethodD\mathcal{D}EasyMediumHardOverallΔ Base
B0Base (no SFT)—36.619.22.224.4—
B1Random-K1,02440.716.92.224.8+0.4
B2Bottom-K1,02433.516.90.021.8−2.6
B3Shortest-K1,02437.618.40.024.2−0.2
B4DPI-only-K1,02437.619.92.225.2+0.8
B5LLM-Judge-K (GPT-4o)1,02443.321.16.728.4+4.0
B6Top-LM-K (length-matched)1,02440.720.74.427.0+2.6
OursTop-K (highest TQS)1,02442.320.36.727.6+3.2

Direct Validation Among Successful Runs

Validation statisticHumanSonnet-5
High vs. Low agreement85.2 (208/244)81.1 (198/244)
Mid vs. Low agreement74.2 (190/256)77.0 (197/256)
High vs. Mid agreement76.8 (172/224)67.4 (151/224)
Overall agreement78.7 (570/724)75.4 (546/724)
Pooled concordance73.3 (631/861)76.2 (656/861)
Full-order match45.7 (137/300)41.3 (124/300)
Spearman ρ0.4170.402

Dimension Ablation

Selection signalpass@1
Full TQS-Top27.6
w/o Information focus24.6
w/o Intent-action alignment23.0
w/o Policy dynamics25.8
Random-K24.8
Base (no SFT)24.4

Behavioral Diagnosis on Rollouts

Process metricTraining Data (Top-K)Top modelRandom modelBottom model
Mean Steps34.250.6657.6463.46
Mean OEC0.6030.5710.5210.484
Mean PSN0.7530.5700.5480.568
Mean SCP0.9940.7770.7980.772
Mean PED0.8260.1920.2670.164
Mean DPI0.9960.9310.9230.906

External Outcome Check

The resolved rate increases monotonically from 54.1% in D1 to 86.9% in D10 across TQS deciles (32.9-point spread, no inversion at decile boundaries).

Theoretical and Practical Implications

Theoretical Implications

  1. Process quality is orthogonal to outcome: The paper demonstrates that "passing" is too coarse a signal for coding-agent SFT data—trajectories with identical outcomes can differ substantially in their value as supervision.

  2. Structured convergence as a quality framework: The three-dimensional characterization (information focus, intent–action alignment, policy dynamics) provides a principled way to think about what makes agent trajectories good training data.

  3. Length is correlated but insufficient: The Top-LM-K result (27.0 vs. Random-K's 24.8) shows that length captures some quality signal, but TQS provides additional discriminative power beyond length alone.

Practical Implications

  1. Scalable data selection: TQS makes corpus-scale trajectory filtering practical (49 minutes CPU time vs. $18.6K for LLM judging), enabling repeated rescoring and iterative data curation.

  2. Cost-quality tradeoff: TQS approaches the effectiveness of GPT-4o rubric-based judging (27.6 vs. 28.4 pass@1) at a fraction of the cost, with the gap narrowing on harder tasks.

  3. Behavioral imprint: Selecting high-TQS supervision leaves measurable behavioral improvements in the fine-tuned policy—shorter interactions, more focused observations, and fewer dirty patterns.

  4. Hard-task sensitivity: The Top–Random gap increases with task difficulty (1.6 on Easy → 3.4 on Medium → 4.5 on Hard), suggesting that process quality matters most for challenging problems.

Conclusion

Main Takeaways

  • TQS provides a lightweight, effective alternative to LLM-based data selection for coding-agent trajectories, operating directly on event-log structure in linear time.
  • Process-level trajectory quality is an important factor in coding-agent supervision, with top-ranked trajectories improving pass@1 by 3.2 points over base and 2.8 points over random selection.
  • All three structural dimensions contribute to the downstream benefit, with intent–action alignment being the most critical (removing it drops performance below random selection).
  • Low-quality successful trajectories can actively hurt downstream performance (Bottom-K: 21.8 vs. base: 24.4).

Future Directions

  • Recalibrating parsers and thresholds for different action spaces, multilingual traces, or other step granularities
  • Extending to GUI or multimodal agents (requiring new definitions of scope and intent)
  • Testing on larger backbones (preliminary 7B experiments showed unstable selector differences)
  • Multi-seed training runs for variance estimates
  • Incorporating long-trajectory tails (>32K tokens) that may contain useful recovery behavior

Key Limitations

  • Single teacher model (Qwen3-Coder-480B) under OpenHands scaffold
  • Fixed-budget setting with 1,024 trajectories per condition
  • Single training run per condition (no multi-seed variance)
  • TQS scores observed process structure, not whether the patch addresses the underlying root cause

Related papers