Skip to content

feat: self-mint app tokens and classify failures in ensure-pr-passes-merge-queue#754

Merged
bkenez merged 2 commits into
mainfrom
753-merge-queue-monitor-token-refresh
Jul 17, 2026
Merged

feat: self-mint app tokens and classify failures in ensure-pr-passes-merge-queue#754
bkenez merged 2 commits into
mainfrom
753-merge-queue-monitor-token-refresh

Conversation

@bkenez

@bkenez bkenez commented Jul 17, 2026

Copy link
Copy Markdown
Member

Closes #753.

What

  • New optional inputs app-id + private-key: the monitor script mints GitHub App installation tokens itself (JWT via openssl, per the documented bash pattern) and re-mints at 50 minutes or immediately on HTTP 401 — monitoring windows beyond the 1-hour installation-token TTL now survive. app-token remains supported for backward compatibility (short windows only).
  • Consecutive-API-failure aborts now report result=api_failure instead of timeout.
  • Before any non-merged result, one final fresh-token recheck: if the PR merged between the last poll and the abort, the action reports merged (this exact false-alarm hit camunda/camunda-platform-helm 14.7.0, see ensure-pr-passes-merge-queue: installation token expires mid-monitor, API failures mislabeled as timeout #753).
  • New outputs queue-state, queue-position, merge-state-status (last observed) so callers can build informative alerts.
  • Failure to re-enable auto-merge after an eviction also concludes via the recheck path instead of exiting without a result.

Testing

  • shellcheck clean (--external-sources).
  • Offline harness (stubbed gh/curl/sleep, real RSA key so the JWT/openssl path runs for real): 14 cases covering validation, static-token mode, self-mint mode, 401 storms with re-mint, timeout-with-recheck rescue, and all eviction paths (re-queue + merge, eviction limit, auto-merge re-enable failure) — all pass, each asserting exactly one result= write.
  • Callers keep working unchanged with app-token; camunda/camunda-platform-helm will switch both its shepherd workflows to app-id/private-key (Merge-queue shepherd jobs fail with expired app token after 60 minutes camunda-platform-helm#6634).

Copilot AI review requested due to automatic review settings July 17, 2026 14:51

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.

Pull request overview

This PR enhances the ensure-pr-passes-merge-queue composite action to support long monitoring windows by self-minting and refreshing GitHub App installation tokens, while also improving outcome classification and reporting for downstream alerting.

Changes:

  • Add optional app-id / private-key inputs to mint + refresh installation tokens in monitor-merge-queue.sh (while keeping app-token for backward compatibility).
  • Classify consecutive API failures as api_failure (instead of timeout) and add a “final recheck” path for timeout/API-failure conclusions.
  • Add new outputs (queue-state, queue-position, merge-state-status) and update documentation/examples accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ensure-pr-passes-merge-queue/README.md Documents new auth modes, new outputs, and clarifies timeout vs api_failure semantics.
ensure-pr-passes-merge-queue/monitor-merge-queue.sh Implements token mint/refresh, new outputs, API-failure classification, and final recheck logic (currently not applied to all non-merged outcomes).
ensure-pr-passes-merge-queue/action.yml Adds new inputs and wires them into the composite action environment; exposes new outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 205 to 209
if [ "$PR_STATE" = "CLOSED" ]; then
echo "PR was closed without merging"
echo "result=closed" >> "$GITHUB_OUTPUT"
write_outputs "closed"
exit 1
fi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8c7ef4f — the CLOSED branch now concludes via conclude_not_merged "closed", so the final fresh-token recheck applies (a closed-then-merged race reports merged).

Comment on lines 224 to 228
if [ $EVICTION_COUNT -ge "$MAX_EVICTIONS" ]; then
echo "PR evicted $MAX_EVICTIONS times - giving up"
echo "result=evicted" >> "$GITHUB_OUTPUT"
write_outputs "evicted"
exit 1
fi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8c7ef4f — the eviction-limit path now concludes via conclude_not_merged "evicted", matching the documented recheck-before-any-non-merged-outcome behavior. Harness covers both new paths (17 cases, incl. closed/evicted-but-recheck-finds-merged).

@bkenez
bkenez merged commit f74bcfa into main Jul 17, 2026
3 checks passed
@bkenez
bkenez deleted the 753-merge-queue-monitor-token-refresh branch July 17, 2026 15:16
@infra-releases infra-releases Bot mentioned this pull request Jul 18, 2026
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.

ensure-pr-passes-merge-queue: installation token expires mid-monitor, API failures mislabeled as timeout

3 participants