fix: prevent premature token revocation in reusable workflows #1081

Merged
mfenniak merged 4 commits from :fix/reusable-workflow-finalization-and-token-revocation into main 2025-10-14 01:45:54 +00:00

Problem

When using reusable workflows, the Forgejo runner prematurely revokes GITHUB_TOKEN after the first step completes, causing subsequent steps to fail with authentication errors.

Reproduction

When the reusable workflow contains multiple steps that require authentication:

  1. First step (e.g., checkout) completes successfully
  2. Reporter receives completion banner from child workflow
  3. Token is revoked prematurely
  4. Second step fails with authentication error
  • bug fixes
    • PR: fix: prevent premature token revocation in reusable workflows
## Problem When using reusable workflows, the Forgejo runner prematurely revokes `GITHUB_TOKEN` after the first step completes, causing subsequent steps to fail with authentication errors. ### Reproduction When the reusable workflow contains multiple steps that require authentication: 1. First step (e.g., checkout) completes successfully 2. Reporter receives completion banner from child workflow 3. Token is revoked prematurely 4. Second step fails with authentication error <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1081): <!--number 1081 --><!--line 0 --><!--description Zml4OiBwcmV2ZW50IHByZW1hdHVyZSB0b2tlbiByZXZvY2F0aW9uIGluIHJldXNhYmxlIHdvcmtmbG93cw==-->fix: prevent premature token revocation in reusable workflows<!--description--> <!--end release-notes-assistant-->
fix: prevent premature token revocation in reusable workflows
All checks were successful
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Successful in 53s
checks / validate mocks (pull_request) Successful in 1m12s
checks / build and test (pull_request) Successful in 1m26s
checks / runner exec tests (pull_request) Successful in 37s
checks / runner integration tests (pull_request) Successful in 8m20s
checks / integration tests (pull_request) Successful in 17m42s
d013126979
test: add test for skipping banner in child reusable workflows
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Successful in 52s
checks / validate mocks (pull_request) Successful in 1m12s
checks / build and test (pull_request) Successful in 3m42s
checks / runner exec tests (pull_request) Successful in 41s
checks / runner integration tests (pull_request) Successful in 6m54s
checks / integration tests (pull_request) Failing after 13m54s
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 10s
2f0a1725d0
Contributor
https://code.forgejo.org/forgejo/runner/actions/runs/11197/jobs/2/attempt/1#jobstep-5-1035 the CI failure is related.
test: fix job executor test flakiness in CI environment
Some checks failed
checks / validate pre-commit-hooks file (pull_request) Successful in 1m14s
checks / validate mocks (pull_request) Successful in 1m47s
cascade / forgejo (pull_request_target) Has been skipped
checks / build and test (pull_request) Successful in 1m53s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / runner exec tests (pull_request) Successful in 54s
Integration tests for the release process / release-simulation (pull_request) Successful in 7m4s
checks / runner integration tests (pull_request) Successful in 8m29s
checks / integration tests (pull_request) Failing after 16m44s
4da9ddfeca
@earl-warren wrote in https://code.forgejo.org/forgejo/runner/pulls/1081#issuecomment-63115: > https://code.forgejo.org/forgejo/runner/actions/runs/11197/jobs/2/attempt/1#jobstep-5-1035 the CI failure is related. Fixed, should work now
Owner

@syncstack The change here looks to make sense to me, but it is still failing another integration test TestRunner_RunEvent/uses-composite-check-for-input-in-if-uses.

@syncstack The change here looks to make sense to me, but it is still failing another integration test `TestRunner_RunEvent/uses-composite-check-for-input-in-if-uses`.
ci: trigger workflow
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 31s
checks / validate mocks (pull_request) Successful in 41s
checks / build and test (pull_request) Successful in 49s
checks / runner exec tests (pull_request) Successful in 24s
Integration tests for the release process / release-simulation (pull_request) Successful in 4m5s
checks / runner integration tests (pull_request) Successful in 4m56s
checks / integration tests (pull_request) Successful in 10m48s
issue-labels / release-notes (pull_request_target) Successful in 6s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 10s
cascade / forgejo (pull_request_target) Successful in 2m53s
1099b63edf

@mfenniak I deployed the exact uses-composite-check-for-input-in-if-uses workflow to my repository running the patched runner, and all steps pass successfully.

I've retriggered the CI workflow to see if it's a transient failure.

@mfenniak I deployed the exact `uses-composite-check-for-input-in-if-uses` workflow to my repository running the patched runner, and all steps pass successfully. I've retriggered the CI workflow to see if it's a transient failure.
Contributor

This is very well done, impressive.

This is very well done, impressive.

Thank you! It was a tricky one to debug, glad the solution works well.

Thank you! It was a tricky one to debug, glad the solution works well.
Contributor

Could you please create an associated bug report that includes a reproducer to run this against? It could be used to add a end-to-end test at https://code.forgejo.org/forgejo/end-to-end/src/branch/main/actions

This is a tricky part of the runner codebase: currently implemented more as a hack than a feature, which makes it hard to work with. Writing tests in such a context is very difficult kudos.

Could you please create an associated bug report that includes a reproducer to run this against? It could be used to add a end-to-end test at https://code.forgejo.org/forgejo/end-to-end/src/branch/main/actions This is a tricky part of the runner codebase: currently implemented more as a hack than a feature, which makes it hard to work with. Writing tests in such a context is very difficult kudos.
Contributor

cascading-pr updated at actions/setup-forgejo#721

cascading-pr updated at https://code.forgejo.org/actions/setup-forgejo/pulls/721
Contributor
If [this a reproducer matching this bug fix](https://codeberg.org/forgejo/forgejo/issues/6657#issuecomment-7688446), there is no need to create another issue. https://v13.next.forgejo.org/2franix/Test/src/commit/01d365eb9f62f6a51720a19f6dddd75da5dcb1cb/.forgejo/workflows/reusable_first_failing.yaml

@earl-warren Yes, this is the same bug. Initially I thought it was only a token issue, but this PR actually fixes a chain of related problems:

The core issue:

  • Workflows completed with "success" status while still writing logs in background
  • Any step during that background phase could fail silently
  • You'd only discover errors by manually checking logs

Manifestation:

  • Fast-running jobs appeared to work fine
  • Adding needs guaranteed token authorization errors
  • actions/checkout could be worked around with explicit token
  • Artifacts were completely broken (no workaround)

It worked sometimes depending on job execution speed, making it look intermittent when it was actually systematic.

This PR should close all these behaviors.

@earl-warren Yes, this is the same bug. Initially I thought it was only a token issue, but this PR actually fixes a chain of related problems: The core issue: - Workflows completed with "success" status while still writing logs in background - Any step during that background phase could fail silently - You'd only discover errors by manually checking logs Manifestation: - Fast-running jobs appeared to work fine - Adding needs guaranteed token authorization errors - actions/checkout could be worked around with explicit token - Artifacts were completely broken (no workaround) It worked sometimes depending on job execution speed, making it look intermittent when it was actually systematic. This PR should close all these behaviors.

P.S. I'm actively testing this while migrating from GitLab pipelines to Forgejo with full decomposition. Currently running complex real-world scenarios:

  • Reusable workflows with workflow_call + needs chains
  • Composite actions that handle artifacts across jobs
  • Release pipelines: unit-tests → build → publish release → deploy
  • Multi-step artifact passing (upload-artifact → download-artifact between jobs)
  • Container matrix builds with S3 deployments

Example structure:

# Caller workflow
jobs:
  release:
    uses: org/ci-templates/.forgejo/workflows/release-frontend.yml@v1
    
# Reusable template with artifact chains
jobs:
  build: ...
  test:
    needs: [build]
  release:
    needs: [test]
    steps:
      - uses: org/ci-templates/actions/release/publish@v1  # composite action
  deploy:
    needs: [release]
    steps:
      - uses: actions/download-artifact@v4  # artifact from previous job
      - uses: org/ci-templates/actions/s3/deploy@v1
**P.S.** I'm actively testing this while migrating from GitLab pipelines to Forgejo with full decomposition. Currently running complex real-world scenarios: - Reusable workflows with `workflow_call` + `needs` chains - Composite actions that handle artifacts across jobs - Release pipelines: unit-tests → build → publish release → deploy - Multi-step artifact passing (`upload-artifact` → `download-artifact` between jobs) - Container matrix builds with S3 deployments Example structure: ```yaml # Caller workflow jobs: release: uses: org/ci-templates/.forgejo/workflows/release-frontend.yml@v1 # Reusable template with artifact chains jobs: build: ... test: needs: [build] release: needs: [test] steps: - uses: org/ci-templates/actions/release/publish@v1 # composite action deploy: needs: [release] steps: - uses: actions/download-artifact@v4 # artifact from previous job - uses: org/ci-templates/actions/s3/deploy@v1 ```
mfenniak approved these changes 2025-10-14 01:45:16 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1081
No description provided.