deepseek-ai/deepseek-harness · error · Error

compactRegion: start seq ${start} not found in surface

Error message

compactRegion: start seq ${start} not found in surface

What it means

compactRegion names its span by surface-position seqs, and `start` must be a seq currently present in session.surface.nodes. This error means the seq is not on the surface: it was shadowed by an earlier compaction replacement, rewritten by pruning, or was never a surface node (for example a log-only compaction/* or turn/* event seq).

Source

Thrown at packages/compaction/compaction-basic/src/region.ts:319

 * Recheck the durable compaction lock after an asynchronous policy decision.
 * @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) }
}

View on GitHub (pinned to b150a551b8)

Solutions

  1. Read agent.session.surface.nodes immediately before the call and take `start` from that array
  2. Re-derive the range after any await during which another compaction could land
  3. Log surface.nodes around the call to see which seqs are actually visible

Example fix

// before: seq from an older surface generation
await ctx.compaction.compactRegion(oldStart, end, agent)

// after: take boundaries 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(start)) {
  throw new RangeError(`start seq ${start} is not on the current surface`)
}

Prevention

When it happens

Trigger: Passing a seq captured before a prior compaction replaced its range (replacements land fresh high-seq summary nodes and shadow the old seqs); passing a log-only event seq; passing a stale seq after the tool-result pruner rewrote a tool/result node.

Common situations: Caching boundary seqs across an await while automatic compaction runs; replaying an earlier command's arguments against a mutated session; assuming every event seq is surface-visible.

Related errors


AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24). Data as JSON: /api/errors/89c3efcb918cd55d. Report an issue: GitHub.