fix(autonomy): correct child ID linkage in _build_hierarchy() #1227

Closed
brent.edwards wants to merge 1 commits from bugfix/m6-build-hierarchy-child-ids into master
2 changed files with 16 additions and 9 deletions
+6
View File
@@ -2,6 +2,12 @@
## Unreleased
- Fixed child ID linkage in `DecompositionService._build_hierarchy()` where
`children_ids.append(nodes[-1].node_id)` used the last node in the flat
list instead of the actual child node ID from each recursive call.
Changed return type to `tuple[int, str]` to propagate both `max_depth`
and `node_id`, and updated `decompose()` caller to unpack the new
return type. (#1225)
- Added missing `LspServerConfig` model fields per specification:
`description` (max 1000 chars), `transport` (`LspTransport` enum with
`stdio`/`tcp`, default `stdio`), `initialization` (dict for LSP
@@ -168,7 +168,7 @@ class DecompositionService:
)
nodes: list[DecompositionNode] = []
max_depth = self._build_hierarchy(
max_depth, _ = self._build_hierarchy(
files=unique_files,
config=cfg,
depth=0,
@@ -198,10 +198,12 @@ class DecompositionService:
depth: int,
parent_id: str | None,
nodes: list[DecompositionNode],
) -> int:
) -> tuple[int, str]:
"""Recursively partition *files* into a tree.
Returns the maximum depth reached during recursion.
Returns a tuple of ``(max_depth, node_id)`` where *max_depth* is
the maximum depth reached during recursion and *node_id* is the
ID of the root node created by this call.
"""
estimated = sum(estimate_tokens_for_path(f) for f in files)
@@ -224,7 +226,7 @@ class DecompositionService:
strategy=ClusterStrategy.DIRECTORY,
)
nodes.append(node)
return depth
return (depth, node_id)
# Cluster using directory strategy first, fall back to language
clusters = ClusteringStrategy.cluster_by_directory(
@@ -261,7 +263,7 @@ class DecompositionService:
strategy=ClusterStrategy.FALLBACK,
)
nodes.append(node)
return depth
return (depth, node_id)
clusters = ClusteringStrategy.deterministic_sort(
clusters, config.language_priority
@@ -271,15 +273,14 @@ class DecompositionService:
max_child_depth = depth
for cluster in clusters:
child_depth = self._build_hierarchy(
child_depth, child_node_id = self._build_hierarchy(
files=cluster,
config=config,
depth=depth + 1,
parent_id=node_id,
nodes=nodes,
)
# The last added node is the child root
children_ids.append(nodes[-1].node_id)
children_ids.append(child_node_id)
max_child_depth = max(max_child_depth, child_depth)
internal_node = DecompositionNode(
@@ -294,7 +295,7 @@ class DecompositionService:
children_ids=children_ids,
)
nodes.append(internal_node)
return max_child_depth
return (max_child_depth, node_id)
# ------------------------------------------------------------------
# Decision recording