Repository navigation
Preserve workflow frontmatter when imports do not change - #74931
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: 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.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
There was a problem hiding this comment.
What this change does: Import processing now returns the original workflow bytes when imports are already resolved or local, so comments and formatting survive no-op updates. The merge path also adds a compatibility escape hatch for files canonicalized by older updates.
Nice to have:
-
Avoid parsing the same merge inputs twice (
pkg/cli/update_merge.go:L110-140)- What this is: The legacy-format check parses all three inputs, then canonicalizes base and current by parsing them again.
- Problem: The one-use
canonicalizeImportsForMergewrapper adds a second parse and YAML round trip to a predicate that already has the parsed inputs. - Fix: Keep the
FrontmatterResultvalues from the first pass and callreconstructWorkflowFileFromMapon their maps and markdown directly; delete the wrapper. - If we skip it: Every conflict that reaches this compatibility path carries duplicate parsing logic and another helper to maintain.
Not checked: Focused Go tests could not run because the checkout tried to download Go 1.27.3 and the configured TLS certificate rejected the module proxy.
Verdict: fix 1 when convenient.
Lean: -9 lines possible.
Generated by ✂️ Ponytail Reviewer for #74931 · codex · routed: gpt56 max · ~5 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
|
|
||
| // canonicalizeImportsForMerge retains the old merge representation when a | ||
| // formatting-only difference in previously rewritten imports causes a conflict. | ||
| func canonicalizeImportsForMerge(content string) (string, error) { |
There was a problem hiding this comment.
Nice to have: This conflict-only predicate parses base, current, and upstream, then parses base and current again through the one-use canonicalizeImportsForMerge wrapper. Keep the parsed results and call reconstructWorkflowFileFromMap on them directly; that removes the wrapper and duplicate YAML parsing without changing the compatibility check.
There was a problem hiding this comment.
Fixed in a04843a. Conflict recovery reuses the parsed frontmatter and normalizes only the imports block, avoiding duplicate parsing.
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Review complete: I found one merge-correctness risk and one misleading diagnostic. The new byte-preservation behavior can mix raw and canonical frontmatter across three-way merge inputs, causing spurious conflicts; the legacy fallback also logs a conflict after resolving it.
Highlights
- Keep merge inputs in a consistent representation when imports are rewritten independently.
- Log conflict warnings only when the final merge remains conflicted.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
| } | ||
| hasConflicts = false | ||
| } | ||
| updateMergeLog.Printf("Merge conflicts detected: exit_code=%d", exitCode) |
There was a problem hiding this comment.
When the legacy-formatting fallback clears hasConflicts, this log and verbose warning still report a conflict even though the merge was resolved cleanly, misleading users and diagnostics.
💡 Log only unresolved conflicts
Move the conflict log and warning into the branch where hasConflicts remains true, or emit a distinct resolution message when the fallback succeeds. The final status should not contradict the returned hasConflicts=false.
There was a problem hiding this comment.
Fixed in a04843a. Conflict diagnostics are emitted only if the normalized retry still reports conflicts.
There was a problem hiding this comment.
🟡 Changes recommended
The merge fallback can silently discard local inline YAML comments without reporting a conflict, while restrictive guards leave recoverable legacy-formatting conflicts unresolved.
3 open issues
What changed in this PR
This PR addresses #74878 by preserving workflow frontmatter during gh aw update when import paths do not change, while retaining path resolution and adding legacy merge compatibility handling.
Changes:
- Return original content unchanged when no import path is rewritten.
- Add a fallback for merge conflicts caused by earlier frontmatter normalization.
- Add regression coverage for formatting preservation and merges with local imports.
| File | Description |
|---|---|
pkg/cli/update_merge.go |
Adds legacy-formatting conflict detection and recovery. |
pkg/cli/update_command_test.go |
Tests comment preservation when merging workflows with local imports. |
pkg/cli/imports.go |
Skips frontmatter reconstruction when imports remain unchanged. |
pkg/cli/imports_test.go |
Tests byte-for-byte preservation for unchanged list and object imports. |
Review effort: Balanced (auto)
| return false | ||
| } | ||
| for _, line := range parsed.FrontmatterLines { | ||
| if strings.HasPrefix(strings.TrimSpace(line), "#") { |
There was a problem hiding this comment.
Fixed in a04843a. The retry preserves raw non-import frontmatter, so local inline comments remain and overlapping upstream edits still conflict.
| for _, input := range []string{base, current, upstream} { | ||
| parsed, err := parser.ExtractFrontmatterFromContent(input) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| if _, ok := parsed.Frontmatter["imports"]; !ok { | ||
| return false | ||
| } | ||
| for _, line := range parsed.FrontmatterLines { | ||
| if strings.HasPrefix(strings.TrimSpace(line), "#") { | ||
| return false | ||
| } |
There was a problem hiding this comment.
Fixed in a04843a. Recovery now tolerates comments and upstream import removal; it normalizes only safe imports blocks and retries a three-way merge.
| canonicalCurrent, err := canonicalizeImportsForMerge(current) | ||
| return err == nil && canonicalBase == canonicalCurrent |
There was a problem hiding this comment.
Fixed in a04843a. Recovery now retries the three-way merge instead of comparing whole files, preserving unrelated local body edits.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd. Requesting changes because the legacy import-merge fallback can silently drop a local inline YAML comment during a conflicting update.
📋 Key Themes & Highlights
Key Themes
- Silent data loss (blocking):
isLegacyImportFormattingOnlyonly rejects full-line#comments. An inline comment such asname: Example # my local notepasses the check, so upstream wins without a conflict. I reproduced this:hasConflicts=falseand the comment is gone. - Untested fallback: the
writeErrbranch andhasConflicts = falsepath inupdate_merge.gohave zero coverage hits.
Positive Highlights
- ✅ The
importChangedshort-circuit inimports.gokeeps unchanged imports byte-identical, which fixes the original re-marshal problem. - ✅ Commented-base cases fall through to conflict instead of dropping comments.
- ✅ The legacy-canonical plus upstream-name-change case merges correctly.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~8 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again
| return false | ||
| } | ||
| for _, line := range parsed.FrontmatterLines { | ||
| if strings.HasPrefix(strings.TrimSpace(line), "#") { |
There was a problem hiding this comment.
[/diagnosing-bugs] The new legacy-merge fallback can silently discard a local inline YAML comment. canonicalizeImportsForMerge re-marshals frontmatter, which drops all comments, but this # check only matches full-line comments. So name: Example # my local note looks formatting-only. If upstream also edits that line, the merge takes upstream with no conflict and the local comment is lost. Before this PR the same input produced conflict markers. I reproduced it: hasConflicts=false and the comment is gone.
💡 Suggested fix
Check current for any # instead of only full-line comments:
currentParsed, err := parser.ExtractFrontmatterFromContent(current)
if err != nil {
return false
}
for _, line := range currentParsed.FrontmatterLines {
if strings.Contains(line, "#") {
return false
}
}I validated this variant against three probes: the inline-comment collision now conflicts, and the commented-base and legacy-canonical cases still merge cleanly. It is conservative: a # inside a quoted value also blocks the fallback, which yields conflict markers, not data loss.
@copilot please address this.
There was a problem hiding this comment.
Fixed in a04843a. The regression case now keeps a local inline comment and reports the overlapping upstream edit as a conflict.
| assert.NotContains(t, merged, "<<<<<<<") | ||
| } | ||
|
|
||
| func TestMergeWorkflowContent_PreservesCommentsWithLocalImport(t *testing.T) { |
There was a problem hiding this comment.
[/tdd] This test covers commented frontmatter with a local import, but nothing covers a local inline comment that collides with an upstream edit. That is the case the legacy fallback currently gets wrong, so add a companion case to lock in the conflict.
💡 Suggested test
base := "---\nname: Example\non: push\nimports:\n - shared/local.md\n---\n\n# Original\n"
current := "---\nname: Example # my local note\non: push\nimports:\n - shared/local.md\nsource: owner/repo/workflows/example.md@v1\n---\n\n# Original\n"
upstream := "---\nname: Example v2\non: push\nimports:\n - shared/local.md\n---\n\n# Original\n"
// expect hasConflicts == true and merged still contains "# my local note"This assertion fails on the current code and should pass once the guard is narrowed.
@copilot please address this.
There was a problem hiding this comment.
Added the requested inline-comment collision regression test in a04843a; it verifies the comment remains present and the merge reports a conflict.
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment, 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: 8569249
|
|
@copilot run pr-finisher skill |
…ate-frontmatter Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |


gh aw updatere-marshaled frontmatter whenever a workflow hadimports:, dropping comments and changing key order and formatting even when no import path changed.gh aw updatedrops frontmatter comments when a workflow hasimports:#74878