{"record":{"id":"de632d28296faae5","repo":"deepseek-ai/deepseek-harness","slug":"surface-replace-start-seq-op-start-index-st","errorCode":null,"errorMessage":"surface replace: start seq ${op.start} (index ${startIdx}) is after end seq ${op.end} (index ${endIdx})","messagePattern":"surface replace: start seq (.+?) \\(index (.+?)\\) is after end seq (.+?) \\(index (.+?)\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/session/src/surface.ts","lineNumber":259,"sourceCode":"    throw new Error(`surface replace: sourceEventSeqs must include every shadowed surface node; missing ${missing.join(', ')}`)\n  }\n}\n\n/** Locate one replacement range without mutating the current fold state. */\nfunction replacementRange(\n  state: SurfaceFoldState,\n  op: Extract<SurfaceOp, { op: 'replace' }>,\n): Pick<SurfaceReplacePlan, 'startIdx' | 'endIdx' | 'shadowedSeqs'> {\n  const startIdx = state.nodes.indexOf(op.start)\n  if (startIdx === -1) {\n    throw new Error(`surface replace: start seq ${op.start} not found in surface`)\n  }\n  const endIdx = state.nodes.indexOf(op.end)\n  if (endIdx === -1) {\n    throw new Error(`surface replace: end seq ${op.end} not found in surface`)\n  }\n  if (startIdx > endIdx) {\n    throw new Error(`surface replace: start seq ${op.start} (index ${startIdx}) is after end seq ${op.end} (index ${endIdx})`)\n  }\n  return {\n    startIdx,\n    endIdx,\n    shadowedSeqs: state.nodes.slice(startIdx, endIdx + 1),\n  }\n}\n\n/**\n * Deep structural equality over the session-event JSON value domain\n * (null/boolean/number/string, arrays, plain objects). Replaces\n * `node:util`'s isDeepStrictEqual to keep this module browser-safe.\n */\nfunction isDeepEqualJson(a: unknown, b: unknown): boolean {\n  if (a === b) return true\n  if (Array.isArray(a) || Array.isArray(b)) {\n    if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false\n    return a.every((item, i) => isDeepEqualJson(item, b[i]))","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/core/session/src/surface.ts#L241-L277","documentation":"Ordering failure in replacementRange: both start and end seqs exist in the surface, but the start node's index is after the end node's index. The replacement range is inverted; the fold cannot replace a backwards range and reports both indices.","triggerScenarios":"Thrown at packages/core/session/src/surface.ts:259 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Swap start and end so start names the earlier surface node","Fix range construction that reversed min/max seqs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}