From 92947a3dc450e1f8bd1eded4682bfe6766a1cbcc Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 29 Dec 2025 22:26:31 +0100 Subject: [PATCH] Fix common ancestor finding: iterate backwards to find deepest ancestor getPath returns root-first, so iterating forward found root as common ancestor instead of the deepest shared node. Now iterates backwards. --- .../src/core/compaction/branch-summarization.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/src/core/compaction/branch-summarization.ts b/packages/coding-agent/src/core/compaction/branch-summarization.ts index 952676be..1d37158c 100644 --- a/packages/coding-agent/src/core/compaction/branch-summarization.ts +++ b/packages/coding-agent/src/core/compaction/branch-summarization.ts @@ -91,14 +91,15 @@ export function collectEntriesForBranchSummary( return { entries: [], commonAncestorId: null }; } - // Find common ancestor + // Find common ancestor (deepest node that's on both paths) const oldPath = new Set(session.getPath(oldLeafId).map((e) => e.id)); const targetPath = session.getPath(targetId); + // targetPath is root-first, so iterate backwards to find deepest common ancestor let commonAncestorId: string | null = null; - for (const entry of targetPath) { - if (oldPath.has(entry.id)) { - commonAncestorId = entry.id; + for (let i = targetPath.length - 1; i >= 0; i--) { + if (oldPath.has(targetPath[i].id)) { + commonAncestorId = targetPath[i].id; break; } }