Skip to content

Run module agents concurrently, with progress, ETA and failure isolation - #2

Merged
dandydarshan merged 5 commits into
mainfrom
perf/speed-up-generation
Oct 18, 2026
Merged

dandydarshan merged 5 commits into
mainfrom
perf/speed-up-generation

Conversation

@dandydarshan

Copy link
Copy Markdown
Owner

Summary

Module agents now run side by side (--concurrency, default 4) with a status line after every page. This PR also fixes the problems a real 8-way run on a ~800-file TypeScript repo exposed.

 generate_module_documentation
-  for module in processing_order:          # one at a time
-    run_module_agent / generate_parent_module_docs
+  _process_module_tree                     # siblings + independent leaves concurrently
+    AgentSlots(concurrency)                # caps live agent sessions
+      parent lends its slot while sub-agents run (no deadlock)
+    SharedModuleTree                       # agents no longer overwrite each other's sub-modules
+    GenerationProgress                     # "✓ name (3m) · 12/40 done · 7 running · ETA ~20m"

The fixes from that run (last commit):

 ETA
-  remaining × avg(module time) / concurrency    # parent time spans its whole subtree → ETA kept climbing
+  remaining × elapsed / finished                 # observed throughput, once ≥ concurrency finished

 generate_sub_module_documentation (pydantic + caw)
-  if any sub-agent failed: raise                 # parent agent dies, its page is lost, failure climbs the tree
+  log each failure; report lists the page as missing; next run regenerates it from module_tree.json

 codewiki generate --update (Step 5)
+  status line per leaf + "Updating N leaves one at a time (they share overview.md)"

Also in this branch: agent pages that were left unwritten are recovered, component ids in super-grouping are normalized, and the module file count includes sub-modules.

Not changed: --update still updates its leaf modules one at a time. Every leaf may edit overview.md, so running them in parallel would mean redesigning how pages are assigned to agents. --concurrency covers the missing-page step of an update; the --help text says so.

Evidence

  • Before (8-way run on widgets-sdk2, code-wiki-new-logs.txt):
    • The ETA climbed from ~41m to ~9h while 94 of 136 pages finished.
    • One timed-out child failed whole parents: directives after 2h 26m, core_ui_components after 2h 20m.
    • --update printed no progress at all.
  • After: 329 tests pass. New or updated tests:
test_progress_status_line_and_eta
  2 modules done in 180 s, 6 left  → "ETA ~9m 00s"   (was 4m 30s from per-module average)

test_pydantic_failed_sub_module_does_not_fail_its_parent
  sub-agents "good" ok, "bad" raises
  → tool returns (no raise), good.md written, "bad" reported missing,
    still in module_tree, progress: 1 done / 1 failed

Not yet run end-to-end on a real repo after the last commit.

Merge Danger

Door: two-way

Revert the merge to go back to sequential generation. --concurrency 1 gives the old one-at-a-time order without reverting.

Blast Radius: generation

  • Higher default concurrency (4) means more parallel model requests, so a rate-limited provider may return HTTP 429 more often. The progress line suggests lowering --concurrency when that happens.
  • A run can now finish with a parent page while one of its sub-module pages is missing. Before, the parent page was missing too. Rerunning codewiki generate fills in the gap.
  • Known, not fixed here: when a request times out, the fallback model rejects the retry with HTTP 400 (tool_use.id pattern). Timeouts still fail that module.

🤖 Generated with Claude Code

Darshan M U and others added 5 commits October 12, 2026 08:50
Subscription CLIs sometimes answer with the whole module page as their
final message instead of calling str_replace_editor, so the run
"completed" without a file and generation then failed on the missing
doc. Save that reply as the page when it looks like one (a "#" heading,
at least 500 characters).

The super-grouping prompt lists each module's components under it, and
the LLM sometimes answered with those component ids instead of module
names, which were then dropped as unknown modules. Map a component id
back to the module that owns it.

Also state in the caw str_replace_editor description that working_dir
is required and must be "repo" or "docs".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generation ran every module agent one after another: a 1046-file
repository took 7.4 h as 211 serial agent runs of ~2 min each (issue
FSoft-AI4Code#126). Independent modules now run at the same time.

- The generator walks the module tree as async tasks: siblings and
  leaves of different branches run together, and a parent page is
  written once all its children are done. --concurrency (default 4)
  caps live agent sessions; `codewiki config set --concurrency N`
  saves a default, which the generate flag overrides per run.
- Sub-modules an agent delegates also run side by side (both backends).
  AgentSlots caps sessions across the whole run; a parent waiting on
  its sub-agents lends them its slot, so a full pool cannot deadlock.
- All agents share one module tree (SharedModuleTree) under a lock.
  Each agent used to load module_tree.json and save its own copy, so
  concurrent agents would drop each other's sub-modules.
- caw sessions get their cwd from Popen instead of a process-wide
  os.chdir, which concurrent sessions would race on.
- Parent and repository overviews run in a worker thread
  (complete_async) instead of blocking the event loop that running
  agents' Mermaid validation uses.
- The stderr swap around PythonMonkey validation is reference-counted;
  interleaved save/restore could leave stderr on a closed devnull.
- save_json writes atomically, so readers never see half a tree.
- The API-key backend now delegates to sub-agents only when a
  multi-file module also has max_token_per_leaf_module tokens, the same
  gate the caw backend and the sub-module tool use.
- str_replace that empties a file no longer fails the agent with
  AssertionError (1, 0, 1) in expand_window.

Benchmarks (benchmarks/): itsdangerous with claude-code, 9 module
agents + 3 overviews, documentation phase: concurrency 1: 1383 s,
4: 372 s (3.7x), 8: 243 s (5.7x), same page count and size.
replay_schedule.py replays a serial run's log through the scheduler;
for the 7.4 h run it projects 3.8x at 4 and 6.3x at 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The documentation phase is nearly all of a run's time and printed no
progress. After every module, sub-module and overview page it now prints
one status line, in normal and verbose mode:

  ✓ Signing (2m 12s) · 5/12 done (42%) · 4 running · ETA ~4m

- The total grows as agents split modules into sub-modules (both
  backends add to it); "running" counts sessions holding a slot, so a
  parent waiting on its sub-modules is not counted.
- ETA is modules left x average time per module / concurrency, plus the
  remaining usage-limit wait. Pages that already existed (resume) are
  shown as "already documented" and kept out of the average.
- Pauses are reported as they happen, so a waiting run does not look
  hung: caw's subscription usage-limit wait (from its log), and HTTP 429
  from API providers (httpx response hooks on the agent and completion
  clients, noted at most once a minute).
- A summary ends the phase: pages, wall time, failures, rate-limited
  requests and the slowest modules.
- Without --verbose, caw's per-session transcripts and FastMCP's INFO
  session logs are turned off; with concurrent agents they interleaved
  and buried everything else. CAW_LOG=short|full opts back in.

The module list after clustering printed "(? files)" for every module:
it expected a list, but modules are {"components", "children"} dicts.
It now counts distinct source files, sub-modules included.

Adds a test for the pydantic sub-module tool's concurrent fan-out (own
deps per sub-agent, slot cap, progress counts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fails

- ETA uses observed throughput once `concurrency` modules have finished;
  per-module averages counted each parent's whole subtree and slot waits.
- --update prints a status line per leaf and says leaves run one at a
  time (every write set shares overview.md); --concurrency help says so.
- A failed sub-module is logged instead of re-raised, so its parent agent
  still writes its page; the missing child is regenerated on the next run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dandydarshan
dandydarshan merged commit 02569eb into main Oct 18, 2026
13 checks passed
@dandydarshan
dandydarshan deleted the perf/speed-up-generation branch October 18, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant