deepseek-ai/deepseek-harness · error · Error
compactRegion: end seq ${end} not found in surface
Error message
compactRegion: end seq ${end} not found in surface What it means
compactRegion's `end` must be a seq currently present in session.surface.nodes. This error means the end seq is not on the surface: an earlier compaction replacement shadowed it, pruning rewrote it, or the value was never a surface node (log-only events such as compaction/* never appear on the surface).
Source
Thrown at packages/compaction/compaction-basic/src/region.ts:320
* @param session - session whose latest marker state is inspected.
* @param stage - operation label included in the busy diagnostic.
*/
export function assertNoActiveCompaction(session: Session, stage: string): void {
const entryState = inspectCompactionEntryState(session.events)
assertCompactionInactive(
entryState.unmatchedCompactionStart,
entryState.latestEndSeedSeq,
stage,
)
}
/** Validate one requested surface-position span before asynchronous work begins. */
function validateSurfaceRegion(session: Session, start: number, end: number): SurfaceSelection {
const nodes = session.surface.nodes
const startIdx = nodes.indexOf(start)
const endIdx = nodes.indexOf(end)
if (startIdx === -1) throw new Error(`compactRegion: start seq ${start} not found in surface`)
if (endIdx === -1) throw new Error(`compactRegion: end seq ${end} not found in surface`)
if (startIdx > endIdx) {
throw new Error(
`compactRegion: start seq ${start} (position ${startIdx}) is after end seq ${end} (position ${endIdx}) on the surface`,
)
}
// oxlint-disable-next-line typescript/no-non-null-assertion
if (!toolPairingBalancedBefore(session, nodes[startIdx]!)) {
throw new Error(`compactRegion: start seq ${start} is not a balanced boundary (would split a step's tool-call/result pair)`)
}
// oxlint-disable-next-line typescript/no-non-null-assertion
if (!toolPairingBalancedAfter(session, nodes[endIdx]!)) {
throw new Error(`compactRegion: end seq ${end} is not a balanced boundary (would split a step, or the step is still open)`)
}
return { start, end, startIdx, endIdx, shadowedSeqs: nodes.slice(startIdx, endIdx + 1) }
}
/** Snapshot pricing and replay input for a validated surface range. */View on GitHub (pinned to b150a551b8)
Solutions
- Read agent.session.surface.nodes immediately before the call and take `end` from that array
- Prefer the last node of the span validated in the same synchronous block that issues the call
- Log surface.nodes to confirm which seqs are visible when the error fires
Example fix
// before: end derived by arithmetic on old seqs await ctx.compaction.compactRegion(start, start + 10, agent) // after: end picked from the current surface const nodes = agent.session.surface.nodes await ctx.compaction.compactRegion(nodes[0]!, nodes[nodes.length - 1]!, agent)
Defensive patterns
Strategy: validation
Validate before calling
const nodes = agent.session.surface.nodes
if (!nodes.includes(end)) {
throw new RangeError(`end seq ${end} is not on the current surface`)
} Prevention
- Pick `end` from session.surface.nodes right before the call
- Do not compute `end` by arithmetic on seqs — replacements make seqs non-contiguous
- After any compaction or prune, re-read the surface before choosing boundaries
When it happens
Trigger: Passing an end seq from a superseded surface generation; passing a compaction/summary or turn/* event seq as `end`; using seqs read before a prior compactionRegion or auto-compaction committed a replacement.
Common situations: Boundary seqs cached across awaits; recomputing `end` by arithmetic (start + n) after replacements made seqs non-contiguous; replaying recorded command arguments on a mutated session.
Related errors
- compactRegion: start seq ${start} not found in surface
- compactRegion: start seq ${start} (position ${startIdx}) is
- compactRegion: start seq ${start} is not a balanced boundary
- compactRegion: end seq ${end} is not a balanced boundary (wo
- BasicCompactionConfig: auto must be a boolean
AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24).
Data as JSON: /api/errors/e962e665eb998aec.
Report an issue: GitHub.