Repository navigation
feat(cli): add a doctor command to preflight the deployment - #4321
Conversation
A misconfigured deployment only fails at the end of a full run: the runner warns about a missing key, carries on, and every tool call then fails against the placeholder (The-PR-Agent#4320, the dummy_key sample in The-PR-Agent#4195). `pr-agent doctor` runs without a PR or diff and never touches a git provider. It checks that config.model is set, that the active provider has a real key (env or settings, never printed), and that a one-token completion against the configured model succeeds, printing one line per check. The exit code is 0 only when every check passes, so CI setups can gate on it.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
⚙️ Agent run details
|
PR Code Suggestions ✨Explore these optional code suggestions:
⚙️ Agent run details
|
fbe80b5 to
47b3c46
Compare
Two /improve findings: ping failures can quote credentials (request URLs, echoed bodies) into stdout and debug logs - route the reason and the debug repr through redact_credentials instead, keeping the failure text diagnosable; and unprefixed models are not always OpenAI's - litellm resolves claude-*, gemini-* itself, so ask its resolver for the provider and defer unresolvable ids to the ping.
47b3c46 to
0971919
Compare
|
Both adopted in 0971919, with one substitution: the failure reason goes through the repo's |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for turning #4320 into a working command so quickly, with the key never printed and the error text redacted. One fix before merge: with openai.api_base set, as with any OpenAI-compatible gateway, the handler keeps the key under openai, but doctor looks under custom_openai, so a working gateway fails the key check and exits 1. Inline below; with both suggestions the doctor tests and the full suite pass.
The bot's unbounded-probe finding is fine for a command run by hand. This won't reach the #4195 runs on its own, since those were Action runs with no key; would you be up for a follow-up where the Action runner stops on a failed key check instead of carrying on with the placeholder?
With openai.api_base set, LiteLLMHandler captures the key under 'openai', but doctor resolved the provider to 'custom_openai' and the key check missed it - a working OpenAI-compatible gateway failed and exited 1. Drop the branch: litellm's resolver already returns 'openai' for gpt-* ids, and unknown ids defer to the ping.
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround and for taking on the runner follow-up; approving and merging.
User description
Problem
A misconfigured deployment only fails at the end of a full run. In the sample from #4195, 20 of 81 owners running the action publicly failed with
Incorrect API key provided: dummy_key: the runner warnsOPENAI_KEY not setand carries on, and every tool call then fails against the placeholder. Wrong base URLs and quota errors surface the same way, one full run later (#4320).The existing
tests.health_test.mainneeds a repository checkout (it is not shipped), a GitHub token, and real PRs — there is nothing lightweight to gate a setup with.Solution
pr-agent doctor— runs without--pr_urlor a diff, never touches a git provider:config.modelis set_captured_api_key, the same source a run uses; the value is never printed; providers unknown to the env table, i.e. keyless auth, defer to the ping)LiteLLMAIHandler.chat_completionpathOne line per check on stdout; exit code 0 only when everything passes, so CI setups can gate on it. No new settings; no existing command changes (
doctorjoins only the CLI choices, not the agent dispatch).Testing
doctornever constructsPRAgent(asserted), and the key value never appears in the output.Fixes #4320
PR Type
Enhancement, Tests, Documentation
Description
Add standalone
pr-agent doctordeployment checks.Validate model configuration, credentials, and endpoint connectivity.
Report check results with CI-friendly exit codes.
Document usage and test diagnostic behavior.
Diagram Walkthrough
File Walkthrough
cli.py
Integrate standalone doctor command into CLIpr_agent/cli.py
doctorto CLI command choices and help text.processing.
PRAgent.doctor.py
Add deployment configuration and connectivity diagnosticspr_agent/doctor.py
placeholder keys.
LiteLLMAIHandler.chat_completionandreport failures.
test_cli_doctor.py
Test doctor diagnostics and standalone executiontests/unittest/test_cli_doctor.py
and completion failures.
PRAgentconstruction.automations_and_usage.md
Document doctor usage and health-check differencesdocs/docs/usage-guide/automations_and_usage.md
pr-agent doctorunder CLI health checks.health checks.
⚙️ Agent run details