Skip to content

fix: raise pydantic-ai request_limit for complex modules and make it configurable - #115

Closed
fabceolin wants to merge 2 commits into
FSoft-AI4Code:mainfrom
fabceolin:fix/request-limit-complex-modules
Closed

fabceolin wants to merge 2 commits into
FSoft-AI4Code:mainfrom
fabceolin:fix/request-limit-complex-modules

Conversation

@fabceolin

@fabceolin fabceolin commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

pydantic-ai's own default (UsageLimits(request_limit=50)) is too low for "complex" modules whose agent loop reads several code components and/or spins off sub-module docs via generate_sub_module_documentation_tool.

On a real-world run (voll-intelligence, a 5,381-file TypeScript monorepo, 16,720 functions), 4 modules hit UsageLimitExceeded mid-run and were skipped outright:

ERROR    Failed to process module app_integration_bff/app_integration_travel_search: The next request would exceed the request_limit of 50.

No retry, no fallback to the configured fallback-model, and no CLI flag to raise the limit.

Fix

  1. Raise the default limit to 100 via UsageLimits(request_limit=100), passed explicitly to both agent.run(...) call sites in pydantic_ai_backend.py (run_update_agent and run_module_agent).
  2. Make the limit a real, first-class configuration knob instead of a hardcoded constant — some repos/modules need more than 100 requests per agent run. request_limit now follows the exact same pattern as the other generation knobs (max_tokens, max_token_per_module, ...):
    • Config.request_limit in the backend (codewiki/src/config.py), default DEFAULT_REQUEST_LIMIT = 100
    • --request-limit on codewiki generate and codewiki config set
    • persisted in ~/.codewiki/config.json, shown in codewiki config show (text and --json)

Usage

# One-off override for this run
codewiki generate --request-limit 200

# Persist a higher default
codewiki config set --request-limit 200
codewiki config show

Validation

  • All 4 modules that previously failed with request_limit=50 succeeded on the exact same input once the limit was raised to 100, with no other change.
  • Config.from_cli(...) with and without a request_limit override; PydanticAIBackend._agent_usage_limits picks up the configured value.
  • Configuration.to_dict/from_dict/to_backend_config round-trip for request_limit.
  • codewiki config set --request-limit N + codewiki config show end-to-end (isolated HOME).
  • codewiki generate --help shows the new flag; invalid (< 1) values are rejected the same way as the sibling max_* options.

🤖 Generated with Claude Code

pydantic-ai's own default (UsageLimits(request_limit=50)) is too low for
"complex" modules whose agent loop reads several code components and/or
spins off sub-module docs via generate_sub_module_documentation_tool.

On a real-world run (voll-intelligence, a 5,381-file TypeScript monorepo,
16,720 functions), 4 modules hit UsageLimitExceeded mid-run and were
skipped outright — no retry, no fallback to the configured fallback-model,
and no CLI flag to raise the limit. All 4 succeeded on the same input once
the limit was raised to 100, with no other change.
@fabceolin
fabceolin marked this pull request as draft September 25, 2026 11:53
The previous commit fixed UsageLimitExceeded on complex modules by raising
pydantic-ai's request_limit from 50 (its own default) to 100, but hardcoded
the new value with no way to tune it. Some repos/modules need more than
100 requests per agent run, so expose it the same way as the other
generation knobs (max_tokens, max_token_per_module, ...):

- Config.request_limit (backend), default DEFAULT_REQUEST_LIMIT = 100
- --request-limit on `codewiki generate` and `codewiki config set`
- persisted in ~/.codewiki/config.json, shown in `codewiki config show`
@fabceolin fabceolin changed the title fix: raise pydantic-ai request_limit from 50 to 100 for complex modules fix: raise pydantic-ai request_limit for complex modules and make it configurable Sep 25, 2026
@anhnh2002 anhnh2002 closed this Sep 29, 2026
@anhnh2002

Copy link
Copy Markdown
Collaborator

fixed at #121

pull Bot pushed a commit to soitun/CodeWiki that referenced this pull request Sep 29, 2026
…ons, ship updater

- Package: add codewiki.src.be.updater to [tool.setuptools] packages; a
  non-editable install had no updater, so every --update failed on import.
  New test checks every package directory is listed. (FSoft-AI4Code#119)
- Agent limits: pass UsageLimits(request_limit=...) to every agent run and
  retries=... to every Agent. pydantic-ai defaults are 50 requests per run and
  1 retry per failing tool call, which complex modules and
  generate_sub_module_documentation hit. New settings request_limit (default
  100) and agent_retries (default 3), in `codewiki config set`, `config show`
  and as per-run overrides on `codewiki generate`. (FSoft-AI4Code#115, FSoft-AI4Code#118)
- Fallback: FallbackModel now also falls back on UnexpectedModelBehavior (a 200
  response whose body does not parse), keeping ModelAPIError. (FSoft-AI4Code#117)
- Overview pages: MODULE_OVERVIEW_PROMPT / REPO_OVERVIEW_PROMPT had no slot for
  the user's instructions. complete() takes an optional system_prompt (OpenAI-
  compatible, litellm, Azure, and caw via CawAgent(system_prompt=...)), and
  parent/repo overviews send the instructions as a system message. (FSoft-AI4Code#116)
- Sub-module agents built their system prompt with a raw .format(), so with no
  instructions the prompt ended in the literal text "None"; they now use
  format_system_prompt / format_leaf_system_prompt like the top-level agents.

Reported in FSoft-AI4Code#115, FSoft-AI4Code#116, FSoft-AI4Code#117, FSoft-AI4Code#118, FSoft-AI4Code#119.
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.

2 participants