Skip to content

Preserve frontmatter comments and formatting during workflow updates - #74945

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-gh-aw-update-frontmatter-again
Nov 5, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/fix-gh-aw-update-frontmatter-again

Conversation

Copilot AI commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Conflict-free gh aw update merges re-serialized frontmatter containing imports, dropping comments, reordering keys, and reflowing lists—even when no import changed.

  • Targeted import edits: Return unchanged content verbatim; otherwise replace only affected YAML scalar values. Preserve comments, quoting, key order, and layout, with serialization as a fallback for unsupported shapes.
  • Legacy compatibility: Retain conflict-free merging for previously canonicalized installations, including independent local edits.
  • Regression coverage: Cover unchanged imports, exact path-only rewrites, commented merges, and legacy formatting.
 imports:
-  - uses: shared/control.md # Shared behavior
+  - uses: owner/repo/workflows/shared/control.md@sha # Shared behavior

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gh aw update to preserve frontmatter comments Preserve frontmatter comments and formatting during workflow updates Nov 4, 2026
Copilot AI requested a review from pelikhan November 4, 2026 20:10
@pelikhan
pelikhan marked this pull request as ready for review November 4, 2026 20:39
Copilot AI adaptive review requested due to automatic review settings November 4, 2026 20:39
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #74945

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: gpt56 max · ~1 AIC · ⌖ ~1 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR adds a lot of core business logic (348 new lines in pkg/) but doesn't link to an Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/74945-surgical-yaml-scalar-edits-for-import-rewrites.md. Please review and complete it before merging.

The draft is based on the diff. It records the decision to rewrite imports: entries in place, one YAML value at a time, using positions from the yaml.v3 node tree. Each edit is verified by re-parsing and comparing the result to the expected frontmatter. Shapes that can't be edited safely fall back to the old serialization path. Merge inputs that older updates already reformatted are normalized so those installs still merge without conflicts.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff.

  2. Complete the missing sections: add context the AI couldn't infer, refine the decision rationale, and list the alternatives you actually considered.

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-74945: Surgical YAML Scalar Edits for Import Rewrites During Workflow Updates (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and check that the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: opus55 medium · ~28 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What this change does: This change adds a YAML-node-based in-place import path rewrite so comments, quoting, ordering, and layout survive updates, with serialization as a fallback. It also adds a compatibility path for older canonicalized installations during three-way merges.

Should fix:

  1. Legacy canonicalization does a redundant full parse (`pkg/cli/update_merge.go:L154-L166)

    • What this is: canonicalImportMergeContent serializes the parsed frontmatter and then calls RemoveTopLevelFieldFromFrontmatter on that newly generated content.
    • Problem: MergeWorkflowContent already removes source from all three inputs before this helper runs, so every legacy merge reparses and rebuilds the same YAML without changing it.
    • Fix: Return canonical, nil directly, or remove source from the map before marshaling.
    • If we skip it: Legacy merges keep paying for an unnecessary parse and retain an extra transformation path.

Verdict: fix 1 first.
Not checked: The targeted Go tests could not run because the installed toolchain attempted a download and TLS verification failed.
Lean: -1 lines possible.

Generated by ✂️ Ponytail Reviewer for #74945 · codex · routed: gpt56 max · ~6 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again

Comment thread pkg/cli/update_merge.go Outdated
if err != nil {
return "", err
}
return RemoveTopLevelFieldFromFrontmatter(canonical, "source")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lean: base, current, and new have already had source removed before this helper is called, so this serializes the YAML and then reparses/rebuilds it through RemoveTopLevelFieldFromFrontmatter for no work; return canonical, nil (or remove source before marshaling) to avoid the redundant full parse on every legacy merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

canonicalImportMergeContent now returns the already source-free canonical content directly, avoiding the redundant parse/rebuild. Included in 643ed76.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fallback in pkg/cli/update_merge.go discards upstream frontmatter comments and authored field order during otherwise conflict-free merges, requiring formatting preservation and exact-output regression coverage.

1 open issue
What changed in this PR

This PR reduces formatting churn in gh aw update by preserving frontmatter text during import processing, while adding compatibility handling for previously canonicalized installations.

Changes:

  • Return unchanged imports verbatim and edit changed import scalars in place, with serialization as a fallback.
  • Add legacy-format normalization to the three-way merge flow.
  • Add regression tests for formatting preservation, import rewrites, and legacy merges.
File Description
pkg/​cli/​update_merge.go Adds legacy frontmatter normalization before merging.
pkg/​cli/​update_merge_test.go Tests commented workflows and legacy merge scenarios.
pkg/​cli/​imports.go Adds targeted import edits that preserve surrounding YAML.
pkg/​cli/​imports_test.go Tests unchanged content, scalar rewrites, and serialization fallbacks.

Review effort: Balanced (auto)

Comment thread pkg/cli/update_merge.go Outdated
Comment on lines +147 to +151
canonicalUpstream, err := canonicalImportMergeContent(upstream)
if err != nil {
return base, current, upstream
}
return stringutil.NormalizeWhitespace(canonicalBase), current, stringutil.NormalizeWhitespace(canonicalUpstream)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Legacy normalization now bypasses matching base/current frontmatter and restores upstream frontmatter formatting for genuine legacy merges. Exact-output regressions cover both cases. Commit: 643ed76.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-04T20:43:34Z
review_event: REQUEST_CHANGES
top_themes: upstream formatting loss during legacy merge normalization
files_reviewed: pkg/cli/imports.go, pkg/cli/imports_test.go, pkg/cli/update_merge.go, pkg/cli/update_merge_test.go
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~8 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes: the legacy merge compatibility path can erase upstream frontmatter comments and authored formatting before merging.

Highlights
  • Preserve the raw upstream representation when entering the legacy normalization path.
  • Add regression coverage proving upstream comments and field order survive.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~8 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

Comment thread pkg/cli/update_merge.go Outdated
if err != nil {
return base, current, upstream
}
return stringutil.NormalizeWhitespace(canonicalBase), current, stringutil.NormalizeWhitespace(canonicalUpstream)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This legacy compatibility path canonicalizes the upstream input and silently discards its comments, quoting, and field order before the three-way merge.

💡 Preserve authored upstream formatting

When the current file happens to match the canonical form, canonicalImportMergeContent(upstream) reserializes the upstream workflow, so comments and layout that the PR otherwise promises to preserve are lost even when the merge is conflict-free. Keep the upstream text in its authored form (normalize only the comparison/base representation as needed), and add an assertion that upstream comments survive this legacy path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The legacy merge path now preserves raw upstream comments and authored field order instead of retaining the serialized fallback output. Commit: 643ed76.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/update_merge.go:166): Lean: base, current, and new have already had source removed before this helper is called, so this serializes the YAML and then reparses/rebuilds it through RemoveTopLevelFieldFromFrontmatter for no work; return canonical, nil (or remove source before marshaling) to avoid the redundant full parse on every legacy merge. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)
  3. Review (pkg/cli/update_merge.go:151): This fallback serializes upstream frontmatter from a map, discarding its comments and authored field order before a conflict-free merge. It runs both for legacy installations with local frontmatter edits and for already-canonical base/current frontmatter with only local Markdown edits, so even an upstream-only comment addition can disappear. Bypass legacy normalization when base/current frontmatter already match, and preserve raw upstream formatting when reconciling genuine legacy edits; cover both cases with exact-output regression tests. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)
  4. Review (pkg/cli/update_merge.go:151): This legacy compatibility path canonicalizes the upstream input and silently discards its comments, quoting, and field order before the three-way merge. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: 07940e4
Sous-chef requested-work: 061face2fb2964792ea3363903a607a2947d5210aba221fedd7b43eabd2e9405 83d63d8914ad1a7993333b911d1d723b02b1bca96cffbbdbfc22ea0e67160d69 87fa57e7d4c7ff7bf2f44a98baf78c4243e6564d40a251becc46ced6a1615bbc
Sous-chef requested-state: dda58cbddba1ca445cfdf3a3e7211fedb0aca1b960d93effcfd9ea965f8e8584

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~15 AIC · ⌖ ~14 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/update_merge.go:166): Lean: base, current, and new have already had source removed before this helper is called, so this serializes the YAML and then reparses/rebuilds it through RemoveTopLevelFieldFromFrontmatter for no work; return canonical, nil (or remove source before marshaling) to avoid the redundant full parse on every legacy merge. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)
  3. Review (pkg/cli/update_merge.go:151): This fallback serializes upstream frontmatter from a map, discarding its comments and authored field order before a conflict-free merge. It runs both for legacy installations with local frontmatter edits and for already-canonical base/current frontmatter with only local Markdown edits, so even an upstream-only comment addition can disappear. Bypass legacy normalization when base/current frontmatter already match, and preserve raw upstream formatting when reconciling genuine legacy edits; cover both cases with exact-output regression tests. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)
  4. Review (pkg/cli/update_merge.go:151): This legacy compatibility path canonicalizes the upstream input and silently discards its comments, quoting, and field order before the three-way merge. - Preserve frontmatter comments and formatting during workflow updates #74945 (comment)

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: 07940e4
Sous-chef requested-work: 061face2fb2964792ea3363903a607a2947d5210aba221fedd7b43eabd2e9405 83d63d8914ad1a7993333b911d1d723b02b1bca96cffbbdbfc22ea0e67160d69 87fa57e7d4c7ff7bf2f44a98baf78c4243e6564d40a251becc46ced6a1615bbc
Sous-chef requested-state: dda58cbddba1ca445cfdf3a3e7211fedb0aca1b960d93effcfd9ea965f8e8584

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~15 AIC · ⌖ ~9 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

@pelikhan

pelikhan commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot assignment requested for the following outstanding work:...

Sous-chef requested-head: 07940e4
Sous-chef requested-work: 061face2fb2964792ea3363903a607a2947d5210aba221fedd7b43eabd2e9405 83d63d8914ad1a7993333b911d1d723b02b1bca96cffbbdbfc22ea0e67160d69 87fa57e7d4c7ff7bf2f44a98baf78c4243e6564d40a251becc46ced6a1615bbc
Sous-chef requested-state: dda58cbddba1ca445cfdf3a3e7211fedb0aca1b960d93effcfd9ea965f8e8584

@copilot resolve the merge conflicts in this pull request

Merged latest main, resolved both Go conflicts, and committed the merge as 643ed76.

Copilot AI and others added 3 commits November 5, 2026 06:36
…ate-frontmatter-again

# Conflicts:
#	pkg/cli/imports.go
#	pkg/cli/update_merge.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit 16e90f3 into main Nov 5, 2026
36 checks passed
@pelikhan
pelikhan deleted the copilot/fix-gh-aw-update-frontmatter-again branch November 5, 2026 15:34
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh aw update drops every frontmatter comment and reorders keys on a conflict-free merge

4 participants