{"record":{"id":"e962e665eb998aec","repo":"deepseek-ai/deepseek-harness","slug":"compactregion-end-seq-end-not-found-in-surface","errorCode":null,"errorMessage":"compactRegion: end seq ${end} not found in surface","messagePattern":"compactRegion: end seq (.+?) not found in surface","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/compaction/compaction-basic/src/region.ts","lineNumber":320,"sourceCode":" * @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\n/** Snapshot pricing and replay input for a validated surface range. */","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/compaction/compaction-basic/src/region.ts#L302-L338","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: end derived by arithmetic on old seqs\nawait ctx.compaction.compactRegion(start, start + 10, agent)\n\n// after: end picked 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(end)) {\n  throw new RangeError(`end seq ${end} is not on the current surface`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"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"}