CodeWiki icon indicating copy to clipboard operation
CodeWiki copied to clipboard

LLM-chosen module names collide in flat output directory, silently overwriting or losing documentation files

Open StefanZoerner opened this issue 4 months ago • 1 comments

Summary

Module and sub-module names are chosen freely by the LLM during clustering and agent delegation, and all resulting .md files are written into a single flat output directory. Nothing enforces uniqueness across hierarchy levels or between sibling sub-modules. When names collide, files are silently overwritten or never written, parent documents end up linking to missing files, and the run still finishes with

✓ Documentation generated successfully!.

Environment

CodeWiki 1.0.1 · Python 3.12 · provider openai-compatible via OpenRouter, model deepseek/deepseek-v4-flash · repo: https://github.com/DokChess/dokchess-en (Java, 43 parsed files) · config: max-token-per-module 20000, max-token-per-leaf-module 16000, max-tokens 16384, max-depth 2

Observed behavior — two collision variants across two consecutive runs on the same repo/config

Variant 1: sub-module names collide with top-level module names.

The repository clustering produced top-level modules including engine, search, and evaluation. The engine module agent then delegated to sub-modules it chose to name search and evaluation — identical to the existing top-level names:


[13:51:03] INFO  LLM module clustering for repository produced 9 top-level modules.
...
[14:15:12] INFO  📄 Processing leaf module: engine
[14:19:28] INFO    └─ Generating documentation for sub-module: search
[14:21:10] INFO    └─ Generating documentation for sub-module: evaluation
[14:25:22] INFO  📄 Processing leaf module: search
[14:25:22] INFO  ✓ Module docs already exists at .../codewiki-docs/search.md
[14:25:22] INFO  📄 Processing leaf module: evaluation
[14:25:22] INFO  ✓ Module docs already exists at .../codewiki-docs/evaluation.md
...
[14:50:39] WARNING  Module docs not found at .../codewiki-docs/engine.md

The top-level search/evaluation modules were skipped because the engine agent's sub-module files already occupied their paths, and engine.md itself was never written. The final summary still reported success.

Variant 2: duplicate sub-module names within one module.

In the next run (same repo, same config, different random clustering), the textui agent generated the same sub-module name twice:

[15:44:48] INFO  📄 Processing leaf module: textui
[15:48:01] INFO    └─ Generating documentation for sub-module: textui_xboard
[15:51:13] INFO    └─ Generating documentation for sub-module: textui_xboard
...
[16:00:17] WARNING  Module docs not found at .../codewiki-docs-v2/main.md

One of the two generations is lost to the collision; in this run main.md additionally went missing. Again: ✓ Documentation generated successfully!.

Notably, in run 2 the engine agent prefixed its sub-modules (engine_search, engine_eval), showing the LLM sometimes avoids collisions on its own — but there is no mechanism guaranteeing it.

Why this matters

Documentation completeness becomes a dice roll: identical repo + config produced 9 modules with one missing file in run 1, 6 modules with a different missing file in run 2. Parent documents contain links to files that don't exist. The failure is silent: warnings appear only late in the log, and the process exits successfully, so CI pipelines would not catch it.

Suggested fixes (any of these would help)

Namespace output files by hierarchy, e.g. engine/search.md or engine__search.md, so LLM-chosen names cannot collide across levels. Enforce uniqueness at write time: refuse/rename on existing path (search_2.md) instead of skipping or overwriting. Validate at the end of generation that every module in module_tree.json has a corresponding file, and exit non-zero (or clearly report) otherwise.

Full logs of both runs available on request.

StefanZoerner avatar Jul 16 '26 16:07 StefanZoerner

Thank you for the report. Module documentation is stored in a single flat directory using the format {module_name}.md. Because module names are chosen freely by the LLM at every level of the hierarchy, there was no guarantee that they would be unique. When two modules received the same name, the second file was silently not written. The resume logic then saw that a file with that name already existed and skipped the legitimate module entirely with the message “Module docs already exists.”

The flat directory structure is intentional. It is designed to make CodeWiki easier to use with smaller open-source LLMs, which often struggle to generate and maintain deeply nested documentation hierarchies.

We have implemented a fix in 840e1f4:

  1. Uniqueness is now enforced at delegation time. Before a submodule name is added to the module tree, it is checked against all existing module names and documentation files on disk. Conflicting names are renamed using the format {parent}_{name}, such as engine_search, with a numeric suffix added as a final fallback. The delegation tool also reports renamed modules and any files that could not be written back to the parent agent, ensuring that cross-references use the actual filenames. Duplicate names within the same delegation batch, such as the textui_xboard case, are handled in the same way.

  2. End-of-run validation has been added. After generation completes, every module in module_tree.json is checked against the documentation files on disk. Any missing files are listed explicitly, and the CLI exits with a non-zero status instead of displaying the success banner. This allows incomplete runs to be detected by CI. Running the same command again will resume the process and generate the missing documentation.

anhnh2002 avatar Jul 20 '26 05:07 anhnh2002