{"record":{"id":"89c3efcb918cd55d","repo":"deepseek-ai/deepseek-harness","slug":"compactregion-start-seq-start-not-found-in-sur","errorCode":null,"errorMessage":"compactRegion: start seq ${start} not found in surface","messagePattern":"compactRegion: start seq (.+?) not found in surface","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/compaction/compaction-basic/src/region.ts","lineNumber":319,"sourceCode":" * Recheck the durable compaction lock after an asynchronous policy decision.\n * @param session - session whose latest marker state is inspected.\n * @param stage - operation label included in the busy diagnostic.\n */\nexport function assertNoActiveCompaction(session: Session, stage: string): void {\n  const entryState = inspectCompactionEntryState(session.events)\n  assertCompactionInactive(\n    entryState.unmatchedCompactionStart,\n    entryState.latestEndSeedSeq,\n    stage,\n  )\n}\n\n/** Validate one requested surface-position span before asynchronous work begins. */\nfunction validateSurfaceRegion(session: Session, start: number, end: number): SurfaceSelection {\n  const nodes = session.surface.nodes\n  const startIdx = nodes.indexOf(start)\n  const endIdx = nodes.indexOf(end)\n  if (startIdx === -1) throw new Error(`compactRegion: start seq ${start} not found in surface`)\n  if (endIdx === -1) throw new Error(`compactRegion: end seq ${end} not found in surface`)\n  if (startIdx > endIdx) {\n    throw new Error(\n      `compactRegion: start seq ${start} (position ${startIdx}) is after end seq ${end} (position ${endIdx}) on the surface`,\n    )\n  }\n  // oxlint-disable-next-line typescript/no-non-null-assertion\n  if (!toolPairingBalancedBefore(session, nodes[startIdx]!)) {\n    throw new Error(`compactRegion: start seq ${start} is not a balanced boundary (would split a step's tool-call/result pair)`)\n  }\n  // oxlint-disable-next-line typescript/no-non-null-assertion\n  if (!toolPairingBalancedAfter(session, nodes[endIdx]!)) {\n    throw new Error(`compactRegion: end seq ${end} is not a balanced boundary (would split a step, or the step is still open)`)\n  }\n\n  return { start, end, startIdx, endIdx, shadowedSeqs: nodes.slice(startIdx, endIdx + 1) }\n}\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/compaction/compaction-basic/src/region.ts#L301-L337","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read agent.session.surface.nodes immediately before the call and take `start` from that array","Re-derive the range after any await during which another compaction could land","Log surface.nodes around the call to see which seqs are actually visible"],"exampleFix":"// before: seq from an older surface generation\nawait ctx.compaction.compactRegion(oldStart, end, agent)\n\n// after: take boundaries from the current surface\nconst nodes = agent.session.surface.nodes\nawait ctx.compaction.compactRegion(nodes[0]!, nodes[nodes.length - 1]!, agent)","handlingStrategy":"validation","validationCode":"const nodes = agent.session.surface.nodes\nif (!nodes.includes(start)) {\n  throw new RangeError(`start seq ${start} is not on the current surface`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Take boundary seqs from session.surface.nodes in the same synchronous block as the call","Never reuse seqs captured before an await — an auto-compaction may have replaced the range","Log-only events (compaction/*, turn/*) are never surface nodes; only message-bearing events appear on the surface"],"tags":["compaction","surface","seq","validation"],"backgroundTag":"id-not-in-collection","analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}