argus-code-review 0.4.1__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/CHANGELOG.md +7 -0
  2. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/PKG-INFO +1 -1
  3. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/gemini_runner.py +169 -20
  4. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_gemini_runner.py +120 -7
  5. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/.gitignore +0 -0
  6. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/LICENSE +0 -0
  7. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/README.md +0 -0
  8. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/__init__.py +0 -0
  9. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/bench.py +0 -0
  10. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/bench_default.toml +0 -0
  11. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/cli.py +0 -0
  12. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/config.py +0 -0
  13. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/coverage.py +0 -0
  14. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/dotenv_utils.py +0 -0
  15. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/gemini_cache.py +0 -0
  16. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/github_client.py +0 -0
  17. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/graph.py +0 -0
  18. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/helpers.py +0 -0
  19. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/llm/models.py +0 -0
  20. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/llm/output_models.py +0 -0
  21. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/llm/pricing.py +0 -0
  22. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/llm/usage.py +0 -0
  23. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/models.py +0 -0
  24. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/openai_client.py +0 -0
  25. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/openai_runner.py +0 -0
  26. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/pipeline_models.py +0 -0
  27. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/__init__.py +0 -0
  28. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/actions_scanner.py +0 -0
  29. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/engine.py +0 -0
  30. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/eslint_bundle/.gitignore +0 -0
  31. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/eslint_bundle/README.md +0 -0
  32. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/eslint_bundle/eslint.config.js +0 -0
  33. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/eslint_bundle/package-lock.json +0 -0
  34. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/eslint_bundle/package.json +0 -0
  35. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/js_scanner.py +0 -0
  36. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/migration_scanner.py +0 -0
  37. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/rules/README.md +0 -0
  38. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/sarif.py +0 -0
  39. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/scanner_utils.py +0 -0
  40. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/secrets_scanner.py +0 -0
  41. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/shadow.py +0 -0
  42. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/terraform_scanner.py +0 -0
  43. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/precheck/workflow_lint_scanner.py +0 -0
  44. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/__init__.py +0 -0
  45. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-blocking-validator.md +0 -0
  46. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-coverage-check.md +0 -0
  47. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-cross-cutting.md +0 -0
  48. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-feedback-verifier.md +0 -0
  49. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-lite.md +0 -0
  50. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-planner.md +0 -0
  51. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-preflight-router.md +0 -0
  52. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-prior-art.md +0 -0
  53. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-scope.md +0 -0
  54. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-deployment.md +0 -0
  55. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-frontend.md +0 -0
  56. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-infra.md +0 -0
  57. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-llm-patterns.md +0 -0
  58. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-observability.md +0 -0
  59. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-orchestration.md +0 -0
  60. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-security.md +0 -0
  61. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-slackbot.md +0 -0
  62. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-specialist-sql.md +0 -0
  63. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-subagent.md +0 -0
  64. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-tests-and-docs.md +0 -0
  65. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts/pr-review-writer.md +0 -0
  66. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/prompts_runtime.py +0 -0
  67. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/repo_provision.py +0 -0
  68. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/review_tools.py +0 -0
  69. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/runners.py +0 -0
  70. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/scope.py +0 -0
  71. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/__init__.py +0 -0
  72. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/http.py +0 -0
  73. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/models.py +0 -0
  74. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/precheck.py +0 -0
  75. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/resolver.py +0 -0
  76. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/session.py +0 -0
  77. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/sql.py +0 -0
  78. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/argus/storage/sqlite.py +0 -0
  79. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/pyproject.toml +0 -0
  80. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/008_add_code_reviews.sql +0 -0
  81. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/009_add_reviewer_version.sql +0 -0
  82. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/010_add_review_patterns.sql +0 -0
  83. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/011_add_review_progress_columns.sql +0 -0
  84. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/015_create_agent_runs.sql +0 -0
  85. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/016_add_agent_runs_failure_reason.sql +0 -0
  86. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/017_add_precheck_rules.sql +0 -0
  87. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/schema/018_widen_agent_runs_failure_reason.sql +0 -0
  88. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/__init__.py +0 -0
  89. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/conftest.py +0 -0
  90. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/golden/review_response.schema.json +0 -0
  91. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/__init__.py +0 -0
  92. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_backend_contract.py +0 -0
  93. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_http.py +0 -0
  94. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_models.py +0 -0
  95. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_resolver.py +0 -0
  96. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_session.py +0 -0
  97. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_sql.py +0 -0
  98. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/storage/test_sqlite_backend.py +0 -0
  99. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_actions_scanner.py +0 -0
  100. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_argus_review_local.py +0 -0
  101. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_bench.py +0 -0
  102. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_bench_config_guard.py +0 -0
  103. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_catchup_gate.py +0 -0
  104. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_cli_args.py +0 -0
  105. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_cli_output_contract.py +0 -0
  106. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_cli_post_review.py +0 -0
  107. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_cli_preflight.py +0 -0
  108. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_cli_prompts.py +0 -0
  109. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_config.py +0 -0
  110. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_conftest.py +0 -0
  111. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_dotenv_utils.py +0 -0
  112. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_failure_diagnostics.py +0 -0
  113. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_gemini_cache.py +0 -0
  114. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_gemini_http_retry.py +0 -0
  115. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_github_client_checks_signal.py +0 -0
  116. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_github_client_write.py +0 -0
  117. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_fetch_diff.py +0 -0
  118. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_get_llm_temperature.py +0 -0
  119. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_http_guards.py +0 -0
  120. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_precheck.py +0 -0
  121. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_preflight_image_bump.py +0 -0
  122. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_progress.py +0 -0
  123. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_storage_resolution.py +0 -0
  124. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_graph_timeout_surfacing.py +0 -0
  125. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_js_scanner.py +0 -0
  126. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_llm_models.py +0 -0
  127. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_llm_models_override.py +0 -0
  128. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_llm_pricing.py +0 -0
  129. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_migration_scanner.py +0 -0
  130. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_models.py +0 -0
  131. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_multi_round.py +0 -0
  132. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_openai_client.py +0 -0
  133. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_openai_runner.py +0 -0
  134. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_output_models.py +0 -0
  135. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_packaging.py +0 -0
  136. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_plan_review.py +0 -0
  137. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_precheck_engine.py +0 -0
  138. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_precheck_engine_integration.py +0 -0
  139. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_precheck_sarif.py +0 -0
  140. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_precheck_shadow.py +0 -0
  141. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_precheck_shadow_integration.py +0 -0
  142. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_prompts.py +0 -0
  143. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_repo_provision.py +0 -0
  144. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_review_patterns_integration.py +0 -0
  145. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_review_tools.py +0 -0
  146. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_runners_context7.py +0 -0
  147. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_runners_context_usage.py +0 -0
  148. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_runners_helpers.py +0 -0
  149. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_runners_new.py +0 -0
  150. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_runners_turn_budget.py +0 -0
  151. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_scanner_utils.py +0 -0
  152. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_scope.py +0 -0
  153. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_scope_gate.py +0 -0
  154. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_sdk_bundled_cli_version.py +0 -0
  155. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_secrets_scanner.py +0 -0
  156. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_specialist_validation.py +0 -0
  157. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_stage_costs.py +0 -0
  158. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_storage_precheck.py +0 -0
  159. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_structured_output_methods.py +0 -0
  160. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_terraform_scanner.py +0 -0
  161. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_terraform_scanner_integration.py +0 -0
  162. {argus_code_review-0.4.1 → argus_code_review-0.4.2}/tests/test_workflow_lint_scanner.py +0 -0
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.2] - 2026-10-29
11
+
12
+ ### Changed
13
+
14
+ - A Gemini `400 INVALID_ARGUMENT` no longer ends the reviewer session on the first occurrence. Argus now logs a key-free, text-free summary of the failing request (message count, approximate size, part kinds and sizes for the last four turns, and anomalies such as empty parts or function calls with no matching result) plus any error `details` the API returned, then retries the same request once after a short pause (`ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S` / `_MAX_S`, default 2-5 s). The log records whether the retry recovered, which separates a transient fault from a malformed request. Other 4xx errors still fail immediately.
15
+
10
16
  ## [0.4.1] - 2026-10-28
11
17
 
12
18
  ### Fixed
@@ -470,6 +476,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
470
476
  - `argus --version`, `argus prompts list`, and `argus prompts export`.
471
477
 
472
478
  [Unreleased]: https://github.com/redesignhealth/argus-review/compare/v0.4.1...HEAD
479
+ [0.4.2]: https://github.com/redesignhealth/argus-review/compare/v0.4.1...v0.4.2
473
480
  [0.4.1]: https://github.com/redesignhealth/argus-review/compare/v0.4.0...v0.4.1
474
481
  [0.4.0]: https://github.com/redesignhealth/argus-review/compare/v0.3.4...v0.4.0
475
482
  [0.3.4]: https://github.com/redesignhealth/argus-review/compare/v0.3.3...v0.3.4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argus-code-review
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Self-orchestrated PR review agent using LangGraph + Claude Agent SDK
5
5
  Project-URL: Repository, https://github.com/redesignhealth/argus-review
6
6
  Project-URL: Issues, https://github.com/redesignhealth/argus-review/issues
@@ -426,6 +426,113 @@ def _failure_detail(exc: BaseException) -> str:
426
426
  return detail
427
427
 
428
428
 
429
+ _INVALID_ARGUMENT_RETRY_MIN_S = 2.0
430
+ _INVALID_ARGUMENT_RETRY_MAX_S = 5.0
431
+ _SHAPE_TAIL_CONTENTS = 4
432
+
433
+
434
+ def _is_invalid_argument(exc: BaseException) -> bool:
435
+ """True for a Gemini ``400 INVALID_ARGUMENT`` API answer."""
436
+ code, status = _error_code_status(exc)
437
+ return code == 400 and (status or "").upper() == "INVALID_ARGUMENT"
438
+
439
+
440
+ def _part_shape(part: Any) -> str:
441
+ """Kind and size of one content part -- never its text."""
442
+ call = getattr(part, "function_call", None)
443
+ if call is not None:
444
+ size = len(json.dumps(call.args or {}, default=str))
445
+ return f"call:{call.name}({size})"
446
+ resp = getattr(part, "function_response", None)
447
+ if resp is not None:
448
+ # An empty result reports size 0 so _describe_request can flag it. The
449
+ # runner wraps every tool output as {"result": output}, so unwrap it.
450
+ payload = resp.response
451
+ if isinstance(payload, dict) and set(payload) == {"result"}:
452
+ payload = payload["result"]
453
+ size = len(json.dumps(payload, default=str)) if payload else 0
454
+ return f"result:{resp.name}({size})"
455
+ text = getattr(part, "text", None)
456
+ if text is not None:
457
+ tag = "thought" if getattr(part, "thought", False) else "text"
458
+ return f"{tag}({len(text)})"
459
+ return type(part).__name__
460
+
461
+
462
+ def _describe_request(contents: list[Any], config: Any = None) -> str:
463
+ """Key-free, text-free summary of a request for diagnosing a 400.
464
+
465
+ Gemini's INVALID_ARGUMENT body carries no field name, so this records the
466
+ structure that could make a request malformed: roles, part kinds and sizes
467
+ for the last few turns, plus anomalies (empty parts, unanswered function
468
+ calls, consecutive same-role turns).
469
+ """
470
+ total = 0
471
+ biggest = 0
472
+ anomalies: list[str] = []
473
+ prev_role = None
474
+ for i, content in enumerate(contents):
475
+ parts = list(content.parts or [])
476
+ if not parts:
477
+ anomalies.append(f"empty-content@{i}")
478
+ calls = results = 0
479
+ for part in parts:
480
+ shape = _part_shape(part)
481
+ size = int(m.group(1)) if (m := re.search(r"\((\d+)\)$", shape)) else 0
482
+ total += size
483
+ biggest = max(biggest, size)
484
+ if shape.startswith("call:"):
485
+ calls += 1
486
+ elif shape.startswith("result:"):
487
+ results += 1
488
+ if size == 0 and shape.startswith(("text", "thought", "result")):
489
+ anomalies.append(f"zero-size-{re.split(r'[:(]', shape)[0]}@{i}")
490
+ if prev_role is not None and content.role == prev_role:
491
+ anomalies.append(f"repeated-role-{content.role}@{i}")
492
+ prev_role = content.role
493
+ nxt = contents[i + 1] if i + 1 < len(contents) else None
494
+ if calls and nxt is not None:
495
+ answered = sum(
496
+ 1 for p in (nxt.parts or []) if getattr(p, "function_response", None) is not None
497
+ )
498
+ if answered != calls:
499
+ anomalies.append(f"calls({calls})!=results({answered})@{i}")
500
+ tail = contents[-_SHAPE_TAIL_CONTENTS:]
501
+ first = len(contents) - len(tail)
502
+ tail_desc = "; ".join(
503
+ f"#{first + j} {c.role}[{', '.join(_part_shape(p) for p in (c.parts or []))}]"
504
+ for j, c in enumerate(tail)
505
+ )
506
+ cfg = ""
507
+ if config is not None:
508
+ cfg = (
509
+ f" tools={len(getattr(config, 'tools', None) or [])}"
510
+ f" system_instruction={bool(getattr(config, 'system_instruction', None))}"
511
+ f" cached_content={bool(getattr(config, 'cached_content', None))}"
512
+ )
513
+ return (
514
+ f"contents={len(contents)} approx_chars={total} largest_part={biggest}{cfg} "
515
+ f"anomalies={anomalies or 'none'} tail: {tail_desc}"
516
+ )
517
+
518
+
519
+ def _safe_describe_request(contents: list[Any], config: Any) -> str:
520
+ """``_describe_request`` that can never mask the error being diagnosed."""
521
+ try:
522
+ return _describe_request(contents, config)
523
+ except Exception as exc: # noqa: BLE001 - diagnostics must not replace the 400
524
+ return f"unavailable ({type(exc).__name__})"
525
+
526
+
527
+ def _error_details(exc: BaseException) -> str:
528
+ """Scrubbed ``details`` payload of an API error (may name the bad field)."""
529
+ details = getattr(exc, "details", None)
530
+ try:
531
+ return _scrub(json.dumps(details, default=str)) if details else ""
532
+ except (TypeError, ValueError):
533
+ return ""
534
+
535
+
429
536
  # Matches the fenced-json extraction argus.helpers.parse_review_result
430
537
  # already applies for the Claude path.
431
538
  _FENCED_JSON_RE = re.compile(r"```(?:json)?\s*(\{.*?\})\s*```", re.DOTALL)
@@ -965,26 +1072,68 @@ async def _run_turns(
965
1072
  _turn,
966
1073
  _scrub(str(exc)),
967
1074
  )
968
- raise
969
- logger.warning(
970
- "Gemini cache [%s] appears invalid upstream (role=%s); "
971
- "invalidating the local record and retrying this turn "
972
- "uncached: %s",
973
- label or "unlabeled",
974
- entry.role,
975
- exc,
976
- )
977
- await asyncio.to_thread(
978
- _invalidate_cache_record,
979
- entry=entry,
980
- model=model,
981
- system_prompt=system_prompt,
982
- )
983
- cached_content_name = None
984
- config = _build_config(None)
985
- response = await client.aio.models.generate_content(
986
- model=model, contents=contents, config=config
987
- )
1075
+ if not _is_invalid_argument(exc):
1076
+ raise
1077
+ # A 400 INVALID_ARGUMENT names no field, so record the
1078
+ # request's shape, then retry this SAME request once:
1079
+ # whether it recovers tells a transient fault from a
1080
+ # deterministic one.
1081
+ logger.error(
1082
+ "Gemini 400 request shape [%s] (turn=%d) details=%s: %s",
1083
+ label or "unlabeled",
1084
+ _turn,
1085
+ _error_details(exc) or "none",
1086
+ _safe_describe_request(contents, config),
1087
+ )
1088
+ lo = _env_float(
1089
+ "ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S",
1090
+ _INVALID_ARGUMENT_RETRY_MIN_S,
1091
+ )
1092
+ hi = _env_float(
1093
+ "ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MAX_S",
1094
+ _INVALID_ARGUMENT_RETRY_MAX_S,
1095
+ )
1096
+ await asyncio.sleep(
1097
+ random.uniform(lo, max(lo, hi)) # noqa: S311 - jitter, not security
1098
+ )
1099
+ try:
1100
+ response = await client.aio.models.generate_content(
1101
+ model=model, contents=contents, config=config
1102
+ )
1103
+ except Exception as retry_exc:
1104
+ logger.error(
1105
+ "Gemini 400 retry failed [%s] (turn=%d): %s",
1106
+ label or "unlabeled",
1107
+ _turn,
1108
+ _scrub(str(retry_exc)),
1109
+ )
1110
+ raise
1111
+ logger.warning(
1112
+ "Gemini 400 recovered on retry [%s] (turn=%d): the failure "
1113
+ "was transient, not a malformed request",
1114
+ label or "unlabeled",
1115
+ _turn,
1116
+ )
1117
+ else:
1118
+ logger.warning(
1119
+ "Gemini cache [%s] appears invalid upstream (role=%s); "
1120
+ "invalidating the local record and retrying this turn "
1121
+ "uncached: %s",
1122
+ label or "unlabeled",
1123
+ entry.role,
1124
+ exc,
1125
+ )
1126
+ await asyncio.to_thread(
1127
+ _invalidate_cache_record,
1128
+ entry=entry,
1129
+ model=model,
1130
+ system_prompt=system_prompt,
1131
+ )
1132
+ cached_content_name = None
1133
+ config = _build_config(None)
1134
+ response = await client.aio.models.generate_content(
1135
+ model=model, contents=contents, config=config
1136
+ )
988
1137
 
989
1138
  progress.responses += 1
990
1139
  usage = response.usage_metadata
@@ -33,7 +33,12 @@ from google.genai import errors as genai_errors # noqa: E402
33
33
  from google.genai import types # noqa: E402
34
34
 
35
35
  from argus.bench import BenchEntry # noqa: E402
36
- from argus.gemini_runner import _MAX_TURNS_GEMINI, run_session_gemini # noqa: E402
36
+ from argus.gemini_runner import ( # noqa: E402
37
+ _MAX_TURNS_GEMINI,
38
+ _describe_request,
39
+ _safe_describe_request,
40
+ run_session_gemini,
41
+ )
37
42
  from argus.llm.models import resolve as resolve_alias # noqa: E402
38
43
  from argus.runners import _TURN_BUDGET_SYSTEM_PROMPT_LINE # noqa: E402
39
44
 
@@ -65,7 +70,7 @@ def _isolate_gemini_cache_dir(tmp_path: Any, monkeypatch: pytest.MonkeyPatch) ->
65
70
 
66
71
  monkeypatch.setenv("ARGUS_GEMINI_CACHE_DIR", str(tmp_path / "gemini-cache"))
67
72
  # Existing tests must not sleep through the real retry cooldown.
68
- for name in ("RATE_LIMIT", "COOLDOWN"):
73
+ for name in ("RATE_LIMIT", "COOLDOWN", "INVALID_ARGUMENT"):
69
74
  monkeypatch.setenv(f"ARGUS_GEMINI_RETRY_{name}_MIN_S", "0")
70
75
  monkeypatch.setenv(f"ARGUS_GEMINI_RETRY_{name}_MAX_S", "0")
71
76
  clear_settings_cache()
@@ -1601,10 +1606,13 @@ class TestCacheInvalidatedUpstreamDegradesGracefully:
1601
1606
  repo_root="/tmp/does-not-need-to-exist",
1602
1607
  )
1603
1608
 
1604
- # Not retried uncached (that would mean 2 awaits, as in the
1605
- # cache-invalid-recovery test above) -- the error propagated
1606
- # straight out of the cache-retry logic on the first attempt.
1607
- assert fake_client.aio.models.generate_content.await_count == 1
1609
+ # Not retried uncached: the one retry a 400 INVALID_ARGUMENT gets
1610
+ # re-sends the exact same request (cache reference included), unlike
1611
+ # the cache-invalid-recovery test above, which drops the cache.
1612
+ calls = fake_client.aio.models.generate_content.await_args_list
1613
+ assert len(calls) == 2
1614
+ assert calls[0].kwargs["config"].cached_content == "cachedContents/abc123"
1615
+ assert calls[1].kwargs["config"].cached_content == "cachedContents/abc123"
1608
1616
  assert result.failure_reason == "worker_crashed"
1609
1617
  assert result.result_text == ""
1610
1618
 
@@ -1807,7 +1815,7 @@ class TestTransientRetry:
1807
1815
  [
1808
1816
  (401, "UNAUTHENTICATED"),
1809
1817
  (403, "PERMISSION_DENIED"),
1810
- (400, "INVALID_ARGUMENT"),
1818
+ (400, "FAILED_PRECONDITION"),
1811
1819
  (404, "NOT_FOUND"),
1812
1820
  ],
1813
1821
  )
@@ -1818,6 +1826,49 @@ class TestTransientRetry:
1818
1826
  assert result.failure_reason == "worker_crashed"
1819
1827
  assert result.failure_detail == f"{code} {status}, turn 0"
1820
1828
 
1829
+ async def test_invalid_argument_logs_request_shape_and_retries_once(
1830
+ self, caplog: pytest.LogCaptureFixture
1831
+ ) -> None:
1832
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1833
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1834
+ with caplog.at_level("INFO", logger="argus.gemini_runner"):
1835
+ result = await _run(client)
1836
+ assert result.failure_reason is None
1837
+ assert client.aio.models.generate_content.await_count == 2
1838
+ messages = [r.message for r in caplog.records]
1839
+ assert any("Gemini 400 request shape [retry-test] (turn=0)" in m for m in messages)
1840
+ assert any("Gemini 400 recovered on retry [retry-test]" in m for m in messages)
1841
+
1842
+ async def test_describer_failure_does_not_skip_the_retry(self) -> None:
1843
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1844
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1845
+ with patch("argus.gemini_runner._describe_request", side_effect=ValueError("odd args")):
1846
+ result = await _run(client)
1847
+ assert result.failure_reason is None
1848
+ assert client.aio.models.generate_content.await_count == 2
1849
+
1850
+ async def test_inverted_retry_bounds_do_not_crash(
1851
+ self, monkeypatch: pytest.MonkeyPatch
1852
+ ) -> None:
1853
+ monkeypatch.setenv("ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S", "0.02")
1854
+ monkeypatch.setenv("ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MAX_S", "0")
1855
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1856
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1857
+ result = await _run(client)
1858
+ assert result.failure_reason is None
1859
+
1860
+ async def test_invalid_argument_failing_twice_fails_session_after_one_retry(
1861
+ self, caplog: pytest.LogCaptureFixture
1862
+ ) -> None:
1863
+ err = _api_error(400, "INVALID_ARGUMENT")
1864
+ client = _make_fake_client([err, err, err])
1865
+ with caplog.at_level("INFO", logger="argus.gemini_runner"):
1866
+ result = await _run(client)
1867
+ assert client.aio.models.generate_content.await_count == 2
1868
+ assert result.failure_reason == "worker_crashed"
1869
+ assert result.failure_detail == "400 INVALID_ARGUMENT, turn 0"
1870
+ assert any("Gemini 400 retry failed [retry-test]" in r.message for r in caplog.records)
1871
+
1821
1872
  async def test_httpx_connect_error_is_retried(self) -> None:
1822
1873
  ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1823
1874
  client = _make_fake_client([httpx.ConnectError("reset"), ok])
@@ -1988,3 +2039,65 @@ class TestTransientRetry:
1988
2039
  text = " ".join(r.getMessage() for r in caplog.records)
1989
2040
  assert secret not in text
1990
2041
  assert len(text) < 1200
2042
+
2043
+
2044
+ class TestDescribeRequest:
2045
+ async def test_summarises_shape_without_leaking_text(self) -> None:
2046
+ contents = [
2047
+ types.Content(role="user", parts=[types.Part.from_text(text="SECRETBODY" * 50)]),
2048
+ types.Content(
2049
+ role="model",
2050
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2051
+ ),
2052
+ types.Content(role="user", parts=[types.Part.from_text(text="")]),
2053
+ ]
2054
+ out = _describe_request(contents)
2055
+ assert "SECRETBODY" not in out
2056
+ assert "contents=3" in out
2057
+ assert "call:grep(" in out
2058
+ assert "calls(1)!=results(0)@1" in out # the call was never answered
2059
+ assert "zero-size-text@2" in out
2060
+
2061
+ async def test_clean_request_reports_no_anomalies(self) -> None:
2062
+ contents = [
2063
+ types.Content(role="user", parts=[types.Part.from_text(text="hi")]),
2064
+ types.Content(
2065
+ role="model",
2066
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2067
+ ),
2068
+ types.Content(
2069
+ role="user",
2070
+ parts=[types.Part.from_function_response(name="grep", response={"output": "ok"})],
2071
+ ),
2072
+ ]
2073
+ assert "anomalies=none" in _describe_request(contents)
2074
+
2075
+ async def test_empty_tool_result_is_flagged(self) -> None:
2076
+ contents = [
2077
+ types.Content(
2078
+ role="model",
2079
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2080
+ ),
2081
+ types.Content(
2082
+ role="user",
2083
+ parts=[types.Part.from_function_response(name="grep", response={})],
2084
+ ),
2085
+ ]
2086
+ assert "zero-size-result@1" in _describe_request(contents)
2087
+
2088
+ async def test_empty_wrapped_tool_result_is_flagged(self) -> None:
2089
+ contents = [
2090
+ types.Content(
2091
+ role="user",
2092
+ parts=[types.Part.from_function_response(name="grep", response={"result": ""})],
2093
+ ),
2094
+ ]
2095
+ assert "zero-size-result@0" in _describe_request(contents)
2096
+
2097
+ async def test_first_turn_without_role_is_not_a_repeat(self) -> None:
2098
+ contents = [types.Content(role=None, parts=[types.Part.from_text(text="hi")])]
2099
+ assert "repeated-role" not in _describe_request(contents)
2100
+
2101
+ async def test_safe_describe_never_raises(self) -> None:
2102
+ out = _safe_describe_request(object(), None)
2103
+ assert out.startswith("unavailable (")