Skip to content

Support triggering the bug-fix agent for follow-ups when mentioning @hackbot#6353

Open
suhaibmujahid wants to merge 11 commits into
mozilla:masterfrom
suhaibmujahid:hackbot-webhooks
Open

Support triggering the bug-fix agent for follow-ups when mentioning @hackbot#6353
suhaibmujahid wants to merge 11 commits into
mozilla:masterfrom
suhaibmujahid:hackbot-webhooks

Conversation

@suhaibmujahid

Copy link
Copy Markdown
Member

Note

This PR car be reviewed commit by commit

This PR will add support to trigger the bug-fix agent for follow-ups when mentioning @hackbot in a comment on a Phabricator revision.

Both consumers run in hackbot-api's event loop (the webhook route and the
apply handler awaited by the action applier), so the Conduit client is now
async (httpx.AsyncClient). The apply handler's helpers become async, with
_repository_phid cached via async-lru instead of functools.lru_cache.
Comment thread agents/bug-fix/hackbot_agents/bug_fix/agent.py Outdated
Update Phabricator mention handling to collect every triggering @hackbot comment in a delivery instead of only the first match. The webhook now returns all qualifying comments in transaction order, skips bot/self and non-triggering transactions as before, and combines multiple comments into a numbered payload so the agent can address each request. Follow-up prompt wording was updated to reflect multi-comment runs and mixed review requests, and webhook tests were expanded for multi-inline mentions, per-transaction version handling, and comment-join formatting.
Pass `bug_id` when rendering the bug-fix follow-up prompt and update the prompt text to include the linked bug number alongside the Phabricator revision. This gives follow-up runs clearer issue context when responding to mention-triggered comments.
@suhaibmujahid
suhaibmujahid marked this pull request as ready for review July 24, 2026 12:09
@suhaibmujahid
suhaibmujahid requested review from a team as code owners July 24, 2026 12:09
Copilot AI review requested due to automatic review settings July 24, 2026 12:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end support for Phabricator follow-up runs triggered by @hackbot mentions: hackbot-api receives signed Phabricator webhooks, resolves the revision+bug via Conduit, and triggers a bug-fix run that checks out the revision’s base+diff via a broker sidecar and can optionally respond on the revision.

Changes:

  • Add a Phabricator webhook receiver to hackbot-api (HMAC-authenticated) that triggers bug-fix follow-up runs when an @hackbot mention is detected.
  • Introduce a shared phabricator-client library (httpx-based) and wire it into both the webhook receiver and the apply-side Phabricator handlers.
  • Extend hackbot-runtime + bug-fix agent to support revision-based follow-ups (checkout revision, follow-up prompt, and a new “add comment” action/handler).

Reviewed changes

Copilot reviewed 41 out of 42 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Adds workspace member phabricator-client and dependency updates for new webhook/revision features.
services/hackbot-api/tests/test_webhooks.py Adds tests for signature verification, mention detection, revision resolution, dedupe, and webhook route behavior.
services/hackbot-api/tests/conftest.py Seeds required env vars so settings validation doesn’t fail during tests.
services/hackbot-api/pyproject.toml Adds runtime deps needed for webhook receiver + Conduit calls (cachetools, httpx, phabricator-client).
services/hackbot-api/app/schemas.py Extends BugFixInputs with optional revision_id and comment for follow-up runs.
services/hackbot-api/app/routers/webhooks.py Implements /webhooks/phabricator endpoint to detect mentions and trigger a bug-fix follow-up run.
services/hackbot-api/app/routers/init.py Exposes the new webhooks router.
services/hackbot-api/app/phabricator_webhook.py Adds webhook payload parsing, mention detection, and Conduit resolution helpers.
services/hackbot-api/app/main.py Includes the new webhooks router in the FastAPI app.
services/hackbot-api/app/config.py Adds nested phabricator + webhook settings and env nesting configuration.
services/hackbot-api/app/client.py Adds async client used by the webhook receiver to trigger hackbot runs via public API.
services/hackbot-api/app/auth.py Adds Phabricator HMAC signature verification + dependency guard.
libs/phabricator-client/tests/test_client.py Adds unit tests for Conduit request behavior and helper methods.
libs/phabricator-client/pyproject.toml Defines the new phabricator-client library package.
libs/phabricator-client/phabricator_client/models.py Adds typed Phabricator models (e.g., latest diff metadata).
libs/phabricator-client/phabricator_client/config.py Adds validated settings model + env-driven loader for standalone use.
libs/phabricator-client/phabricator_client/client.py Implements the async httpx-based Conduit client and helper APIs.
libs/phabricator-client/phabricator_client/init.py Exports the public API of phabricator-client.
libs/hackbot-runtime/tests/test_revision.py Tests revision checkout via broker patch endpoint and git apply behavior.
libs/hackbot-runtime/tests/test_phabricator_handler.py Updates apply-side handler tests for async client and adds comment handler coverage.
libs/hackbot-runtime/tests/test_phabricator_actions.py Adds tests for recording phabricator.add_comment.
libs/hackbot-runtime/tests/test_context.py Updates tests to the new async prepare_repo() / repo_path contract.
libs/hackbot-runtime/pyproject.toml Adds deps for Phabricator support (httpx, async-lru, phabricator-client).
libs/hackbot-runtime/hackbot_runtime/revision.py Adds logic to check out a Phabricator revision (base commit + diff) via broker.
libs/hackbot-runtime/hackbot_runtime/context.py Replaces source_repo lazy property with prepare_repo() + repo_path and one-time preparation enforcement.
libs/hackbot-runtime/hackbot_runtime/actions/phabricator.py Adds phabricator_add_comment action recording with a standard footer.
libs/hackbot-runtime/hackbot_runtime/actions/handlers/registry.py Registers the new phabricator.add_comment apply handler.
libs/hackbot-runtime/hackbot_runtime/actions/handlers/phabricator_handler.py Migrates Conduit calls to shared phabricator-client and adds apply-side comment posting.
libs/hackbot-runtime/hackbot_runtime/init.py Exports checkout_revision from the runtime package.
agents/frontend-triage/hackbot_agents/frontend_triage/main.py Updates to call prepare_repo() and pass ctx.repo_path instead of ctx.source_repo.
agents/build-repair/hackbot_agents/build_repair/main.py Uses prepare_repo(ref=…, depth=…) rather than env mutation and passes ctx.repo_path.
agents/bug-fix/tests/test_inputs.py Adds validation tests for revision follow-ups requiring broker URL.
agents/bug-fix/tests/test_broker.py Adds tests for broker patch route (base commit expansion + diff retrieval).
agents/bug-fix/pyproject.toml Adds phabricator-client + pytest config for the agent package.
agents/bug-fix/hackbot_agents/bug_fix/prompts/triage-and-fix.md Moves the triage prompt text into a template file.
agents/bug-fix/hackbot_agents/bug_fix/prompts/system.md Updates system prompt to reflect “Hackbot” identity and new action tool.
agents/bug-fix/hackbot_agents/bug_fix/prompts/follow-up.md Adds follow-up prompt template for responding to @hackbot mention comments on a revision.
agents/bug-fix/hackbot_agents/bug_fix/config.py Enables the new Phabricator add-comment action type.
agents/bug-fix/hackbot_agents/bug_fix/broker.py Extends broker to serve Phabricator patch route in addition to Bugzilla MCP.
agents/bug-fix/hackbot_agents/bug_fix/agent.py Adds prompt templating and follow-up mode (revision_id + comment).
agents/bug-fix/hackbot_agents/bug_fix/main.py Checks out revision via broker when REVISION_ID is set; otherwise prepares repo.
agents/bug-fix/compose.yml Wires Phabricator broker URL + follow-up env vars into local compose.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +72 to +85
# Dedupe retried deliveries: if we've already seen every triggering
# transaction, this is a retry of work already handled.
fresh = [phid for phid in triggering if phid not in _seen_transactions]
if not fresh:
return {"status": "ignored", "reason": "duplicate delivery"}
for phid in fresh:
_seen_transactions[phid] = True

detected = await detect_mention_and_revision(
phab_client,
settings.webhook,
object_phid,
triggering,
)
Comment on lines +91 to +98
run_id = await api_client.trigger_run(
"bug-fix",
{
"bug_id": bug_id,
"revision_id": revision_id,
"comment": comment,
},
)
Comment on lines +152 to 156
if revision_id and comment:
user_prompt = render_prompt(
"follow-up.md", revision_id=revision_id, bug_id=bug, comment=comment
)
else:
Comment on lines +45 to +50
# Phabricator Conduit connection config, embedded as a nested model and
# populated in this single settings parse from PHABRICATOR_URL /
# PHABRICATOR_API_KEY / PHABRICATOR_TIMEOUT_SECONDS (see env_nested_delimiter
# below). Injected directly as PhabricatorClient(settings.phabricator).
# Required, so a missing/invalid api_key fails at startup.
phabricator: PhabricatorSettings
Comment on lines 33 to 37
bugzilla_api_url: str
bugzilla_api_key: str
phabricator_url: str
phabricator_api_key: str
host: str = "0.0.0.0"
Comment on lines +95 to +104
phabricator_settings = PhabricatorSettings(
url=inputs.phabricator_url, api_key=inputs.phabricator_api_key
)
return Starlette(
routes=[
Mount("/mcp", app=mcp_handler),
_phabricator_route(phabricator_settings),
],
lifespan=lifespan,
)
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.

3 participants