Record the created comment id when applying a Bugzilla comment - #6553
Open
msujaws wants to merge 1 commit into
Open
Record the created comment id when applying a Bugzilla comment#6553msujaws wants to merge 1 commit into
msujaws wants to merge 1 commit into
Conversation
Field changes and a comment ride in one PUT /bug/{id} so Bugzilla applies
them as a single transaction, but that response carries only
{bugs: [{id, changes, last_change_time}]} — no comment id. So nothing in
run_actions.result said which comment an action produced, unlike
AddAttachmentHandler and CreateBugHandler, which do capture their ids.
That matters downstream: both bug-fix and frontend-triage comment from
the same Bugzilla account, so a tool reading feedback off those comments
cannot tell which agent wrote one without joining back through
run_actions — and with no comment id the join has to be inferred from
comment text or timing.
Read the id back instead of switching to POST /bug/{id}/comment, which
would return it directly but split the write into two code paths and give
up the single-transaction coalescing. One shared helper serves both
handlers.
Matching is on the text we posted, not "the newest comment": the latter
would happily pick up an engineer replying in the same moment. Where the
text does not match, no id is reported rather than a guessed one — a
wrong id would silently misattribute a comment, which is worse for the
consumer than a missing one that it can still infer. The read-back is
best-effort in the other direction too: the comment is already posted by
then, so a failure there must not fail the action.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Field changes and a comment ride in one
PUT /bug/{id}so Bugzilla applies them as a single transaction — one bugmail, one history entry. But that response carries only{bugs: [{id, changes, last_change_time}]}, with no comment id. So nothing inrun_actions.resultsaid which comment an action produced, unlikeAddAttachmentHandlerandCreateBugHandler, which do capture their ids.That matters downstream.
bug-fixandfrontend-triagecomment from the same Bugzilla account, so a tool reading feedback off those comments cannot tell which agent wrote one without joining back throughrun_actions— and with no comment id, that join has to be inferred from comment text or timing. (Concretely: mozilla/hackbot-agent-feedback#1.)Approach
Read the id back rather than switching to
POST /bug/{id}/comment. That endpoint returns the id directly, but it would split the write into two code paths and give up the single-transaction coalescing. One shared helper serves both handlers instead.Two deliberate choices in
_resolve_comment_id:is_markdownaffects rendering only, so the stored text is what we sent; normalisation absorbs CRLF and trailing-whitespace round-tripping.The read-back is best-effort in the other direction too: the comment is already posted by the time we get there, so a failure must not turn a successful post into
ActionResult.failed.UpdateBugHandleronly does the lookup when a comment was actually folded in — a changes-only update created nothing to point at.Testing
libs/hackbot-runtimeis green: 211 passed, ruff check and format clean, all pre-commit hooks pass.Seven new cases: id captured on a plain add-comment and on an
update_bugwith a folded comment; whitespace round-trip tolerated; newest of duplicate texts wins; no id when nothing matches; stillappliedwhen the read-back raises; and no extra request for a changes-only update.Three existing tests needed their
_requestmocks widened to serve the second call. Worth flagging:test_add_comment_handler_builds_comment_bodyinitially still passed after the change — its three-arg lambda raisedTypeErroron the new GET, which the deliberately broadexcept Exceptionswallowed. It was passing for the wrong reason, so the mocks now serve both calls explicitly.I also mutation-tested the new cases to confirm they are load-bearing: forcing
_resolve_comment_idto always returnNonefails 4 tests, and making it ignore the text and take the newest comment failstest_add_comment_handler_applied_when_no_text_matches.