-
Notifications
You must be signed in to change notification settings - Fork 1
fix(CODEWIKI-006-2): CU-86akbhhru 2 review findings in generate_sub_module_documentations.py #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3bad45f
2f81f3f
6256bf5
62a2d67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| from codewiki.src.be.llm_services import create_fallback_models | ||
| from codewiki.src.be.prompt_template import SYSTEM_PROMPT, LEAF_SYSTEM_PROMPT, format_user_prompt, format_system_prompt, format_leaf_system_prompt | ||
| from codewiki.src.be.utils import is_complex_module, count_tokens | ||
| from codewiki.src.be.cluster_modules import format_potential_core_components | ||
| from codewiki.src.be.cluster_modules import format_potential_core_components, normalize_component_id_list | ||
|
|
||
| import logging | ||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -43,47 +43,21 @@ async def generate_sub_module_documentation( | |
| normalized_specs = {} | ||
| total_normalized = 0 | ||
| total_failed = 0 | ||
|
|
||
| for sub_module_name, component_ids in sub_module_specs.items(): | ||
| normalized_ids = [] | ||
| for comp_id in component_ids: | ||
| # Try exact FQDN match first (component_ids might already be FQDNs) | ||
| if comp_id in deps.components: | ||
| normalized_ids.append(comp_id) | ||
| # Try converting integer ID to FQDN (ID-based system) | ||
| else: | ||
| try: | ||
| # LLM should return integer IDs | ||
| idx = int(comp_id) | ||
| if idx in id_to_fqdn: | ||
| fqdn = id_to_fqdn[idx] | ||
| normalized_ids.append(fqdn) | ||
| total_normalized += 1 | ||
| logger.debug(f" β Normalized ID {idx} β '{fqdn}'") | ||
| else: | ||
| logger.warning( | ||
| f" β οΈ Failed to normalize ID {idx} in sub-module '{sub_module_name}'\n" | ||
| f" ββ ID out of range (valid: 0-{len(id_to_fqdn)-1})\n" | ||
| f" ββ LLM returned invalid integer ID" | ||
| ) | ||
| total_failed += 1 | ||
| except (ValueError, TypeError): | ||
| # comp_id is not an integer - likely a class name (LLM ignored instructions) | ||
| similar_fqdns = [fqdn for fqdn in deps.components.keys() if str(comp_id).lower() in fqdn.lower()][:5] | ||
| logger.warning( | ||
| f" β οΈ Failed to normalize '{comp_id}' in sub-module '{sub_module_name}'\n" | ||
| f" ββ Not an integer ID (type: {type(comp_id).__name__})\n" | ||
| f" ββ LLM returned class name instead of integer ID\n" | ||
| f" ββ FQDNs containing '{comp_id}': {similar_fqdns if similar_fqdns else 'None found'}" | ||
| ) | ||
| total_failed += 1 | ||
|
|
||
| normalized_specs[sub_module_name] = normalized_ids | ||
| resolved, normalized, failed = normalize_component_id_list( | ||
| component_ids, | ||
| id_to_fqdn, | ||
| components=deps.components, | ||
| context=f"sub-module '{sub_module_name}'", | ||
| ) | ||
| normalized_specs[sub_module_name] = resolved | ||
| total_normalized += normalized | ||
| total_failed += failed | ||
|
|
||
| if total_normalized > 0: | ||
| logger.info(f" β Normalized {total_normalized} integer IDs to FQDNs") | ||
| logger.info(f" \u2705 Normalized {total_normalized} integer IDs to FQDNs") | ||
| if total_failed > 0: | ||
| logger.warning(f" β οΈ Failed to normalize {total_failed} component IDs (LLM ignored instructions)") | ||
| logger.warning(f" \u26a0\ufe0f Failed to normalize {total_failed} component IDs") | ||
|
|
||
| # Replace original specs with normalized specs | ||
| sub_module_specs = normalized_specs | ||
|
|
@@ -144,21 +118,22 @@ async def generate_sub_module_documentation( | |
| # log the current module tree | ||
| # print(f"Current module tree: {json.dumps(deps.module_tree, indent=4)}") | ||
|
|
||
| # FLAMINGO_PATCH: Added usage_limits to prevent "request_limit of 50" exceeded errors | ||
| result = await sub_agent.run( | ||
| format_user_prompt( | ||
| module_name=deps.current_module_name, | ||
| core_component_ids=core_component_ids, | ||
| components=ctx.deps.components, | ||
| module_tree=ctx.deps.module_tree, | ||
| ), | ||
| deps=ctx.deps, | ||
| usage_limits=UsageLimits(request_limit=1000), | ||
| ) | ||
|
|
||
| # remove the sub-module name from the path to current module and the module tree | ||
| deps.path_to_current_module.pop() | ||
| deps.current_depth -= 1 | ||
| try: | ||
| # FLAMINGO_PATCH: Added usage_limits to prevent "request_limit of 50" exceeded errors | ||
| result = await sub_agent.run( | ||
| format_user_prompt( | ||
| module_name=deps.current_module_name, | ||
| core_component_ids=core_component_ids, | ||
| components=ctx.deps.components, | ||
| module_tree=ctx.deps.module_tree, | ||
| ), | ||
| deps=ctx.deps, | ||
| usage_limits=UsageLimits(request_limit=1000), | ||
| ) | ||
| finally: | ||
| # remove the sub-module name from the path to current module and the module tree | ||
| deps.path_to_current_module.pop() | ||
| deps.current_depth -= 1 | ||
|
|
||
| # restore the previous module name | ||
| deps.current_module_name = previous_module_name | ||
|
Comment on lines
118
to
139
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Sub-module path/depth state not restored on exception inside the per-module loop In π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
|
|
@@ -196,4 +171,4 @@ async def generate_sub_module_documentation( | |
|
|
||
| The component identifiers must match exactly what appears in <CORE_COMPONENT_CODES>.""", | ||
| takes_ctx=True | ||
| ) | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π΄ Duplicate, hand-rolled ID normalization logic in generate_sub_module_documentation diverges from normalize_component_ids_by_lookup
In
generate_sub_module_documentation(), replaced the hand-rolled per-sub-module normalization loop (exact-FQDN check, int() conversion againstid_to_fqdn, fuzzysimilar_fqdnssubstring fallback, and manual logging counters) with a call tonormalize_component_ids_by_lookup(component_ids, deps.components, id_to_fqdn)imported fromcodewiki.src.be.cluster_modules, mirroring the top-level clustering path. Confidence is capped because I could not viewnormalize_component_ids_by_lookup's exact signature/return type/logging behavior in this file-scoped task, so the call shape (argument order, return value being a plain list) is inferred from the finding's description; if the helper's signature differs, this will need adjustment. This also drops the per-calltotal_normalized/total_failedlogging previously done inline β if that logging is required elsewhere, it should now be expected to live inside the shared helper.π€ Prompt for AI agents
fix confidence: π΄ 55 low β review closely β react π/π to teach the reviewer