Skip to content

Fix: Keep every trailer in metadata sync - #528

Merged
ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-523
Nov 2, 2026
Merged

ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-523

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #523

Authored by an AI agent; human review required
Command Exit
uv run pytest -q tests/test_pr_update_detection.py (test commit fixup, new cases xfail) 0
uv run pytest -q -p no:cacheprovider 0
uv run pytest -q --no-cov tests/test_pr_update_detection.py (at test commit 0ab6153) 0
uv run ruff check src/github2gerrit/core.py tests/test_pr_update_detection.py 0
uv run ruff format --check src/github2gerrit/core.py tests/test_pr_update_detection.py 0
uv run mypy src/github2gerrit/core.py 0
prek run --files src/github2gerrit/core.py tests/test_pr_update_detection.py 0
uvx gitlint --commits 677880bd..HEAD 0
uv run --no-sync aislop scan --base 677880bd --json (0 diagnostics, no engine skipped) 0
git log --raw --format=%h 677880bd..HEAD (no 100755/120000/160000, no mode change) 0

The github-code-monkey-bot workflow 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_metadata kept only the last trailer line. Messages the tool pushes end with its own sign-off, so the title sync dropped Change-Id, GitHub-PR and GitHub-Hash, and Gerrit answered PUT /changes/{id}/message with 409 missing Change-Id footer.

  • The no-metadata fallback now walks up from the end of the message while each non-blank line is a trailer, and keeps the whole run. A line counts as a trailer by its shape, following 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.
  • The metadata-block branch (_find_trailer_start) is unchanged and keeps its prefix list.
  • A rejected metadata update now logs the change, the HTTP status and Gerrit's response body, not only the exception text.

This round

  • _TRAILER_LINE_RE is now ^[A-Za-z][A-Za-z0-9-]*[ \t]*:, with no condition on what follows the colon. It accepts Change-Id:I… and Bug:\t12345, as Copilot's finding and the maintainer's round-3 guidance asked. It also accepts Bug :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:

    • a managed Change-Id:I… with no space;
    • an unmanaged Bug trailer between Change-Id and the sign-off, in four forms: Bug:\t12345, Bug:12345, Bug :12345 and Bug\t: 12345.

    The fix commit removes their markers.

Commits

  1. Test: Add expected-fail trailer split tests: the tests, marked strict xfail.
  2. 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 check and ruff format --check
  • mypy
  • prek run --files on the changed files
  • gitlint over both commits
  • aislop scan --base (no diagnostics, with no engine skipped)

For the reviewer

  • Keys must still start with a letter. Git also accepts a digit or - there, but no real trailer key starts that way.
  • A URL line (https://…) directly above the trailers, with no blank line between, is trailer-shaped. Git reads it the same way.

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.

🟡 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

Comment thread src/github2gerrit/core.py Resolved
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>

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.

🟡 Changes recommended

The trailer scan still loses Change-Id when rstrip() removes the space after a folded Bug: trailer with an empty first line, requiring a parsing fix and regression test.

1 open issue

Review effort: Balanced

Comment thread src/github2gerrit/core.py Resolved
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>

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.

🟡 Changes recommended

The trailer regex rejects valid no-space and tab-separated values, which can drop Change-Id and cause Gerrit to reject metadata updates.

1 open issue

Review effort: Balanced

Comment thread src/github2gerrit/core.py Resolved
lf-releng-code-monkey-bot Bot and others added 2 commits November 2, 2026 17:44
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>

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.

🟢 Approval recommended

No active review issues were identified in the trailer-preservation and metadata-update diagnostics changes.

No open issues 🎉

Review effort: Balanced

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 585d32d into lfreleng-actions:main Nov 2, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata sync drops Change-Id when the message has no G2G block

2 participants