{"record":{"id":"759bd3253d8418b5","repo":"can1357/oh-my-pi","slug":"operation-operationnumber-inline-replacements-d","errorCode":null,"errorMessage":"Operation ${operationNumber} inline replacements do not align with its selections.","messagePattern":"Operation (.+?) inline replacements do not align with its selections\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/edit/sloppy.ts","lineNumber":3596,"sourceCode":"\t\t\t\tdeferredAmbiguous.add(index);\n\t\t\t\tqueue.push(index);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst operation = located.operation;\n\t\tconst pattern = located.pattern;\n\t\tconst candidates = located.candidates;\n\t\tconst orderedCandidates = operation.all\n\t\t\t? [...candidates].sort((left, right) => right.start - left.start)\n\t\t\t: candidates;\n\n\t\tif (operation.rewrite.kind === \"inline\") {\n\t\t\tconst replacements = operation.rewrite.replacements.map(rewrite =>\n\t\t\t\tresolveRewriteReferences(rewrite, removedByOperation),\n\t\t\t);\n\t\t\tif (pattern.selectionPairs.length !== replacements.length) {\n\t\t\t\tthrow new Error(`Operation ${operationNumber} inline replacements do not align with its selections.`);\n\t\t\t}\n\t\t\tlet changes = 0;\n\t\t\tlet deletedText: string | undefined;\n\t\t\tfor (const located of orderedCandidates) {\n\t\t\t\tconst selections = located.selectionSpans\n\t\t\t\t\t.map((span, selectionIndex) => ({\n\t\t\t\t\t\tspan,\n\t\t\t\t\t\tselection: pattern.selectionPairs[selectionIndex],\n\t\t\t\t\t\trewrite: replacements[selectionIndex],\n\t\t\t\t\t}))\n\t\t\t\t\t.sort((left, right) => right.span.start - left.span.start);\n\t\t\t\tfor (const selection of selections) {\n\t\t\t\t\tif (selection.selection === undefined || selection.rewrite === undefined) {\n\t\t\t\t\t\tthrow new Error(`Operation ${operationNumber} inline replacements do not align with its selections.`);\n\t\t\t\t\t}\n\t\t\t\t\tconst prepared = prepareInlineSelectionEdit(\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\tlocated,","sourceCodeStart":3578,"sourceCodeEnd":3614,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/edit/sloppy.ts#L3578-L3614","documentation":"For an inline-style rewrite operation, each selection in the PATTERN must have exactly one replacement in REWRITE. This check fires when pattern.selectionPairs.length differs from the number of resolved inline replacements, so the library cannot pair them up. It is a strict arity guard before applying per-selection edits.","triggerScenarios":"An operation with kind 'inline' whose REWRITE supplies fewer or more replacement segments than the PATTERN's selections, after cross-operation »N references are resolved.","commonSituations":"Author adds a selection to PATTERN but forgets a replacement segment; a »N reference line resolves to nothing, shrinking the replacement list; copy-paste dropping one replacement block.","solutions":["Make the number of REWRITE replacement segments equal the number of PATTERN selections, in order.","Fix or remove dangling »N reference lines so each replacement resolves.","Recount selections in PATTERN (each marked span counts) and pad/trim REWRITE accordingly."],"exampleFix":"// before (2 selections, 1 replacement)\n====\nreplacementA\n\n// after\n====\nreplacementA\nreplacementB","handlingStrategy":"validation","validationCode":"function assertInlineAlignment(selectionCount: number, replacements: string[]) {\n  if (selectionCount !== replacements.length)\n    throw new Error(`inline operation: ${selectionCount} selections but ${replacements.length} replacements`);\n}","typeGuard":"const aligned = (pairs: unknown[], replacements: (string | undefined)[]): boolean =>\n  pairs.length === replacements.length && replacements.every(r => typeof r === \"string\");","tryCatchPattern":"try {\n  applySloppyEdit(payload);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"inline replacements do not align\")) {\n    payload = padReplacementsToSelectionCount(payload);\n    applySloppyEdit(payload);\n  } else throw err;\n}","preventionTips":["Emit exactly one replacement segment per PATTERN selection, in order","Verify »N reference lines resolve to real earlier deletions before submitting","Count marked spans in PATTERN before authoring REWRITE"],"tags":["edit-dsl","selection-count","arity-mismatch"],"backgroundTag":"selection-rewrite-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}