Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix: Preserve manually added labels during workflow run and refine label sync logic#917

Merged
HarithaVattikuti merged 2 commits into
actions:mainfrom
chiranjib-swain:fix/label-preservation-and-sync
Jan 22, 2026
Merged

Fix: Preserve manually added labels during workflow run and refine label sync logic#917
HarithaVattikuti merged 2 commits into
actions:mainfrom
chiranjib-swain:fix/label-preservation-and-sync

Conversation

@chiranjib-swain
Copy link
Copy Markdown
Contributor

@chiranjib-swain chiranjib-swain commented Nov 24, 2025

Description:
This pull request updates the labeler function to improve how labels are managed and applied to pull requests, especially when labels may have been added manually or by other bots during the workflow run.

Label management improvements:

  • The label application logic now fetches the latest labels from the pull request before applying new ones, so it can detect labels that were manually added or added by other bots during the workflow run. It merges these with the labels determined by the config, deduplicates them, and enforces the maximum label limit (GITHUB_MAX_LABELS).
  • The output for all-labels now reflects the final set of labels actually applied to the pull request, ensuring outputs are accurate and up-to-date..

Related issue:
(#908 , #763).

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

Copilot AI review requested due to automatic review settings November 24, 2025 05:14
@chiranjib-swain chiranjib-swain requested a review from a team as a code owner November 24, 2025 05:14
Copy link
Copy Markdown

Copilot AI left a comment

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 labeler action to preserve labels that are manually added or added by other bots during the workflow execution, addressing issue #908. The key improvement is fetching the latest PR labels before applying changes, merging them with config-based labels, and ensuring accurate outputs.

  • Fetches latest PR labels to detect manual additions during workflow execution
  • Merges manually added labels with config-based labels while respecting the 100-label limit
  • Updates the 'all-labels' output to reflect the final applied labels

Reviewed changes

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

File Description
src/labeler.ts Implements label fetching and merging logic to preserve manually added labels, updates output to use final applied labels
dist/index.js Compiled/bundled version of the TypeScript changes with identical logic updates

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

Comment thread src/labeler.ts Outdated
Comment thread src/labeler.ts
Comment thread src/labeler.ts
Comment thread src/labeler.ts Outdated
Comment thread src/labeler.ts Outdated
Comment thread src/labeler.ts Outdated
Comment thread src/labeler.ts
Copy link
Copy Markdown

@jnewland jnewland left a comment

Choose a reason for hiding this comment

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

#908 describes a lost update where a user-added label is removed because a setLabels call is made without knowledge of the user-added label. My read of this PR is that it reduces the window of time during which updates can be lost but it does not in any way prevent those lost updates from happening.

I don't believe that ANY approach using setLabels can fix the lost-update problem introduced by #497: setLabels replaces the entire label set in a single write operation, discarding any label changes made since the last read. If concurrent changes are made between the read and write steps - by a user or another workflow - those updates will be overwritten and lost.

I believe the only path towards removing the ability of this action to clobber user writes is to rework it to use addLabels and removeLabels as it did before #497.

Comment thread src/labeler.ts
@chiranjib-swain
Copy link
Copy Markdown
Contributor Author

chiranjib-swain commented Dec 16, 2025

Hi @jnewland ,
Thank you for sharing your thoughts on the label management strategy.

We understand the familiarity with the earlier POST + DELETE approach. After revisiting the long-standing reliability challenges documented in PR #497, we’ve chosen to continue with the setLabels (PUT-based bulk update) method because it offers a more stable and predictable foundation for large or high-activity repositories.

Why we rely on setLabels (PUT)

The previous incremental approach worked for smaller workflows, but at scale it introduced several issues:

  1. High API usage: DELETE removes one label at a time, often triggering rate-limit exhaustion.
  2. Inconsistent retries: The non-atomic POST failed with a 502 error after applying a partial set of over 50 labels. Subsequent retries failed with a 422 error ("more than 100 labels") as the new labels combined with the partially applied ones exceeded the limit.
  3. Unreliable under load: A high volume of PR labels (50+) or concurrent workflow runs increased 5xx errors and incomplete updates due to the nature of POST/DELETE operations.

These problems were significant enough that PR #497 replaced POST/DELETE with a single PUT-based update.

Why PUT is more reliable

  1. Safe to retry (idempotent)
  2. Updates all labels in one atomic call
  3. Enforces GitHub’s 100-label limit before sending the request.
  4. Replaces dozens of DELETE calls with a single operation

This aligns better with the concurrency patterns common in GitHub Actions.

How PR #917 improves this further

PR 917 narrows the read–write race window, preserves manually added labels more consistently, and improves workflow stability when updates happen mid-run.

We truly appreciate your feedback and are open to further discussion on improving label synchronization within the constraints of GitHub’s API.

@jnewland
Copy link
Copy Markdown

Thanks for the update. I had forgotten that the label delete API only allows one label to be removed at a time; that's disappointing.

@HarithaVattikuti HarithaVattikuti merged commit 77a4082 into actions:main Jan 22, 2026
7 checks passed
@melissawm
Copy link
Copy Markdown

Hi all - it looks like this has been merged but not yet released. Would it be possible to have a new release some time soon for this change to be available? Thank you for your work on this action! ❤️

leofang added a commit to NVIDIA/cuda-python that referenced this pull request Apr 24, 2026
The previous pin (v6.0.1, 634933e) has a bug where labels added
by other workflows during the same run can be removed even with
sync-labels: false.  This caused Needs-Restricted-Paths-Review
to be stripped immediately after being applied (see #1967).

Pin to e52e4fb which includes the fix from actions/labeler#917
("Preserve manually added labels during workflow run and refine
label sync logic").
rwgk pushed a commit to NVIDIA/cuda-python that referenced this pull request Apr 24, 2026
The previous pin (v6.0.1, 634933e) has a bug where labels added
by other workflows during the same run can be removed even with
sync-labels: false.  This caused Needs-Restricted-Paths-Review
to be stripped immediately after being applied (see #1967).

Pin to e52e4fb which includes the fix from actions/labeler#917
("Preserve manually added labels during workflow run and refine
label sync logic").
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request May 6, 2026
…v6.0.1 → v6.1.0) (#384)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [https://github.com/actions/labeler](https://github.com/actions/labeler) | action | minor | `v6.0.1` → `v6.1.0` |

---

### Release Notes

<details>
<summary>actions/labeler (https://github.com/actions/labeler)</summary>

### [`v6.1.0`](https://github.com/actions/labeler/releases/tag/v6.1.0)

[Compare Source](actions/labeler@v6.0.1...v6.1.0)

#### Enhancements

- Add changed-files-labels-limit and max-files-changed configuration options to cap the number of labels added by [@&#8203;bluca](https://github.com/bluca) in [#&#8203;923](actions/labeler#923)

#### Bug Fixes

- Improve Labeler Action documentation and permission error handling by [@&#8203;chiranjib-swain](https://github.com/chiranjib-swain) in [#&#8203;897](actions/labeler#897)
- Preserve manually added labels during workflow runs and refine label synchronization logic by [@&#8203;chiranjib-swain](https://github.com/chiranjib-swain) in [#&#8203;917](actions/labeler#917)

#### Dependency Updates

- Upgrade brace-expansion from 1.1.11 to 1.1.12 and document breaking changes in v6 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;877](actions/labeler#877)
- Upgrade minimatch from 10.0.1 to 10.2.3 by [@&#8203;dependabot](https://github.com/dependabot) in [#&#8203;926](actions/labeler#926)
- Upgrade dependencies ([@&#8203;actions/core](https://github.com/actions/core), [@&#8203;actions/github](https://github.com/actions/github), js-yaml, minimatch, [@&#8203;typescript-eslint](https://github.com/typescript-eslint)) by [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;934](actions/labeler#934)

#### New Contributors

- [@&#8203;chiranjib-swain](https://github.com/chiranjib-swain) made their first contribution in [#&#8203;897](actions/labeler#897)
- [@&#8203;bluca](https://github.com/bluca) made their first contribution in [#&#8203;923](actions/labeler#923)
- [@&#8203;Copilot](https://github.com/Copilot) made their first contribution in [#&#8203;934](actions/labeler#934)

**Full Changelog**: <actions/labeler@v6...v6.1.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9naXRodWItYWN0aW9uIiwidHlwZS9taW5vciJdfQ==-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/384
@chiranjib-swain
Copy link
Copy Markdown
Contributor Author

Hi @melissawm! 👋
Thank you so much for your kind words and your patience!
Great news — we're happy to let you know that v6.1.0 has been released and includes this change.
Please feel free to give it a try and let us know if you run into any issues. We appreciate your support and enthusiasm for this action!

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.

7 participants