bugbug 0.0.662__tar.gz → 0.0.663__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 (193) hide show
  1. {bugbug-0.0.662 → bugbug-0.0.663}/PKG-INFO +4 -4
  2. bugbug-0.0.663/VERSION +1 -0
  3. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/repository.py +10 -0
  4. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/agent.py +27 -5
  5. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/data_types.py +5 -20
  6. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/langchain_tools.py +33 -8
  7. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/prompts.py +10 -0
  8. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/review_context.py +6 -17
  9. bugbug-0.0.663/bugbug/tools/code_review/stack.py +166 -0
  10. bugbug-0.0.663/bugbug/tools/core/connection.py +113 -0
  11. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/platforms/base.py +33 -6
  12. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/platforms/phabricator.py +253 -166
  13. {bugbug-0.0.662 → bugbug-0.0.663}/pyproject.toml +7 -7
  14. bugbug-0.0.662/VERSION +0 -1
  15. bugbug-0.0.662/bugbug/tools/core/connection.py +0 -47
  16. {bugbug-0.0.662 → bugbug-0.0.663}/.gitignore +0 -0
  17. {bugbug-0.0.662 → bugbug-0.0.663}/LICENSE +0 -0
  18. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/__init__.py +0 -0
  19. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/bug_features.py +0 -0
  20. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/bug_snapshot.py +0 -0
  21. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/bugzilla.py +0 -0
  22. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/build_platforms.py +0 -0
  23. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/__init__.py +0 -0
  24. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/function_search.py +0 -0
  25. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/mozilla.py +0 -0
  26. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/parser.py +0 -0
  27. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/searchfox_api.py +0 -0
  28. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/searchfox_data.py +0 -0
  29. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/code_search/searchfox_download.py +0 -0
  30. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/commit_features.py +0 -0
  31. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/db.py +0 -0
  32. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/feature_cleanup.py +0 -0
  33. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/github.py +0 -0
  34. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/issue_features.py +0 -0
  35. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/issue_snapshot.py +0 -0
  36. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/annotateignore.csv +0 -0
  37. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/bug_nobug.csv +0 -0
  38. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/defect_enhancement_task.csv +0 -0
  39. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/defect_enhancement_task_e.csv +0 -0
  40. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/defect_enhancement_task_h.csv +0 -0
  41. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/defect_enhancement_task_p.csv +0 -0
  42. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/defect_enhancement_task_s.csv +0 -0
  43. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/regression_bug_nobug.csv +0 -0
  44. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/regressionrange.csv +0 -0
  45. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/str.csv +0 -0
  46. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels/tracking.csv +0 -0
  47. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/labels.py +0 -0
  48. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/model.py +0 -0
  49. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/model_calibration.py +0 -0
  50. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/__init__.py +0 -0
  51. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/accessibility.py +0 -0
  52. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/annotate_ignore.py +0 -0
  53. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/assignee.py +0 -0
  54. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/backout.py +0 -0
  55. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/browsername.py +0 -0
  56. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/bugtype.py +0 -0
  57. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/component.py +0 -0
  58. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/component_specific.py +0 -0
  59. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/defect.py +0 -0
  60. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/defect_enhancement_task.py +0 -0
  61. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/devdocneeded.py +0 -0
  62. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/fenixcomponent.py +0 -0
  63. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/fixtime.py +0 -0
  64. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/invalid_compatibility_report.py +0 -0
  65. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/needsdiagnosis.py +0 -0
  66. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/perf_regression_predictor.py +0 -0
  67. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/performancebug.py +0 -0
  68. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/qaneeded.py +0 -0
  69. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/rcatype.py +0 -0
  70. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/regression.py +0 -0
  71. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/regressionrange.py +0 -0
  72. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/regressor.py +0 -0
  73. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/severity.py +0 -0
  74. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/spambug.py +0 -0
  75. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/stepstoreproduce.py +0 -0
  76. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/testconfigdimensions.py +0 -0
  77. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/testconfigselect.py +0 -0
  78. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/testfailure.py +0 -0
  79. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/testselect.py +0 -0
  80. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/tracking.py +0 -0
  81. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/uplift.py +0 -0
  82. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/models/worksforme.py +0 -0
  83. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/nlp.py +0 -0
  84. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/__init__.py +0 -0
  85. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/calibration.py +0 -0
  86. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/commit_risk.py +0 -0
  87. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/datasets.py +0 -0
  88. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/extraction.py +0 -0
  89. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/label_policy.py +0 -0
  90. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/push_status.py +0 -0
  91. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/regression_commits.py +0 -0
  92. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/regression_labeling.py +0 -0
  93. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/selection_pairs.py +0 -0
  94. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/__init__.py +0 -0
  95. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/capacity.py +0 -0
  96. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/detection.py +0 -0
  97. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/metrics.py +0 -0
  98. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/optimize.py +0 -0
  99. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/splits.py +0 -0
  100. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/stats.py +0 -0
  101. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/strategies.py +0 -0
  102. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/simulation/timeline.py +0 -0
  103. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/__init__.py +0 -0
  104. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_alerts.sql +0 -0
  105. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_background.sql +0 -0
  106. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_builds.sql +0 -0
  107. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_eligible.sql +0 -0
  108. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_labels.sql +0 -0
  109. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_pools.sql +0 -0
  110. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_capacity_workers.sql +0 -0
  111. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_pushes.sql +0 -0
  112. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_task_costs.sql +0 -0
  113. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/sql/perf_task_filter.sql +0 -0
  114. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/task_costs.py +0 -0
  115. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/perf/task_labels.py +0 -0
  116. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/phabricator.py +0 -0
  117. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/redash.py +0 -0
  118. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/rust_code_analysis_server.py +0 -0
  119. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/sklearn_utils.py +0 -0
  120. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/swarm.py +0 -0
  121. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/test_scheduling.py +0 -0
  122. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/test_scheduling_features.py +0 -0
  123. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/__init__.py +0 -0
  124. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/base.py +0 -0
  125. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/__init__.py +0 -0
  126. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/database.py +0 -0
  127. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/protocols.py +0 -0
  128. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/review_context_schema.py +0 -0
  129. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/scorer.py +0 -0
  130. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/code_review/utils.py +0 -0
  131. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/comment_matching/agent.py +0 -0
  132. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/comment_matching/prompts.py +0 -0
  133. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/comment_resolution/__init__.py +0 -0
  134. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/comment_resolution/agent.py +0 -0
  135. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/__init__.py +0 -0
  136. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/data_types.py +0 -0
  137. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/exceptions.py +0 -0
  138. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/llms.py +0 -0
  139. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/platforms/__init__.py +0 -0
  140. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/platforms/bugzilla.py +0 -0
  141. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/platforms/patch_apply.py +0 -0
  142. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/text.py +0 -0
  143. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/core/validators.py +0 -0
  144. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/patch_summarization/__init__.py +0 -0
  145. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/patch_summarization/agent.py +0 -0
  146. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/patch_summarization/prompts.py +0 -0
  147. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/suggestion_filtering/__init__.py +0 -0
  148. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/suggestion_filtering/agent.py +0 -0
  149. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/tools/suggestion_filtering/prompts.py +0 -0
  150. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/utils.py +0 -0
  151. {bugbug-0.0.662 → bugbug-0.0.663}/bugbug/vectordb.py +0 -0
  152. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/__init__.py +0 -0
  153. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/analyze_training_metrics.py +0 -0
  154. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/backout_related_test_regressions.py +0 -0
  155. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/bug_classifier.py +0 -0
  156. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/bug_retriever.py +0 -0
  157. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/check.py +0 -0
  158. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/check_all_metrics.py +0 -0
  159. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/ci_failures_matching.py +0 -0
  160. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/comment_classifier.py +0 -0
  161. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/comment_level_labeler.py +0 -0
  162. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/comment_resolver_runner.py +0 -0
  163. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/commit_classifier.py +0 -0
  164. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/commit_retriever.py +0 -0
  165. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/compatibility_report_classifier.py +0 -0
  166. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/gcp_logs_retriever.py +0 -0
  167. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/generate_landings_risk_report.py +0 -0
  168. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/generate_sheet.py +0 -0
  169. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/get_type_labels.py +0 -0
  170. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/get_untriaged.py +0 -0
  171. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/github_issue_classifier.py +0 -0
  172. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/github_issue_retriever.py +0 -0
  173. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/inline_comments_data_collection.py +0 -0
  174. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/integration_test.sh +0 -0
  175. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/maintenance_effectiveness_indicator.py +0 -0
  176. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/microannotate_generator.py +0 -0
  177. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/past_bugs_by_unit.py +0 -0
  178. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/perf_alerts_retriever.py +0 -0
  179. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/perf_commit_risk_scorer.py +0 -0
  180. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/perf_regression_predictor.py +0 -0
  181. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/perf_scheduling_simulator.py +0 -0
  182. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/redundant_failures.py +0 -0
  183. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/regressor_finder.py +0 -0
  184. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/retrieve_ci_failures.py +0 -0
  185. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/retrieve_training_metrics.py +0 -0
  186. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/retrieve_try_pushes.py +0 -0
  187. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/review_comments_retriever.py +0 -0
  188. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/revision_retriever.py +0 -0
  189. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/shadow_scheduler_stats.py +0 -0
  190. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/test_scheduling_history_retriever.py +0 -0
  191. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/testing_policy_stats.py +0 -0
  192. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/trainer.py +0 -0
  193. {bugbug-0.0.662 → bugbug-0.0.663}/scripts/trainer_extract_args.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bugbug
3
- Version: 0.0.662
3
+ Version: 0.0.663
4
4
  Summary: ML tools for Mozilla projects
5
5
  Author-email: Marco Castelluccio <mcastelluccio@mozilla.com>
6
6
  License-Expression: MPL-2.0
@@ -30,7 +30,7 @@ Requires-Dist: markdown2~=2.5.5
30
30
  Requires-Dist: matplotlib<3.12.0,>=3.10.8
31
31
  Requires-Dist: mercurial~=7.2
32
32
  Requires-Dist: microannotate~=0.0.24
33
- Requires-Dist: mozci~=2.6.3
33
+ Requires-Dist: mozci~=2.6.6
34
34
  Requires-Dist: numpy<2.6.0,>=2.4.3
35
35
  Requires-Dist: orjson<3.14.0,>=3.11.7
36
36
  Requires-Dist: ortools~=9.15.6755
@@ -50,7 +50,7 @@ Requires-Dist: searchfox>=0.20.3
50
50
  Requires-Dist: sendgrid~=6.12.5
51
51
  Requires-Dist: shap[plots]<0.55,>=0.51
52
52
  Requires-Dist: tabulate~=0.10.0
53
- Requires-Dist: taskcluster~=116.0
53
+ Requires-Dist: taskcluster~=117.2
54
54
  Requires-Dist: tenacity~=9.1.4
55
55
  Requires-Dist: tqdm<4.71.0,>=4.67.3
56
56
  Requires-Dist: unidiff<1.1.0,>=0.7.5
@@ -63,6 +63,6 @@ Requires-Dist: spacy==3.8.18; extra == 'nlp'
63
63
  Provides-Extra: nn
64
64
  Provides-Extra: perf-regression-predictor
65
65
  Requires-Dist: torch==2.15.0; extra == 'perf-regression-predictor'
66
- Requires-Dist: transformers==5.22.2; extra == 'perf-regression-predictor'
66
+ Requires-Dist: transformers==5.24.0; extra == 'perf-regression-predictor'
67
67
  Provides-Extra: perf-simulation
68
68
  Requires-Dist: optuna>=5.0.0; extra == 'perf-simulation'
bugbug-0.0.663/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.663
@@ -1962,6 +1962,16 @@ def clone(
1962
1962
  logger.info("%s cloned", repo_dir)
1963
1963
 
1964
1964
 
1965
+ def has_revision(repo_dir: str, revision: str) -> bool:
1966
+ """Whether a revision is in a local repository."""
1967
+ with hglib.open(repo_dir) as hg:
1968
+ try:
1969
+ hg.log(revrange=revision.encode("ascii"))
1970
+ except hglib.error.CommandError:
1971
+ return False
1972
+ return True
1973
+
1974
+
1965
1975
  def pull(repo_dir: str, branch: str, revision: str, update: bool = False) -> None:
1966
1976
  """Pull a revision from a branch of a remote repository into a local repository."""
1967
1977
 
@@ -42,11 +42,17 @@ from bugbug.tools.code_review.prompts import (
42
42
  SYSTEM_PROMPT_TEMPLATE,
43
43
  TEMPLATE_COMMENT_EXAMPLE,
44
44
  TEMPLATE_PATCH_FROM_HUNK,
45
+ TEMPLATE_PATCH_STACK,
45
46
  )
46
47
  from bugbug.tools.code_review.protocols import (
47
48
  PatchSummarizer,
48
49
  SuggestionFilterer,
49
50
  )
51
+ from bugbug.tools.code_review.stack import (
52
+ PatchStack,
53
+ format_stack_context,
54
+ load_patch_stack,
55
+ )
50
56
  from bugbug.tools.code_review.utils import (
51
57
  convert_generated_comments_to_inline,
52
58
  format_patch_set,
@@ -209,22 +215,34 @@ class CodeReviewTool(GenerativeModelTool):
209
215
  def count_tokens(self, text):
210
216
  return len(self._tokenizer.encode(text))
211
217
 
212
- def generate_initial_prompt(
213
- self, patch: Patch, patch_summary: str, external_context: str = ""
218
+ async def generate_initial_prompt(
219
+ self,
220
+ patch: Patch,
221
+ patch_summary: str,
222
+ external_context: str = "",
223
+ stack: Optional[PatchStack] = None,
214
224
  ) -> str:
215
225
  created_before = patch.date_created if self.is_experiment_env else None
226
+ if stack is None:
227
+ stack = await load_patch_stack(patch)
228
+ stack_context = format_stack_context(stack)
216
229
 
217
230
  return FIRST_MESSAGE_TEMPLATE.format(
218
231
  current_date=current_date_for_prompt(),
219
232
  patch=format_patch_set(patch.patch_set),
220
233
  patch_summarization=patch_summary,
221
234
  external_context=external_context,
235
+ patch_stack=(
236
+ TEMPLATE_PATCH_STACK.format(stack_context=stack_context)
237
+ if stack_context
238
+ else ""
239
+ ),
222
240
  comment_examples=self._get_comment_examples(patch, created_before),
223
241
  approved_examples=self._get_generated_examples(patch, created_before),
224
242
  )
225
243
 
226
244
  async def generate_review_comments(
227
- self, patch: Patch, patch_summary: str
245
+ self, patch: Patch, patch_summary: str, stack: Optional[PatchStack] = None
228
246
  ) -> tuple[AgentResponse, list[dict]]:
229
247
  from bugbug.tools.code_review.review_context import (
230
248
  resolve_external_context_for_review,
@@ -242,7 +260,9 @@ class CodeReviewTool(GenerativeModelTool):
242
260
 
243
261
  messages = [
244
262
  HumanMessage(
245
- self.generate_initial_prompt(patch, patch_summary, external_context)
263
+ await self.generate_initial_prompt(
264
+ patch, patch_summary, external_context, stack
265
+ )
246
266
  )
247
267
  ]
248
268
  for attempt in range(2):
@@ -296,13 +316,15 @@ class CodeReviewTool(GenerativeModelTool):
296
316
  return result["structured_response"].comments[:1]
297
317
 
298
318
  async def run(self, patch: Patch) -> CodeReviewToolResponse:
319
+ await patch.load()
299
320
  if self.count_tokens(patch.raw_diff) > 21000:
300
321
  raise LargeDiffError("The diff is too large")
301
322
 
302
323
  patch_summary = self.patch_summarizer.run(patch)
324
+ stack = await load_patch_stack(patch)
303
325
 
304
326
  agent_response, external_content_manifest = await self.generate_review_comments(
305
- patch, patch_summary
327
+ patch, patch_summary, stack
306
328
  )
307
329
  unfiltered_suggestions = agent_response.comments
308
330
  if not unfiltered_suggestions:
@@ -2,10 +2,9 @@ import re
2
2
  from typing import Annotated
3
3
 
4
4
  import httpx
5
- import tenacity
6
5
  from pydantic import BaseModel, Field, PrivateAttr
7
6
 
8
- from bugbug.tools.core.connection import get_http_client
7
+ from bugbug.tools.core.connection import get_http_client, retry_transient_errors
9
8
  from bugbug.tools.core.data_types import (
10
9
  CommentCategory,
11
10
  CommentSeverity,
@@ -138,8 +137,7 @@ class Skill(BaseModel):
138
137
  return self._cached_body
139
138
 
140
139
  try:
141
- response = await get_http_client().get(self.url, timeout=30)
142
- response.raise_for_status()
140
+ response = await _fetch_url(self.url)
143
141
  except httpx.HTTPError as e:
144
142
  raise SkillLoadError(
145
143
  f"Could not load skill '{self.name}' from {self.url}"
@@ -153,22 +151,9 @@ class ExternalContentLoadError(Exception):
153
151
  """Raised when an ExternalContent body cannot be loaded."""
154
152
 
155
153
 
156
- def _is_retryable(exc: BaseException) -> bool:
157
- if isinstance(exc, httpx.HTTPStatusError):
158
- status = exc.response.status_code
159
- # 429: rate limited; 5xx: temporary server error
160
- return status == 429 or status >= 500
161
- return isinstance(exc, httpx.TransportError)
162
-
163
-
164
- @tenacity.retry(
165
- stop=tenacity.stop_after_attempt(3),
166
- wait=tenacity.wait_exponential(multiplier=1, min=1),
167
- retry=tenacity.retry_if_exception(_is_retryable),
168
- reraise=True,
169
- )
170
- async def _fetch_url(url: str) -> httpx.Response:
171
- response = await get_http_client().get(url, timeout=30)
154
+ @retry_transient_errors()
155
+ async def _fetch_url(url: str, headers: dict[str, str] | None = None) -> httpx.Response:
156
+ response = await get_http_client().get(url, headers=headers)
172
157
  response.raise_for_status()
173
158
  return response
174
159
 
@@ -11,12 +11,12 @@ from logging import getLogger
11
11
  from typing import Annotated, Literal, Optional
12
12
 
13
13
  import httpx
14
- import tenacity
15
14
  from langchain.tools import tool
16
15
  from langgraph.runtime import get_runtime
17
16
  from searchfox import AsyncSearchfoxClient, SearchfoxNetworkError, SearchfoxRequestError
18
17
 
19
18
  from bugbug.tools.code_review.data_types import Skill, SkillLoadError
19
+ from bugbug.tools.core.connection import retry_transient_errors
20
20
  from bugbug.tools.core.platforms.base import Patch
21
21
  from bugbug.tools.core.platforms.patch_apply import get_file_after_stack
22
22
  from bugbug.tools.core.platforms.phabricator import PhabricatorPatch
@@ -24,12 +24,7 @@ from bugbug.tools.core.validators import StripEnumQuotes
24
24
 
25
25
  logger = getLogger(__name__)
26
26
 
27
- _retry = tenacity.retry(
28
- stop=tenacity.stop_after_attempt(3),
29
- wait=tenacity.wait_exponential(multiplier=1, min=1, max=4),
30
- retry=tenacity.retry_if_exception_type(SearchfoxNetworkError),
31
- reraise=True,
32
- )
27
+ _retry = retry_transient_errors(lambda e: isinstance(e, SearchfoxNetworkError))
33
28
 
34
29
 
35
30
  def _tool_error(message: str, *, fatal: bool = False) -> str:
@@ -101,7 +96,7 @@ async def expand_context(
101
96
  try:
102
97
  if isinstance(patch, PhabricatorPatch):
103
98
  try:
104
- stack = patch._stack_patches
99
+ stack = await patch.get_stack_patches()
105
100
  except ValueError as e:
106
101
  warning = f"Could not retrieve the full patch stack ({e}). File content reflects only this patch; please flag this in your review."
107
102
  stack = [patch]
@@ -193,6 +188,9 @@ async def search_text(
193
188
  ) -> str:
194
189
  """Search for text or patterns across the codebase.
195
190
 
191
+ Results come from mozilla-central, without this patch or its stack. Use
192
+ `expand_context` to read a file as the patch stack leaves it.
193
+
196
194
  Args:
197
195
  query: Text or regular expression to search for.
198
196
  path_filter: Optional path prefix, e.g. 'dom/media'.
@@ -242,6 +240,9 @@ async def get_field_layout(
242
240
  ) -> str:
243
241
  """Show the memory layout of a C++ class or struct, including field offsets and sizes.
244
242
 
243
+ Results come from mozilla-central, without this patch or its stack. Use
244
+ `expand_context` to read a file as the patch stack leaves it.
245
+
245
246
  Args:
246
247
  class_name: Fully-qualified class name, e.g. 'mozilla::dom::AudioContext'.
247
248
 
@@ -267,6 +268,9 @@ async def get_blame(
267
268
  ) -> str:
268
269
  """Get the commit that last modified each of the given lines in a file.
269
270
 
271
+ Results come from mozilla-central, without this patch or its stack. Use
272
+ `expand_context` to read a file as the patch stack leaves it.
273
+
270
274
  Args:
271
275
  file_path: Repository-relative path, e.g. 'dom/media/webaudio/AudioNode.cpp'.
272
276
  lines: List of 1-based line numbers to look up.
@@ -300,6 +304,9 @@ async def check_can_gc(
300
304
  ) -> str:
301
305
  """Check whether a C++ function can trigger garbage collection in SpiderMonkey.
302
306
 
307
+ Results come from mozilla-central, without this patch or its stack. Use
308
+ `expand_context` to read a file as the patch stack leaves it.
309
+
303
310
  Accepts partial names (e.g. 'CreateGain') or fully-qualified names
304
311
  (e.g. 'mozilla::dom::AudioContext::CreateGain').
305
312
 
@@ -338,6 +345,9 @@ async def find_definition(
338
345
  ) -> str:
339
346
  """Find the definition of a function, method, class, or struct.
340
347
 
348
+ Results come from mozilla-central, without this patch or its stack. Use
349
+ `expand_context` to read a file as the patch stack leaves it.
350
+
341
351
  Accepts partial names (e.g. 'AudioNode') or fully-qualified names
342
352
  (e.g. 'mozilla::dom::AudioNode' or 'AudioNode::Connect').
343
353
 
@@ -372,6 +382,9 @@ async def search_identifier(
372
382
  ) -> str:
373
383
  """Search for an exact identifier across the codebase.
374
384
 
385
+ Results come from mozilla-central, without this patch or its stack. Use
386
+ `expand_context` to read a file as the patch stack leaves it.
387
+
375
388
  Args:
376
389
  identifier: Identifier to search for.
377
390
  path_filter: Optional path prefix, e.g. 'dom/media'.
@@ -416,6 +429,9 @@ async def calls_from(
416
429
  ) -> str:
417
430
  """Find functions called by the given symbol (outgoing calls).
418
431
 
432
+ Results come from mozilla-central, without this patch or its stack. Use
433
+ `expand_context` to read a file as the patch stack leaves it.
434
+
419
435
  Args:
420
436
  symbol: Fully-qualified function or method name, e.g. 'mozilla::dom::AudioNode::Connect'.
421
437
  depth: Levels of calls to traverse (default 2).
@@ -444,6 +460,9 @@ async def calls_to(
444
460
  ) -> str:
445
461
  """Find functions that call the given symbol (incoming calls).
446
462
 
463
+ Results come from mozilla-central, without this patch or its stack. Use
464
+ `expand_context` to read a file as the patch stack leaves it.
465
+
447
466
  Args:
448
467
  symbol: Fully-qualified function or method name, e.g. 'mozilla::dom::AudioNode::Connect'.
449
468
  depth: Levels of callers to traverse (default 2).
@@ -473,6 +492,9 @@ async def calls_between(
473
492
  ) -> str:
474
493
  """Find call paths between two symbols or classes.
475
494
 
495
+ Results come from mozilla-central, without this patch or its stack. Use
496
+ `expand_context` to read a file as the patch stack leaves it.
497
+
476
498
  Args:
477
499
  symbol_a: First fully-qualified symbol or class name, e.g. 'mozilla::dom::AudioContext'.
478
500
  symbol_b: Second fully-qualified symbol or class name.
@@ -513,6 +535,9 @@ async def get_function_at_line(
513
535
  ) -> str:
514
536
  """Get the source of the innermost function enclosing a given line.
515
537
 
538
+ Results come from mozilla-central, without this patch or its stack. Use
539
+ `expand_context` to read a file as the patch stack leaves it.
540
+
516
541
  Useful when you know a line number and want the full function body without
517
542
  having to know the function name.
518
543
 
@@ -120,6 +120,7 @@ Here are examples of good code review comments to guide your style and approach:
120
120
  </examples>
121
121
 
122
122
 
123
+ {patch_stack}
123
124
  Here is the patch you need to review:
124
125
 
125
126
  <patch>
@@ -128,6 +129,15 @@ Here is the patch you need to review:
128
129
  """
129
130
 
130
131
 
132
+ TEMPLATE_PATCH_STACK = """Here is the stack of patches this patch belongs to:
133
+
134
+ <patch_stack>
135
+ {stack_context}
136
+ </patch_stack>
137
+
138
+ """
139
+
140
+
131
141
  TEMPLATE_COMMENT_EXAMPLE = """Patch example {example_number}:
132
142
 
133
143
  {patch}
@@ -9,7 +9,6 @@ Fetches review-context.toml from a GitHub repository, matches changed files
9
9
  against the rules, and pre-loads the referenced content.
10
10
  """
11
11
 
12
- import asyncio
13
12
  import fnmatch
14
13
  import hashlib
15
14
  import json
@@ -50,7 +49,6 @@ from bugbug.tools.code_review.review_context_schema import (
50
49
  parse_review_context_toml,
51
50
  tomllib,
52
51
  )
53
- from bugbug.tools.core.connection import get_github_api_headers, get_http_client
54
52
 
55
53
  logger = getLogger(__name__)
56
54
 
@@ -338,15 +336,11 @@ async def _fetch_revision(
338
336
  return None
339
337
  rev_num = int(m.group(1))
340
338
  try:
341
- from bugbug.tools.core.platforms.phabricator import get_phabricator_client
339
+ from bugbug.tools.core.platforms.phabricator import PhabricatorPatch
342
340
 
343
- def _load():
344
- phab = get_phabricator_client()
345
- revision = phab.load_revision(rev_id=rev_num)
346
- diff_id = revision["fields"]["diffID"]
347
- return phab.load_raw_diff(diff_id)
348
-
349
- content = await asyncio.get_event_loop().run_in_executor(None, _load)
341
+ patch = PhabricatorPatch(revision_id=rev_num)
342
+ await patch.load()
343
+ content = patch.raw_diff
350
344
  name = f"Revision D{rev_num}"
351
345
  return (
352
346
  name,
@@ -361,15 +355,10 @@ async def _fetch_revision(
361
355
 
362
356
  if repo and commit_hash:
363
357
  try:
364
- response = await get_http_client().get(
358
+ response = await _fetch_url(
365
359
  f"https://api.github.com/repos/{repo}/commits/{commit_hash}",
366
- headers={
367
- "Accept": "application/vnd.github.diff",
368
- **get_github_api_headers(),
369
- },
370
- timeout=30,
360
+ headers={"Accept": "application/vnd.github.diff"},
371
361
  )
372
- response.raise_for_status()
373
362
  source = f"{repo}@{commit_hash}"
374
363
  return (
375
364
  f"{repo}@{commit_hash[:12]}",
@@ -0,0 +1,166 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This Source Code Form is subject to the terms of the Mozilla Public
3
+ # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
+ # You can obtain one at http://mozilla.org/MPL/2.0/.
5
+
6
+ """Describe the stack of patches that a reviewed patch belongs to."""
7
+
8
+ import asyncio
9
+ from dataclasses import dataclass, field
10
+ from logging import getLogger
11
+ from typing import Optional
12
+
13
+ from unidiff import PatchSet
14
+
15
+ from bugbug.tools.core.platforms.base import Patch
16
+
17
+ logger = getLogger(__name__)
18
+
19
+ # The nearest ancestors are listed with the files they touch, older ones by
20
+ # title only, to keep deep stacks within a reasonable prompt size.
21
+ MAX_DETAILED_ANCESTORS = 15
22
+ MAX_FILES_PER_ANCESTOR = 10
23
+ MAX_LISTED_ANCESTORS = 60
24
+ MAX_LISTED_DESCENDANTS = 15
25
+
26
+ STACK_TOOLS_WARNING = """\
27
+ The Searchfox-backed tools (`find_definition`, `search_text`, `search_identifier`,
28
+ `get_blame`, `get_function_at_line`, `get_field_layout`, `calls_from`, `calls_to`,
29
+ `calls_between` and `check_can_gc`) index mozilla-central, so they do not see this
30
+ patch or any patch in its stack. Before reporting that a symbol does not exist, that a
31
+ caller was not updated, or that code is unchanged, read the files the ancestors touch
32
+ with `expand_context`, which applies the whole stack.
33
+
34
+ Later patches may finish work that this patch starts. Do not report a missing
35
+ follow-up step that the title of a later patch says it covers."""
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class StackEntry:
40
+ """One patch in the stack, other than the reviewed one."""
41
+
42
+ display_id: str
43
+
44
+ title: str
45
+
46
+ # The changes of the patch, or `None` when they were not loaded.
47
+ patch_set: Optional[PatchSet] = None
48
+
49
+
50
+ @dataclass(frozen=True)
51
+ class PatchStack:
52
+ """The patches around the reviewed patch in its stack."""
53
+
54
+ # The patches applied before the reviewed one, oldest first.
55
+ ancestors: list[StackEntry] = field(default_factory=list)
56
+
57
+ # The patches that build on the reviewed one, nearest first.
58
+ descendants: list[StackEntry] = field(default_factory=list)
59
+
60
+ # Problems that kept part of the stack from loading.
61
+ errors: list[str] = field(default_factory=list)
62
+
63
+ @property
64
+ def is_stacked(self) -> bool:
65
+ return bool(self.ancestors or self.descendants or self.errors)
66
+
67
+
68
+ async def load_patch_stack(patch: Patch) -> PatchStack:
69
+ """Load the titles and changes of the patches around `patch`, concurrently.
70
+
71
+ The stack is optional context, so a failure to load it is recorded in
72
+ `errors` rather than raised.
73
+ """
74
+ (
75
+ (ancestors, ancestors_error),
76
+ (descendants, descendants_error),
77
+ ) = await asyncio.gather(load_ancestors(patch), load_descendants(patch))
78
+ errors = [error for error in (ancestors_error, descendants_error) if error]
79
+ return PatchStack(ancestors, descendants, errors)
80
+
81
+
82
+ async def load_ancestors(patch: Patch) -> tuple[list[StackEntry], Optional[str]]:
83
+ """Return the ancestors of `patch` with their changes, or the reason they failed."""
84
+ logger.debug("Loading the ancestors of patch %s.", patch.patch_id)
85
+ try:
86
+ ancestors = await patch.get_stack_ancestors()
87
+ except Exception as error:
88
+ logger.warning("Could not load the ancestors of %s: %s", patch.patch_id, error)
89
+ return [], f"The patches before this one could not be loaded ({error})."
90
+
91
+ return [
92
+ StackEntry(ancestor.display_id, ancestor.patch_title, ancestor.patch_set)
93
+ for ancestor in ancestors
94
+ ], None
95
+
96
+
97
+ async def load_descendants(patch: Patch) -> tuple[list[StackEntry], Optional[str]]:
98
+ """Return the descendants of `patch` by title, or the reason they failed."""
99
+ logger.debug("Loading the descendants of patch %s.", patch.patch_id)
100
+ try:
101
+ descendants = await patch.get_stack_descendants()
102
+ except Exception as error:
103
+ logger.warning(
104
+ "Could not load the descendants of %s: %s", patch.patch_id, error
105
+ )
106
+ return [], f"The patches after this one could not be loaded ({error})."
107
+
108
+ return [
109
+ StackEntry(descendant.display_id, descendant.patch_title)
110
+ for descendant in descendants
111
+ ], None
112
+
113
+
114
+ def format_file_changes(patch_set: PatchSet) -> list[str]:
115
+ """Return one line per file the patch touches, with its line counts."""
116
+ lines = [
117
+ f" - {patched_file.path} (+{patched_file.added} -{patched_file.removed})"
118
+ for patched_file in patch_set[:MAX_FILES_PER_ANCESTOR]
119
+ ]
120
+ if len(patch_set) > MAX_FILES_PER_ANCESTOR:
121
+ lines.append(f" - … and {len(patch_set) - MAX_FILES_PER_ANCESTOR} more files")
122
+ return lines
123
+
124
+
125
+ def format_ancestors(ancestors: list[StackEntry]) -> list[str]:
126
+ """List the ancestors nearest first, with the files the nearest ones touch."""
127
+ nearest_first = list(reversed(ancestors))
128
+ lines = [f"{len(ancestors)} patches come before this one, nearest first:"]
129
+ for position, ancestor in enumerate(nearest_first[:MAX_LISTED_ANCESTORS]):
130
+ lines.append(f"- {ancestor.display_id}: {ancestor.title}")
131
+ if position < MAX_DETAILED_ANCESTORS and ancestor.patch_set is not None:
132
+ lines.extend(format_file_changes(ancestor.patch_set))
133
+ if len(nearest_first) > MAX_LISTED_ANCESTORS:
134
+ lines.append(f"- … and {len(nearest_first) - MAX_LISTED_ANCESTORS} older")
135
+ return lines
136
+
137
+
138
+ def format_descendants(descendants: list[StackEntry]) -> list[str]:
139
+ """List the descendants nearest first, by title only."""
140
+ lines = [f"{len(descendants)} patches build on this one, nearest first:"]
141
+ lines.extend(
142
+ f"- {descendant.display_id}: {descendant.title}"
143
+ for descendant in descendants[:MAX_LISTED_DESCENDANTS]
144
+ )
145
+ if len(descendants) > MAX_LISTED_DESCENDANTS:
146
+ lines.append(f"- … and {len(descendants) - MAX_LISTED_DESCENDANTS} more")
147
+ return lines
148
+
149
+
150
+ def format_stack_context(stack: PatchStack) -> str:
151
+ """Describe the stack for the review prompt, or return "" for a lone patch."""
152
+ if not stack.is_stacked:
153
+ return ""
154
+
155
+ sections = [
156
+ "This patch is part of a stack of patches. The patches before it have not "
157
+ "landed, and this patch is written against the code as they leave it."
158
+ ]
159
+ if stack.ancestors:
160
+ sections.append("\n".join(format_ancestors(stack.ancestors)))
161
+ if stack.descendants:
162
+ sections.append("\n".join(format_descendants(stack.descendants)))
163
+ sections.extend(f"Warning: {error}" for error in stack.errors)
164
+ sections.append(STACK_TOOLS_WARNING)
165
+
166
+ return "\n\n".join(sections)
@@ -0,0 +1,113 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This Source Code Form is subject to the terms of the Mozilla Public
3
+ # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4
+ # You can obtain one at http://mozilla.org/MPL/2.0/.
5
+
6
+ """Core connection utilities for bugbug tools."""
7
+
8
+ import logging
9
+ import os
10
+ from functools import cache
11
+ from typing import Callable
12
+
13
+ import httpx
14
+ import tenacity
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+ # Longest wait honored from a Retry-After header, so a single call stays bounded.
19
+ MAX_RETRY_AFTER = 30
20
+
21
+ # Connecting is quick unless something is wrong, and failures are retried. Reads
22
+ # get more time: Conduit can take tens of seconds on large revisions, GitHub
23
+ # serves large files slowly, and the timers keep running while the event loop
24
+ # is busy with other concurrent reviews.
25
+ HTTP_TIMEOUT = httpx.Timeout(60, connect=10)
26
+
27
+
28
+ def get_user_agent() -> str:
29
+ """Get the User-Agent string from environment or default."""
30
+ return os.getenv("USER_AGENT", "bugbug")
31
+
32
+
33
+ # Hosts the GitHub token authenticates to. raw.githubusercontent.com is included
34
+ # because unauthenticated raw file downloads are rate limited much more strictly.
35
+ GITHUB_HOSTS = frozenset({"api.github.com", "raw.githubusercontent.com"})
36
+
37
+
38
+ class GitHubTokenAuth(httpx.Auth):
39
+ """Authenticate requests to GitHub hosts with a token, and only those."""
40
+
41
+ def __init__(self, token: str) -> None:
42
+ self.token = token
43
+
44
+ def auth_flow(self, request: httpx.Request):
45
+ if request.url.host in GITHUB_HOSTS:
46
+ request.headers["Authorization"] = f"Bearer {self.token}"
47
+ yield request
48
+
49
+
50
+ def is_transient_http_error(exc: BaseException) -> bool:
51
+ """Return whether a failed HTTP request may succeed if retried."""
52
+ if isinstance(exc, httpx.HTTPStatusError):
53
+ status = exc.response.status_code
54
+ return status == 429 or status >= 500
55
+ return isinstance(exc, httpx.TransportError)
56
+
57
+
58
+ _backoff = tenacity.wait_exponential_jitter(initial=1, max=10)
59
+
60
+
61
+ def _wait_before_retry(retry_state: tenacity.RetryCallState) -> float:
62
+ """Wait as long as a Retry-After header asks, or back off exponentially."""
63
+ assert retry_state.outcome is not None
64
+ exc = retry_state.outcome.exception()
65
+ if isinstance(exc, httpx.HTTPStatusError):
66
+ retry_after = exc.response.headers.get("Retry-After", "")
67
+ if retry_after.isdigit():
68
+ return min(int(retry_after), MAX_RETRY_AFTER)
69
+ return _backoff(retry_state)
70
+
71
+
72
+ def retry_transient_errors(
73
+ is_transient: Callable[[BaseException], bool] = is_transient_http_error,
74
+ ):
75
+ """Retry the decorated function when it fails with a transient error.
76
+
77
+ Only errors for which is_transient returns True are retried, at most three
78
+ times, with an exponential backoff of up to 10 seconds between attempts.
79
+ """
80
+ return tenacity.retry(
81
+ stop=tenacity.stop_after_attempt(4),
82
+ wait=_wait_before_retry,
83
+ retry=tenacity.retry_if_exception(is_transient),
84
+ before_sleep=tenacity.before_sleep_log(logger, logging.WARNING),
85
+ reraise=True,
86
+ )
87
+
88
+
89
+ @cache
90
+ def get_http_client() -> httpx.AsyncClient:
91
+ """Get the shared HTTP client instance."""
92
+ token = os.getenv("GITHUB_TOKEN")
93
+ http_client = httpx.AsyncClient(
94
+ auth=GitHubTokenAuth(token) if token else None,
95
+ follow_redirects=True,
96
+ timeout=HTTP_TIMEOUT,
97
+ headers={
98
+ "User-Agent": get_user_agent(),
99
+ },
100
+ )
101
+
102
+ return http_client
103
+
104
+
105
+ async def close_http_client() -> None:
106
+ """Close the shared HTTP client instance and clear the cache."""
107
+ if get_http_client.cache_info().currsize == 0:
108
+ # No cached client to close
109
+ return
110
+
111
+ client = get_http_client()
112
+ get_http_client.cache_clear()
113
+ await client.aclose()