Skip to content

[codex] Fix post-merge upload SHA correlation - #2593

Open
Erik Osterman (Cloud Posse) (osterman) wants to merge 5 commits into
mainfrom
osterman/fix-post-merge-sha
Open

Erik Osterman (Cloud Posse) (osterman) wants to merge 5 commits into
mainfrom
osterman/fix-post-merge-sha

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

what

  • Use pull_request.merge_commit_sha for native CI uploads from raw merged pull_request.closed events.
  • Preserve open PR and merge queue upload correlation behavior.
  • Add CI diagnostics for PR action, merged flag, PR head SHA, merge commit SHA, checked-out HEAD, and upload head SHA.
  • Update native CI base-resolution docs and regression coverage.

why

  • Post-merge uploads from raw GitHub PR-closed runs can otherwise correlate to the pre-merge PR SHA instead of the commit that landed on the base branch.
  • The change keeps Atmos Pro's synthetic settings.pro.pull_request.merged event behavior unchanged while making the native CI edge explicit.
  • The added diagnostics make future SHA mismatches visible in CI logs.

references

  • GitHub documents pull_request.merge_commit_sha as the landed commit SHA after merge, squash, or rebase.
  • Validated with go test ./pkg/ci/providers/github ./internal/exec and go test ./pkg/ci/....

Summary by CodeRabbit

  • Improvements

    • More reliable upload correlation for merged PRs and richer CI base-resolution diagnostics/logging.
  • Bug Fixes

    • Post-merge runs now use the correct landed commit SHA and sensibly fall back when merge metadata is missing.
  • Documentation

    • Updated native CI base-resolution PRD and added post-merge upload-correlation doc.
  • Tests

    • Added unit tests covering merged-PR upload-correlation scenarios.
  • Chores

    • Updated link-checker exclusions.
  • Examples

    • LocalStack demo README and config clarified to avoid Terraform account-id hangs.

@atmos-pro

atmos-pro Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/m Medium size PR label Jun 10, 2026
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@osterman
Erik Osterman (Cloud Posse) (osterman) marked this pull request as ready for review June 10, 2026 05:15
@osterman Erik Osterman (Cloud Posse) (osterman) added the patch A minor, backward compatible change label Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cad6223b-1afb-4539-a58f-6d00fcd4790f

📥 Commits

Reviewing files that changed from the base of the PR and between 6a91ef9 and bcdf23a.

📒 Files selected for processing (2)
  • examples/demo-localstack/README.md
  • examples/demo-localstack/stacks/mixins/localstack.yaml
✅ Files skipped from review due to trivial changes (1)
  • examples/demo-localstack/README.md

📝 Walkthrough

Walkthrough

This PR makes upload-correlation event-aware for GitHub Actions: it records PR/head/merge metadata in BaseResolution, uses pull_request.merge_commit_sha for closed+merged events (falling back to local HEAD when absent), refactors resolvePRBase to apply metadata consistently, and surfaces these fields in describe_affected logging and tests.

Changes

Merged PR upload correlation support

Layer / File(s) Summary
Data contract and PRD documentation
pkg/ci/internal/provider/types.go, docs/prd/native-ci/framework/base-resolution.md, docs/fixes/2026-06-10-describe-affected-post-merge-upload-sha.md, lychee.toml
BaseResolution gains diagnostic fields (PullRequestHeadSHA, PullRequestMergeCommitSHA, PullRequestMerged, EventAction, LocalHeadSHA); PRD/docs updated to document event-aware upload correlation (open PRs use pull_request.head.sha, merged closed PRs use pull_request.merge_commit_sha); link-checker exclusions updated.
GitHub base resolution refactoring
pkg/ci/providers/github/base.go
resolvePRBase now extracts PR metadata (head SHA, merge commit SHA, merged state, local HEAD), computes upload-correlation head SHA (merge commit SHA for merged closed PRs, else PR head SHA), adds helper extractors, and applies withPRMetadata to populate BaseResolution across merge-base and fallback paths.
Integration into describe_affected
internal/exec/describe_affected.go
resolveBaseFromCI logging now emits extended PR metadata (event action, PR merged/head/merge_commit fields, local checked-out HEAD, upload head SHA). uploadableQuery comments and debug logs clarify HeadSHAOverride vs local HEAD selection.
Test coverage for merged PR scenarios
internal/exec/describe_affected_test.go, pkg/ci/providers/github/base_test.go
Adds an integration test for merged pull_request handling in resolveBaseFromCI and two unit tests for ResolveBase covering merged PRs with and without merge_commit_sha, asserting metadata population and upload-head-SHA fallback behavior.
LocalStack example update
examples/demo-localstack/README.md, examples/demo-localstack/stacks/mixins/localstack.yaml
Enable skip_requesting_account_id and update README to explain the expected Terraform warning for CI usage.
sequenceDiagram
  participant GitHubActions
  participant resolvePRBase
  participant BaseResolution
  participant DescribeAffected
  participant AtmosProUpload
  GitHubActions->>resolvePRBase: deliver pull_request event (pull_request.head.sha, pull_request.merged, pull_request.merge_commit_sha)
  resolvePRBase->>BaseResolution: populate PullRequestHeadSHA, PullRequestMergeCommitSHA, PullRequestMerged, EventAction, LocalHeadSHA, HeadSHA (upload correlation)
  DescribeAffected->>BaseResolution: read HeadSHAOverride / LocalHeadSHA for upload correlation
  DescribeAffected->>AtmosProUpload: send upload correlated by HeadSHA
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • aknysh
  • atmos-pro
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing post-merge upload SHA correlation for native CI workflows.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/fix-post-merge-sha

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/ci/providers/github/base.go (1)

154-163: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Gate HEAD~1 fallback to merged PRs only.

pull_request.closed includes both merged and unmerged closures. Running HEAD~1 for unmerged closures can pick an unrelated parent and produce incorrect base resolution. The fallback should only execute for closed and merged PRs.

Suggested fix
-	// 2) Closed/merged PRs: HEAD~1.
+	// 2) Closed merged PRs: HEAD~1.
 	// Correct when the merge commit is checked out (merge/squash strategies).
-	if action == "closed" {
+	if action == "closed" && merged {
 		if sha, parentErr := resolveParentCommit(); parentErr == nil {
 			return withPRMetadata(&provider.BaseResolution{
 				SHA:    sha,
 				Source: "HEAD~1 (merged PR, merge-base unavailable)",
 			}), nil
 		} else {
-			log.Debug("HEAD~1 failed for merged PR", "error", parentErr)
+			log.Debug("HEAD~1 failed for closed merged PR", "error", parentErr)
 		}
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/ci/providers/github/base.go` around lines 154 - 163, The fallback to use
HEAD~1 should only run for PRs that are both closed and merged; update the
conditional around the resolveParentCommit() call (the block that currently
checks if action == "closed") to also verify the PR is merged (e.g., check the
pull request payload's merged flag or equivalent before calling
resolveParentCommit), so withPRMetadata(&provider.BaseResolution{SHA: sha,
Source: "HEAD~1 (merged PR, merge-base unavailable)"}) only executes for merged
PRs and not for unmerged/closed-but-not-merged events.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/ci/providers/github/base.go`:
- Around line 154-163: The fallback to use HEAD~1 should only run for PRs that
are both closed and merged; update the conditional around the
resolveParentCommit() call (the block that currently checks if action ==
"closed") to also verify the PR is merged (e.g., check the pull request
payload's merged flag or equivalent before calling resolveParentCommit), so
withPRMetadata(&provider.BaseResolution{SHA: sha, Source: "HEAD~1 (merged PR,
merge-base unavailable)"}) only executes for merged PRs and not for
unmerged/closed-but-not-merged events.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 753477f0-2cf3-4c9f-b422-822433ff75f5

📥 Commits

Reviewing files that changed from the base of the PR and between 3c1aba3 and d51a1a8.

📒 Files selected for processing (6)
  • docs/prd/native-ci/framework/base-resolution.md
  • internal/exec/describe_affected.go
  • internal/exec/describe_affected_test.go
  • pkg/ci/internal/provider/types.go
  • pkg/ci/providers/github/base.go
  • pkg/ci/providers/github/base_test.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 10, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 10, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.94%. Comparing base (3c1aba3) to head (bcdf23a).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ci/providers/github/base.go 92.72% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2593      +/-   ##
==========================================
+ Coverage   78.91%   78.94%   +0.03%     
==========================================
  Files        1207     1207              
  Lines      116464   116505      +41     
==========================================
+ Hits        91906    91979      +73     
+ Misses      19488    19454      -34     
- Partials     5070     5072       +2     
Flag Coverage Δ
unittests 78.94% <94.11%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/exec/describe_affected.go 79.86% <100.00%> (+0.77%) ⬆️
pkg/ci/providers/github/base.go 88.46% <92.72%> (+4.14%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 10, 2026
@mergify

mergify Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏

@mergify mergify Bot added the conflict This PR has conflicts label Jun 11, 2026

This branch has not been deployed

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

Labels

conflict This PR has conflicts patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant