Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions agents/uplift-resolve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Set per run (see `UpliftInputs` in hackbot-api for the full schema):
`diff_id` is optional and defaults to the revision's latest.
- `BUG_ID` — optional Bugzilla bug for context.

`BUGBUG_MCP_URL` and `BROKER_URL` are deploy-time constants: the bugbug MCP
server, and the sidecar holding the Conduit key the agent fetches diffs through.
`BROKER_URL` is a deploy-time constant: the sidecar holding the Bugzilla and
Phabricator keys, which serves their read-only MCP tools and the Conduit proxy the
agent fetches diffs through.

## Output

Expand Down
28 changes: 5 additions & 23 deletions agents/uplift-resolve/compose.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
services:
# The bugbug MCP server, run as a sidecar so the agent reaches the originating
# bug and Phabricator revision over HTTP. It holds the Bugzilla/Phabricator
# credentials; the agent container binds none. In production the agent points
# at the deployed bugbug MCP instead via BUGBUG_MCP_URL.
uplift-resolve-bugbug-mcp:
build:
context: ../..
dockerfile: services/mcp/Dockerfile
target: base
environment:
PORT: "8080"
BUGZILLA_API_KEY: ${BUGZILLA_API_KEY:-}
BUGZILLA_URL: ${BUGZILLA_URL:-https://bugzilla.mozilla.org}
PHABRICATOR_API_KEY: ${PHABRICATOR_API_KEY:-}
PHABRICATOR_URL: ${PHABRICATOR_URL:-https://phabricator.services.mozilla.com}
expose:
- "8080"

# Holds the Phabricator key so the agent can fetch each source's raw diff
# over the read-only Conduit proxy without binding a credential itself.
# Holds the Bugzilla and Phabricator keys, serving their read-only MCP tools
# and the Conduit proxy the agent fetches each source's raw diff through, so
# the agent binds no credential itself.
uplift-resolve-broker:
build:
context: ../..
dockerfile: agents/uplift-resolve/Dockerfile
target: broker
environment:
BUGZILLA_API_URL: ${BUGZILLA_API_URL:-https://bugzilla.mozilla.org/rest}
BUGZILLA_API_KEY: ${BUGZILLA_API_KEY:-}
PHABRICATOR_URL: ${PHABRICATOR_URL:-https://phabricator.services.mozilla.com}
PHABRICATOR_API_KEY: ${PHABRICATOR_API_KEY:-}
expose:
Expand All @@ -41,7 +26,6 @@ services:
- TARGET_COMMIT=${TARGET_COMMIT:-}
- SOURCES=${SOURCES:-}
- BUG_ID=${BUG_ID:-}
- BUGBUG_MCP_URL=http://uplift-resolve-bugbug-mcp:8080/mcp
- BROKER_URL=http://uplift-resolve-broker:8765
- SOURCE_REPO=/workspace/firefox
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:?error}
Expand All @@ -52,8 +36,6 @@ services:
- workspace:/workspace
- ${HOME}/hackbot/artifacts:/artifacts
depends_on:
uplift-resolve-bugbug-mcp:
condition: service_started
uplift-resolve-broker:
condition: service_started

Expand Down
31 changes: 25 additions & 6 deletions agents/uplift-resolve/hackbot_agents/uplift_resolve/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class AgentInputs(BaseSettings):
# The patches to apply onto the branch, in this order; a stack is several.
sources: list[UpliftSource]

# The bugbug MCP, serving the bug, revision and fx-docs tools.
bugbug_mcp_url: str

# The broker sidecar, whose Conduit proxy diffs are fetched through.
# The broker sidecar, serving the Bugzilla and Phabricator tools and the
# Conduit proxy diffs are fetched through.
broker_url: str

# The originating bug, for context when a conflict's intent is unclear.
Expand All @@ -50,6 +48,23 @@ class AgentInputs(BaseSettings):
# Compose passes unset inputs as empty strings (``${BUG_ID:-}``).
model_config = SettingsConfigDict(extra="ignore", env_ignore_empty=True)

def broker_endpoint(self, path: str) -> str:
return f"{self.broker_url.rstrip('/')}/{path.lstrip('/')}"

@property
def bugzilla_mcp_url(self) -> str:
return self.broker_endpoint("/bugzilla/mcp")

@property
def phabricator_mcp_url(self) -> str:
"""The broker's Phabricator MCP endpoint.

Derived from the broker URL rather than taken as its own input: both
endpoints are served by the same sidecar, so there is nothing for a
caller to configure independently.
"""
return self.broker_endpoint("/phabricator/mcp")


async def main(ctx: HackbotContext) -> UpliftResult:
inputs = AgentInputs()
Expand All @@ -60,9 +75,13 @@ async def main(ctx: HackbotContext) -> UpliftResult:
source_repo = await ctx.prepare_repo(ref=ref)

return await run_uplift(
bugbug_mcp_server={
bugzilla_mcp_server={
"type": "http",
"url": inputs.bugzilla_mcp_url,
},
phabricator_mcp_server={
"type": "http",
"url": inputs.bugbug_mcp_url,
"url": inputs.phabricator_mcp_url,
},
broker_url=inputs.broker_url,
source_repo=source_repo,
Expand Down
22 changes: 13 additions & 9 deletions agents/uplift-resolve/hackbot_agents/uplift_resolve/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class UpliftResult(HackbotAgentResult):

async def run_uplift(
*,
bugbug_mcp_server: McpServerConfig,
bugzilla_mcp_server: McpServerConfig,
phabricator_mcp_server: McpServerConfig,
broker_url: str,
source_repo: Path,
target_branch: str,
Expand Down Expand Up @@ -153,7 +154,7 @@ async def run_uplift(
options = build_options(
source_repo=source_repo,
scratch_out=scratch_out,
mcp_servers=build_mcp_servers(bugbug_mcp_server),
mcp_servers=build_mcp_servers(bugzilla_mcp_server, phabricator_mcp_server),
model=model,
effort=effort,
max_turns=max_turns,
Expand Down Expand Up @@ -212,15 +213,18 @@ def describe_requested(


def build_mcp_servers(
bugbug_mcp_server: McpServerConfig,
bugzilla_mcp_server: McpServerConfig,
phabricator_mcp_server: McpServerConfig,
) -> dict[str, McpServerConfig]:
"""The bugbug server, plus in-process Searchfox and HGMO lookups.
"""The broker's Bugzilla and Phabricator tools, plus in-process Searchfox and HGMO.

No Firefox build tools: resolving a conflict is a source-level judgment,
and a build would need the toolchain image `build-repair` carries.
The broker holds the API keys and talks to this environment's Bugzilla and
Phabricator. No Firefox build tools: resolving a conflict is a source-level
judgment, and a build would need the toolchain image `build-repair` carries.
"""
return {
"bugbug": bugbug_mcp_server,
"bugzilla": bugzilla_mcp_server,
"phabricator": phabricator_mcp_server,
"searchfox": build_sdk_server(
"searchfox",
SearchfoxContext(client=AsyncSearchfoxClient()),
Expand Down Expand Up @@ -323,8 +327,8 @@ def render_bug_block(bug_id: int | None) -> str:
return ""
return (
f"## Originating bug\n\n"
f"These patches belong to bug {bug_id}. Consult it with `get_bugzilla_bug` "
f"when a conflict's intent is unclear."
f"These patches belong to bug {bug_id}. Consult it with `get_bugs` and "
f"`get_bug_comments` when a conflict's intent is unclear."
)


Expand Down
79 changes: 69 additions & 10 deletions agents/uplift-resolve/hackbot_agents/uplift_resolve/broker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
"""Read-only Phabricator Conduit broker.
"""Bugzilla and Phabricator broker for the uplift agent.

Sidecar holding the Phabricator API key, reached by the agent over loopback in
the same Cloud Run Job task. The agent container binds no credential.
Sidecar holding the Bugzilla and Phabricator API keys, reached by the agent over
loopback in the same Cloud Run Job task. The agent container binds no credential:

Only `/phabricator/api` is mounted: the model's Bugzilla and Phabricator tools
come from the bugbug MCP, and the broker exists solely so agent code can fetch
each source's diff before the prompt is rendered. `phabricator_proxy`
allow-lists the read methods that needs and substitutes the real key.
- Bugzilla: the read-only `bugzilla` MCP tools over `/bugzilla/mcp`, so the model
can read the originating bug.
- Phabricator: the read-only `phabricator` MCP tools over `/phabricator/mcp`, so
the model can read each source revision's title, summary and comments.
- Phabricator: `/phabricator/api` mounts a read-only Conduit proxy
(``phabricator_proxy``), which agent code fetches each source's diff through
before the prompt is rendered. It allow-lists read methods and substitutes the
real key.
"""

import logging
from contextlib import asynccontextmanager

import bugsy
import uvicorn
from agent_tools import bugzilla
from agent_tools import phabricator as phabricator_tools
from agent_tools.bugzilla import BugzillaContext
from agent_tools.claude_sdk import build_sdk_server
from agent_tools.phabricator import PhabricatorContext
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
from phabricator_client import PhabricatorClient, PhabricatorSettings
from phabricator_proxy import create_app as conduit_proxy
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand All @@ -22,6 +34,8 @@


class BrokerInputs(BaseSettings):
bugzilla_api_url: str
bugzilla_api_key: str
phabricator: PhabricatorSettings
host: str = "0.0.0.0"
port: int = 8765
Expand All @@ -33,10 +47,55 @@ class BrokerInputs(BaseSettings):
)


def mcp_endpoint(manager: StreamableHTTPSessionManager):
"""An ASGI app serving one MCP server over streamable HTTP."""

async def handler(scope, receive, send):
await manager.handle_request(scope, receive, send)

return handler


def build_app(inputs: BrokerInputs) -> Starlette:
client = PhabricatorClient(inputs.phabricator)
log.info("broker serving the read-only Conduit proxy on %s", inputs.port)
return Starlette(routes=[Mount("/phabricator/api", app=conduit_proxy(client))])
bugzilla_client = bugsy.Bugsy(
api_key=inputs.bugzilla_api_key, bugzilla_url=inputs.bugzilla_api_url
)
bugzilla_config = build_sdk_server(
"bugzilla", BugzillaContext(client=bugzilla_client), bugzilla.TOOLS
)
bugzilla_manager = StreamableHTTPSessionManager(
app=bugzilla_config["instance"], stateless=True
)

phabricator_client = PhabricatorClient(inputs.phabricator)
phabricator_config = build_sdk_server(
"phabricator",
PhabricatorContext(client=phabricator_client),
phabricator_tools.TOOLS,
)
phabricator_manager = StreamableHTTPSessionManager(
app=phabricator_config["instance"], stateless=True
)

@asynccontextmanager
async def lifespan(app):
async with bugzilla_manager.run(), phabricator_manager.run():
log.info(
"broker ready on %s:%d (bugzilla + phabricator read-only, "
"phabricator conduit proxy)",
inputs.host,
inputs.port,
)
yield

return Starlette(
routes=[
Mount("/bugzilla/mcp", app=mcp_endpoint(bugzilla_manager)),
Mount("/phabricator/mcp", app=mcp_endpoint(phabricator_manager)),
Mount("/phabricator/api", app=conduit_proxy(phabricator_client)),
],
lifespan=lifespan,
)


def main() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ For a **Phabricator** source (a revision id):
`git apply --3way <diff-file>`
4. Resolve any conflicts and commit the fixed patch. A raw diff carries no
commit message, so do not write one yourself: read the revision's title and
summary with `get_phabricator_revision` and commit under those, ending the
summary with `get_revision` and commit under those, ending the
message with a `Differential Revision: <the revision's URI>` line.

If no base commit is listed, Phabricator never recorded one. Try the apply
Expand All @@ -45,10 +45,9 @@ Resolve conflicts while preserving the _intent_ of the original patch while
fitting the code as it exists on the target branch:

- When the intent is not obvious from the diff alone, consult the originating
bug (`get_bugzilla_bug`) and the Phabricator revision (`get_phabricator_revision`)
through the bugbug MCP. Read both before resolving a non-trivial conflict.
- Use `read_fx_doc_section` when you need Firefox architecture or workflow
context.
bug (`get_bugs`, `get_bug_comments`) and the Phabricator revision
(`get_revision`, `get_revision_comments`). Read both before resolving a
non-trivial conflict.
- Never drop the patch's functional change to make a conflict "go away", and
never invent behavior the patch did not have. If a hunk simply does not apply
because the surrounding feature is absent on the branch, that is a real signal
Expand All @@ -60,6 +59,10 @@ You work like a local Claude Code session: `Read`/`Grep`/`Glob`/`Edit`/`Write`,
`Bash` for git, and `Task` sub-agents for parallel investigation. On top of the
built-ins, the following Mozilla MCP servers are wired in:

- **bugzilla** — read bugs, their comments, history and attachments. Use it to
understand what the originating bug was fixing.
- **phabricator** — read a revision's title, summary, reviewers and comments.

- **searchfox** — search mozilla-central by identifier, text, or definition, and
read blame. Use it to understand how the code the patch touches evolved on the
branch, and to find the modern location of code the patch expected.
Expand Down
3 changes: 2 additions & 1 deletion agents/uplift-resolve/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description = "Cloud Run Job image that runs the uplift conflict-resolution agen
requires-python = ">=3.14"
dependencies = [
"hackbot-runtime[claude-sdk]",
"agent-tools[searchfox,vcs]",
"agent-tools[bugzilla,searchfox,vcs]",
"bugsy",
"claude-agent-sdk>=0.1.30",
"mcp>=1.0.0",
"phabricator-client",
Expand Down
61 changes: 61 additions & 0 deletions agents/uplift-resolve/tests/test_broker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Tests for the uplift broker's route wiring and inputs."""

from hackbot_agents.uplift_resolve import broker
from phabricator_client import PhabricatorSettings
from starlette.applications import Starlette
from starlette.routing import Mount
from starlette.testclient import TestClient

VALID_TOKEN = "api-" + "a" * 28


def build_test_app() -> Starlette:
return broker.build_app(
broker.BrokerInputs(
bugzilla_api_url="https://bugzilla.example.com/rest",
bugzilla_api_key="bz-key",
phabricator=PhabricatorSettings(
url="https://phab.example.com", api_key=VALID_TOKEN
),
)
)


def test_inputs_read_bugzilla_and_phabricator_config_from_env(monkeypatch):
monkeypatch.setenv("BUGZILLA_API_URL", "https://bugzilla.example.com/rest")
monkeypatch.setenv("BUGZILLA_API_KEY", "bz-key")
monkeypatch.setenv("PHABRICATOR_URL", "https://phab.example.com")
monkeypatch.setenv("PHABRICATOR_API_KEY", VALID_TOKEN)

inputs = broker.BrokerInputs()

assert inputs.bugzilla_api_url == "https://bugzilla.example.com/rest", (
"The Bugzilla URL should come from `BUGZILLA_API_URL`, as Terraform sets it."
)
assert inputs.bugzilla_api_key == "bz-key", (
"The Bugzilla key should come from `BUGZILLA_API_KEY`."
)
assert inputs.phabricator.api_key == VALID_TOKEN, (
"The Phabricator key should come from `PHABRICATOR_API_KEY`."
)


def test_app_mounts_every_endpoint_the_agent_uses():
mounts = {
route.path for route in build_test_app().routes if isinstance(route, Mount)
}

assert mounts == {"/bugzilla/mcp", "/phabricator/mcp", "/phabricator/api"}, (
"The broker should serve the Bugzilla and Phabricator MCP tools and the "
"Conduit proxy the agent fetches diffs through."
)


def test_conduit_proxy_refuses_writes():
response = TestClient(build_test_app()).post(
"/phabricator/api/differential.revision.edit"
)

assert response.status_code == 403, (
"The Conduit proxy should be mounted, and refuse to forward a write."
)
Loading