Repository navigation
Fix: Keep every trailer in metadata sync - #528
Merged
ModeSevenIndustrialSolutions merged 2 commits intoNov 2, 2026
Merged
ModeSevenIndustrialSolutions merged 2 commits into
ModeSevenIndustrialSolutions merged 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The footer scan can drop Change-Id when an unmanaged trailer follows it, causing Gerrit to reject metadata updates; generic trailer handling and regression coverage are needed.
1 open issue
What changed in this PR
This PR addresses #523 by preserving trailer blocks during GitHub-to-Gerrit metadata sync and improving diagnostics for rejected updates.
Changes:
- Preserve the trailing run of recognized trailers when no G2G metadata block exists.
- Log the change ID, HTTP status, and a bounded Gerrit response body on update failure.
- Add regression tests for trailer preservation and failure logging.
| File | Description |
|---|---|
tests/test_pr_update_detection.py |
Adds trailer-preservation and error-logging tests; strengthens title-sync assertions. |
src/github2gerrit/core.py |
Revises trailer extraction and adds REST failure details to metadata-update warnings. |
Review effort: Balanced
lf-releng-code-monkey-bot Bot
added a commit
to lfreleng-bot-forks/github2gerrit-action
that referenced
this pull request
Nov 2, 2026
The metadata sync rewrites a Gerrit commit message with PUT
/changes/{id}/message, keeping the trailers it finds in the current
message. When the message has no GitHub2Gerrit metadata block, only
the last trailer line survives, so Gerrit rejects the new message
with 409 "missing Change-Id footer".
Add tests, marked strict expected-fail, that split a message as the
tool pushes it and one carrying Issue-ID and Co-authored-by trailers,
and extend the title sync test so the PUT body must keep Change-Id,
GitHub-PR and GitHub-Hash. Also expect the failure log of a rejected
update to carry the HTTP status and Gerrit's response body. A
message without trailers already splits into empty parts, so that
test passes now.
Review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or
Reviewed-by:, which the tool places after GitHub-Hash, would still
end the walk and drop Change-Id. Add expected-fail cases for an
unmanaged trailer at the end and before the final sign-off, a blank
line above the final sign-off, a folded trailer value, a prose last
paragraph and a prose line directly above the trailers. A test that
a trailer-shaped subject is never taken as a trailer passes now.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot Bot
added a commit
to lfreleng-bot-forks/github2gerrit-action
that referenced
this pull request
Nov 2, 2026
The metadata sync rewrites a Gerrit commit message with PUT
/changes/{id}/message, keeping the trailers it finds in the current
message. When the message has no GitHub2Gerrit metadata block, only
the last trailer line survives, so Gerrit rejects the new message
with 409 "missing Change-Id footer".
Add tests, marked strict expected-fail, that split a message as the
tool pushes it and one carrying Issue-ID and Co-authored-by trailers,
and extend the title sync test so the PUT body must keep Change-Id,
GitHub-PR and GitHub-Hash. Also expect the failure log of a rejected
update to carry the HTTP status and Gerrit's response body. A
message without trailers already splits into empty parts, so that
test passes now.
Review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or
Reviewed-by:, which the tool places after GitHub-Hash, would still
end the walk and drop Change-Id. Add expected-fail cases for an
unmanaged trailer at the end and before the final sign-off, a blank
line above the final sign-off, a folded trailer value, a prose last
paragraph and a prose line directly above the trailers. A test that
a trailer-shaped subject is never taken as a trailer passes now.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot Bot
added a commit
to lfreleng-bot-forks/github2gerrit-action
that referenced
this pull request
Nov 2, 2026
When the current Gerrit commit message has no GitHub2Gerrit metadata block, the metadata sync kept only the last trailer line. Messages the tool pushes end with its own sign-off, so Change-Id, GitHub-PR and GitHub-Hash were dropped and Gerrit rejected the rewritten message with 409 "missing Change-Id footer"; the PR title never synced. Walk up from the end of the message while each non-blank line is a trailer and keep the whole run, including blank lines inside it. Recognise a trailer by its shape, git's token rule "Key: value" or a folded continuation line directly below one, rather than by the managed prefix list: review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or Reviewed-by:, which the tool places after GitHub-Hash, stopped a prefix-based walk and lost Change-Id again. The walk stops at the first non-blank line that is not a trailer and never consumes the subject. The metadata-block branch keeps the prefix list, since the block's own Mode:, Topic: and Digest: lines are trailer-shaped. A rejected update logged only the exception text, which names the status but not Gerrit's reason. Log the change, the HTTP status and Gerrit's response body, taken from the requests response the error was raised from, so a failed sync is diagnosable from a run log. Remove the expected-fail markers from the tests this makes pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot
Bot
force-pushed
the
code-monkey/issue-523
branch
from
November 2, 2026 17:03
ef4b512 to
6daada5
Compare
lf-releng-code-monkey-bot Bot
added a commit
to lfreleng-bot-forks/github2gerrit-action
that referenced
this pull request
Nov 2, 2026
The metadata sync rewrites a Gerrit commit message with PUT
/changes/{id}/message, keeping the trailers it finds in the current
message. When the message has no GitHub2Gerrit metadata block, only
the last trailer line survives, so Gerrit rejects the new message
with 409 "missing Change-Id footer".
Add tests, marked strict expected-fail, that split a message as the
tool pushes it and one carrying Issue-ID and Co-authored-by trailers,
and extend the title sync test so the PUT body must keep Change-Id,
GitHub-PR and GitHub-Hash. Also expect the failure log of a rejected
update to carry the HTTP status and Gerrit's response body. A
message without trailers already splits into empty parts, so that
test passes now.
Review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or
Reviewed-by:, which the tool places after GitHub-Hash, would still
end the walk and drop Change-Id. Add expected-fail cases for an
unmanaged trailer at the end and before the final sign-off, a blank
line above the final sign-off, a folded trailer value, a prose last
paragraph and a prose line directly above the trailers. A test that
a trailer-shaped subject is never taken as a trailer passes now.
A further review of lfreleng-actions#528 found that a folded trailer whose first line
is the bare key ("Bug: " or "Bug:", value on the indented line below)
still ended the walk and dropped Change-Id. Add an expected-fail case
for both forms, with Change-Id above and the sign-off below.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot Bot
added a commit
to lfreleng-bot-forks/github2gerrit-action
that referenced
this pull request
Nov 2, 2026
When the current Gerrit commit message has no GitHub2Gerrit metadata block, the metadata sync kept only the last trailer line. Messages the tool pushes end with its own sign-off, so Change-Id, GitHub-PR and GitHub-Hash were dropped and Gerrit rejected the rewritten message with 409 "missing Change-Id footer"; the PR title never synced. Walk up from the end of the message while each non-blank line is a trailer and keep the whole run, including blank lines inside it. Recognise a trailer by its shape, git's token rule "Key: value" or a folded continuation line directly below one, rather than by the managed prefix list: review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or Reviewed-by:, which the tool places after GitHub-Hash, stopped a prefix-based walk and lost Change-Id again. The walk stops at the first non-blank line that is not a trailer and never consumes the subject. The metadata-block branch keeps the prefix list, since the block's own Mode:, Topic: and Digest: lines are trailer-shaped. The trailer shape accepts a bare key as well as "Key: value": the walk matches each line with trailing whitespace stripped, so a folded trailer whose first line is "Bug: " became "Bug:" and, rejected, ended the walk above the sign-off and lost Change-Id again, as a further review of lfreleng-actions#528 found. A rejected update logged only the exception text, which names the status but not Gerrit's reason. Log the change, the HTTP status and Gerrit's response body, taken from the requests response the error was raised from, so a failed sync is diagnosable from a run log. Remove the expected-fail markers from the tests this makes pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot
Bot
force-pushed
the
code-monkey/issue-523
branch
from
November 2, 2026 17:20
6daada5 to
250d970
Compare
The metadata sync rewrites a Gerrit commit message with PUT
/changes/{id}/message, keeping the trailers it finds in the current
message. When the message has no GitHub2Gerrit metadata block, only
the last trailer line survives, so Gerrit rejects the new message
with 409 "missing Change-Id footer".
Add tests, marked strict expected-fail, that split a message as the
tool pushes it and one carrying Issue-ID and Co-authored-by trailers,
and extend the title sync test so the PUT body must keep Change-Id,
GitHub-PR and GitHub-Hash. Also expect the failure log of a rejected
update to carry the HTTP status and Gerrit's response body. A
message without trailers already splits into empty parts, so that
test passes now.
Review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or
Reviewed-by:, which the tool places after GitHub-Hash, would still
end the walk and drop Change-Id. Add expected-fail cases for an
unmanaged trailer at the end and before the final sign-off, a blank
line above the final sign-off, a folded trailer value, a prose last
paragraph and a prose line directly above the trailers. A test that
a trailer-shaped subject is never taken as a trailer passes now.
A further review of lfreleng-actions#528 found that a folded trailer whose first line
is the bare key ("Bug: " or "Bug:", value on the indented line below)
still ended the walk and dropped Change-Id. Add an expected-fail case
for both forms, with Change-Id above and the sign-off below.
A third review of lfreleng-actions#528 found that a trailer with no space after the
colon, such as "Change-Id:I..." or "Bug:\t12345", still ended the
walk, though git and gitutils._parse_trailers accept it. Add
expected-fail cases for a managed Change-Id with no space and for an
unmanaged Bug trailer between Change-Id and the sign-off, written
with a tab, with no space, and with whitespace before the colon.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
When the current Gerrit commit message has no GitHub2Gerrit metadata block, the metadata sync kept only the last trailer line. Messages the tool pushes end with its own sign-off, so Change-Id, GitHub-PR and GitHub-Hash were dropped and Gerrit rejected the rewritten message with 409 "missing Change-Id footer"; the PR title never synced. Walk up from the end of the message while each non-blank line is a trailer and keep the whole run, including blank lines inside it. Recognise a trailer by its shape, a git trailer line or a folded continuation line directly below one, rather than by the managed prefix list: review of lfreleng-actions#528 found that an unmanaged trailer such as Bug: or Reviewed-by:, which the tool places after GitHub-Hash, stopped a prefix-based walk and lost Change-Id again. The walk stops at the first non-blank line that is not a trailer and never consumes the subject. The metadata-block branch keeps the prefix list, since the block's own Mode:, Topic: and Digest: lines are trailer-shaped. The trailer shape follows git interpret-trailers: a token, optional spaces or tabs, the colon, then anything. Two further reviews of lfreleng-actions#528 found narrower patterns losing Change-Id. Demanding a space after the colon rejected a folded trailer's first line "Bug: " once trailing whitespace was stripped, and rejected "Change-Id:I..." and "Bug:\t12345", which git and gitutils._parse_trailers accept. A rejected update logged only the exception text, which names the status but not Gerrit's reason. Log the change, the HTTP status and Gerrit's response body, taken from the requests response the error was raised from, so a failed sync is diagnosable from a run log. Remove the expected-fail markers from the tests this makes pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
lf-releng-code-monkey-bot
Bot
force-pushed
the
code-monkey/issue-523
branch
from
November 2, 2026 17:44
250d970 to
620fea5
Compare
ModeSevenIndustrialSolutions
approved these changes
Nov 2, 2026
ModeSevenIndustrialSolutions
merged commit Nov 2, 2026
585d32d
into
lfreleng-actions:main
33 checks passed
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.

Closes #523
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLI677880bd0efbffa62d0b3a9755245213b23ce198uv run pytest -q tests/test_pr_update_detection.py (test commit fixup, new cases xfail)uv run pytest -q -p no:cacheprovideruv run pytest -q --no-cov tests/test_pr_update_detection.py (at test commit 0ab6153)uv run ruff check src/github2gerrit/core.py tests/test_pr_update_detection.pyuv run ruff format --check src/github2gerrit/core.py tests/test_pr_update_detection.pyuv run mypy src/github2gerrit/core.pyprek run --files src/github2gerrit/core.py tests/test_pr_update_detection.pyuvx gitlint --commits 677880bd..HEADuv run --no-sync aislop scan --base 677880bd --json (0 diagnostics, no engine skipped)git log --raw --format=%h 677880bd..HEAD (no 100755/120000/160000, no mode change)The
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds; a maintainer must act on any finding that remains after that, and reviews every round before merge.
Round 3 of revision, on its base.
What this does
Fixes #523. When the current Gerrit message has no
GitHub2Gerrit Metadata:block,_split_preserved_metadatakept only the last trailer line. Messages the tool pushes end with its own sign-off, so the title sync droppedChange-Id,GitHub-PRandGitHub-Hash, and Gerrit answeredPUT /changes/{id}/messagewith 409missing Change-Id footer.git interpret-trailers: a token, optional spaces or tabs, the:separator, then anything. A folded continuation line directly below a trailer also counts. Blank lines inside the run are kept. The walk stops at the first non-blank line that is not a trailer, and never takes in the subject._find_trailer_start) is unchanged and keeps its prefix list.This round
_TRAILER_LINE_REis now^[A-Za-z][A-Za-z0-9-]*[ \t]*:, with no condition on what follows the colon. It acceptsChange-Id:I…andBug:\t12345, as Copilot's finding and the maintainer's round-3 guidance asked. It also acceptsBug :12345, because git allows spaces or tabs between the key and the separator.GitHub2Gerrit Metadata:still does not match.Added expected-fail regression tests to the test commit:
Change-Id:I…with no space;Bugtrailer betweenChange-Idand the sign-off, in four forms:Bug:\t12345,Bug:12345,Bug :12345andBug\t: 12345.The fix commit removes their markers.
Commits
Test: Add expected-fail trailer split tests: the tests, marked strict xfail.Fix: Keep every trailer in metadata sync: the fix, which removes the markers.Checks run
uv run pytest(full suite, and the test file at the test commit on its own)ruff checkandruff format --checkmypyprek run --fileson the changed filesgitlintover both commitsaislop scan --base(no diagnostics, with no engine skipped)For the reviewer
-there, but no real trailer key starts that way.https://…) directly above the trailers, with no blank line between, is trailer-shaped. Git reads it the same way.