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
1 change: 1 addition & 0 deletions agents/bug-fix/hackbot_agents/bug_fix/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"phabricator.submit_patch",
"phabricator.update_patch",
"phabricator.add_comment",
"phabricator.mark_inline_comments_done",
"feedback.report_problem",
]

Expand Down
2 changes: 2 additions & 0 deletions agents/bug-fix/hackbot_agents/bug_fix/prompts/follow-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Then address each quoted comment by taking the matching path:

A single review can mix these: make the code changes and commit message edits it asks for and answer the questions it raises in the same run.

When you address inline comments as instructed, including ones a quoted comment points you to, record `phabricator_mark_inline_comments_done` for them so reviewers can see what is resolved. Leave a comment open if you did not address it, or addressed it differently from what it asked.

If you are unsure, prefer answering with a comment over making speculative code changes.
33 changes: 33 additions & 0 deletions libs/hackbot-runtime/hackbot_runtime/actions/phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,37 @@ async def add_comment(
return confirmation(action)


@tool
async def mark_inline_comments_done(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think making it comment by comment would be better, the reasoning would be also more useful. WDYT?

recorder: ActionsRecorder,
revision_id: Annotated[
int,
Field(description="Differential revision the comments are on (the D number)."),
],
comment_phids: Annotated[
list[str],
Field(
description=(
"The 'comment_phid' of each inline comment to mark as done, as "
"returned by get_revision_comments."
)
),
],
reasoning: Annotated[
str, Field(description="Why these comments are done (for audit log).")
],
) -> str:
"""Record marking inline comments on a Phabricator revision as done.

Recorded into the run summary for human review; nothing is changed on
Phabricator during the run.
"""
action = recorder.record(
"phabricator.mark_inline_comments_done",
{"revision_id": revision_id, "comment_phids": comment_phids},
reasoning=reasoning,
)
return confirmation(action)


TOOLS = tools_in(__name__)
23 changes: 23 additions & 0 deletions services/hackbot-api/app/action_handlers/phabricator_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ async def apply(self, params: dict[str, Any], ctx: ApplyContext) -> ActionResult
)


class MarkInlineCommentsDoneHandler:
async def apply(self, params: dict[str, Any], ctx: ApplyContext) -> ActionResult:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It does not seem that we group the transactions.

revision_id = params["revision_id"]
try:
await _conduit_request(
"differential.revision.edit",
objectIdentifier=revision_id,
transactions=[
{
"type": "inline.done",
"value": {"commentPHID": phid, "done": True},
}
for phid in params["comment_phids"]
],
)
except Exception as exc:
log.exception(
"Failed to mark inline comments done on revision D%s", revision_id
)
return ActionResult.failed(str(exc))
return ActionResult.ok()


class SubmitPatchHandler:
"""Applies ``phabricator.submit_patch``: the diff becomes a new revision.

Expand Down
2 changes: 2 additions & 0 deletions services/hackbot-api/app/action_handlers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AddCommentHandler as PhabricatorAddCommentHandler,
)
from app.action_handlers.phabricator_handler import (
MarkInlineCommentsDoneHandler,
SubmitPatchHandler,
UpdatePatchHandler,
)
Expand All @@ -42,6 +43,7 @@
"phabricator.submit_patch": SubmitPatchHandler(),
"phabricator.update_patch": UpdatePatchHandler(),
"phabricator.add_comment": PhabricatorAddCommentHandler(),
"phabricator.mark_inline_comments_done": MarkInlineCommentsDoneHandler(),
"github.add_comment": GitHubAddCommentHandler(),
"github.add_inline_comments": AddInlineCommentsHandler(),
"github.submit_patch": GitHubSubmitPatchHandler(),
Expand Down
35 changes: 35 additions & 0 deletions services/hackbot-api/tests/test_phabricator_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,41 @@ async def test_add_comment_posts_comment_transaction(monkeypatch):
]


async def test_mark_inline_comments_done_sends_one_inline_done_per_comment(monkeypatch):
fake, calls = _fake_conduit({"differential.revision.edit": {"object": {"id": 42}}})
monkeypatch.setattr(phabricator_handler, "_conduit_request", fake)

result = await phabricator_handler.MarkInlineCommentsDoneHandler().apply(
{"revision_id": 42, "comment_phids": ["PHID-XCMT-1", "PHID-XCMT-2"]},
ApplyContext(
run_id="run-1",
agent="test-agent",
download_artifact=None,
hackbot_client=object(),
),
)

assert result.status == "applied"
assert calls == [
(
"differential.revision.edit",
{
"objectIdentifier": 42,
"transactions": [
{
"type": "inline.done",
"value": {"commentPHID": "PHID-XCMT-1", "done": True},
},
{
"type": "inline.done",
"value": {"commentPHID": "PHID-XCMT-2", "done": True},
},
],
},
)
]


async def test_add_comment_conduit_error_fails(monkeypatch):
async def fake(method, **payload):
raise RuntimeError("Conduit error ERR-CONDUIT-CORE: nope")
Expand Down