Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The client passes charset-decoded characters to a JSON decoder expecting UTF-8 bytes, causing valid non-ASCII responses to fail parsing, caching the failure, and hiding the runs module.
1 open issue
What changed in this PR
Adds a Hackbot integration to BMO that displays run status on bug pages for authorized editbugs members.
Changes:
- Adds a permission-checked REST endpoint backed by a cached Hackbot API client.
- Adds an asynchronously loaded run table with status, origin, start time, and run links.
- Adds configuration switches, development defaults, and backend and REST tests.
| File | Description |
|---|---|
| scripts/generate_bmo_data.pl | Enables Hackbot features in generated development data. |
| qa/t/rest_hackbot_runs.t | Tests REST access controls and run responses. |
| extensions/Hackbot/web/style/hackbot_runs.css | Styles the run table and status badges. |
| extensions/Hackbot/web/js/hackbot_runs.js | Fetches and renders runs on bug pages. |
| extensions/Hackbot/template/en/default/hook/bug_modal/header-end.html.tmpl | Loads Hackbot styles and JavaScript conditionally. |
| extensions/Hackbot/template/en/default/hook/bug_modal/edit-module.html.tmpl | Adds the initially hidden Hackbot module. |
| extensions/Hackbot/template/en/default/hackbot/table.html.tmpl | Defines the run table structure. |
| extensions/Hackbot/template/en/default/admin/params/hackbot.html.tmpl | Documents integration settings for administrators. |
| extensions/Hackbot/t/bmo/bug-runs.t | Tests API handling, filtering, requester mapping, and caching. |
| extensions/Hackbot/lib/Constants.pm | Defines access, timeout, cache, and validation constants. |
| extensions/Hackbot/lib/Config.pm | Defines feature switches and connection settings. |
| extensions/Hackbot/lib/Client.pm | Implements Hackbot API requests and conditional fetching. |
| extensions/Hackbot/lib/BugRuns.pm | Caches, filters, and prepares runs for display. |
| extensions/Hackbot/lib/API/V1/Runs.pm | Exposes runs with authentication and bug-visibility checks. |
| extensions/Hackbot/Extension.pm | Registers settings and enables bug-page integration. |
| extensions/Hackbot/Config.pm | Declares the Hackbot extension identity. |
Review effort: Balanced
Bug 2086125. Label each run by what started it: needinfo, @hackbot on a Phabricator revision, Hackbot UI, CI failure, or a follow-up run, falling back to "Hackbot". Decode API responses as UTF-8 exactly once, and handle responses without an ETag, which previously broke the result hash.
Xzzz
left a comment
There was a problem hiding this comment.
lgtm, thanks!
One small thing to update in the description: it still says BMO calls GET /runs?bug_id=N (mozilla/ai-dev#7440), but the code calls GET /bugs/N/runs from mozilla/ai-dev#7442.
Thanks. Updated. |
kyoshino
left a comment
There was a problem hiding this comment.
Just quickly checking the UI 🙂
|
|
||
| my $response = $client->bug_runs($bug_id, $stale && $stale->{etag}); | ||
|
|
||
| unless ($response->{ok}) { |
There was a problem hiding this comment.
A single failed revalidation overwrites the good cached entry (and its ETag) with an error entry, so the table disappears for 60s and the next fetch is a full one. Would it be better to keep serving the stale runs on failure and only cache the error when there is no stale copy?
| $t->get_ok($url | ||
| . "rest/hackbot/bug_runs/$bug_id" => | ||
| {'X-Bugzilla-API-Key' => $unprivileged_key}) | ||
| ->json_is('/error', 1) |
There was a problem hiding this comment.
Should these error cases also assert the HTTP status (here and for the private bug below), so we know they fail for the expected reason rather than with any error?
| { | ||
| name => 'hackbot_ui_url', | ||
| type => 't', | ||
| default => 'https://hackbot.moz.tools/', |
There was a problem hiding this comment.
| default => 'https://hackbot.moz.tools/', | |
| default => 'https://hackbot-api.moz.tools/', |
| my ($class, %args) = @_; | ||
| my $self = bless { | ||
| base_url => $args{base_url} // Bugzilla->params->{hackbot_api_url}, | ||
| api_key => $args{api_key} // Bugzilla->params->{hackbot_api_key}, |
There was a problem hiding this comment.
Is Bugzilla deployed on GCP with access to the meta server? If so, we could use IAM to access the Hackbot API without a key.
| sub _origin { | ||
| my ($run) = @_; | ||
| my $dedupe_key = $run->{dedupe_key} // ''; | ||
| my $requested_via = $run->{requested_via} // ''; | ||
|
|
||
| return 'needinfo' if $run->{needinfo}; | ||
| return 'phabricator' | ||
| if $dedupe_key =~ HACKBOT_PHABRICATOR_DEDUPE_REGEX && $run->{revision_id}; | ||
| return 'followup' if $dedupe_key =~ HACKBOT_FOLLOWUP_DEDUPE_REGEX; | ||
| return 'ui' if $requested_via =~ HACKBOT_UI_ACCOUNT_REGEX; | ||
| return 'ci' if $requested_via =~ HACKBOT_CI_ACCOUNT_REGEX; | ||
| return 'other'; | ||
| } |
There was a problem hiding this comment.
It might be better to do this on Hackbot side instead of guessing it here.


Adds a Hackbot module to the bug page that lists the bug's Hackbot runs: agent, status, origin, start time, and a "view run" link into the Hackbot UI. Until now a run gave no sign on the bug until it posted a comment, so nobody could tell whether Hackbot had picked up a needinfo request or was still working on it.
Screenshot
Changes
Hackbotextension. The bug page loads the table fromGET /rest/hackbot/bug_runs/:bug_id, and BMO forwards that request to the Hackbot API (GET /bugs/N/runs, Bug 2091030 - Add the ability to filter runs based on bug id in the hackbot API ai-dev#7440) with anX-API-Key.@hackbot on D123(Phabricator), Hackbot UI, CI failure, or a follow-up run. Anything else shows as "Hackbot". The requester's BMO nick is added when Hackbot reports one.editbugsonly, and the user must be able to see the bug. Each run'sbug_idmust match the bug, so an API that ignores the filter can't leak runs from other bugs. Only nicks reach the browser, never emails or dedupe keys.If-None-Match(kept for a day). Failures are cached for 60 s.hackbot_runs_enabled,hackbot_api_url,hackbot_api_keyandhackbot_ui_url. Test data turns the feature on.Tests
extensions/Hackbot/t/bmo/bug-runs.t: client (UTF-8, no ETag, failures), trimming, every origin, ETag/304/error caching.qa/t/rest_hackbot_runs.t: login,editbugsand private-bug access, response shape.Depends on
bug_idfilter) being deployed.bug_idfor them. It doesn't today.