@@ -227,8 +227,18 @@ def determine_project_for_conversation(
227227) -> str | None :
228228 """Resolve which workspace folder owns a composer conversation.
229229
230- Uses per-workspace composer maps, project layouts, file paths in bubbles,
231- and path-segment heuristics in priority order.
230+ Args:
231+ composer_data: Parsed ``composerData`` JSON for *composer_id*.
232+ composer_id: Composer UUID from the global DB key.
233+ project_layouts_map: ``{composer_id: [root_path, ...]}`` from global KV.
234+ project_name_to_workspace_id: Basename-to-workspace-folder map.
235+ workspace_path_to_id: Normalized root path to workspace folder map.
236+ workspace_entries: Output of :func:`services.workspace_db.collect_workspace_entries`.
237+ bubble_map: ``{bubble_id: bubble_dict}`` from global KV.
238+ composer_id_to_workspace_id: Definitive per-workspace composer map; when
239+ ``None``, layout and path heuristics are used without this shortcut.
240+ invalid_workspace_ids: Workspace folders marked invalid; mapped IDs in
241+ this set are ignored when using *composer_id_to_workspace_id*.
232242
233243 Returns:
234244 Workspace folder name, or ``None`` when no project can be determined.
@@ -360,7 +370,27 @@ def infer_invalid_workspace_aliases(
360370 composer_id_to_ws : dict ,
361371 invalid_workspace_ids : set [str ],
362372) -> dict [str , str ]:
363- """Majority-vote each invalid workspace ID to its most likely valid replacement."""
373+ """Map invalid workspace IDs to valid replacements by majority vote.
374+
375+ For each composer assigned to an *invalid_workspace_ids* entry, calls
376+ :func:`determine_project_for_conversation` without the definitive composer map
377+ and counts votes for inferred valid workspace folders.
378+
379+ Args:
380+ composer_rows: Global ``composerData:*`` SQLite rows.
381+ project_layouts_map: Layout map passed to :func:`determine_project_for_conversation`.
382+ project_name_map: Basename map for path resolution.
383+ workspace_path_map: Normalized path map for path resolution.
384+ workspace_entries: Workspace folder entries from storage scan.
385+ bubble_map: Bubble KV map for path resolution.
386+ composer_id_to_ws: Composer-to-workspace map (may point at invalid IDs).
387+ invalid_workspace_ids: Workspace folder names to reassign.
388+
389+ Returns:
390+ ``{invalid_id: replacement_id}`` for IDs with at least one vote. Ties
391+ break by choosing the replacement with the highest vote count (first
392+ max in iteration order). Returns ``{}`` when no invalid ID receives votes.
393+ """
364394 votes : dict [str , dict [str , int ]] = {}
365395 for row in composer_rows :
366396 cid = row ["key" ].split (":" )[1 ]
0 commit comments