Fix job display name extraction: handle escaped quotes and identify correct Worker log on non-ephemeral runners#2089
Merged
rodrigo-roca merged 5 commits intoDataDog:masterfrom Feb 13, 2026
Conversation
…runners This PR addresses two critical issues in GitHub Actions job display name extraction from Runner diagnostic logs: 1. Escaped Quotes: The regex now properly handles JSON-escaped strings containing quotes, backslashes, and other special characters using an improved pattern and proper JSON.parse() unescaping. 2. Non-Ephemeral Runners: Uses ACTIONS_ORCHESTRATION_ID environment variable to identify the correct Worker log file when multiple logs accumulate from different job executions, preventing extraction of job names from old logs. The implementation includes comprehensive test coverage with 4 new test cases for Worker log identification scenarios and fixes for test helpers to properly escape job names in mock data. All 1012 tests now pass. Changes are backward compatible with older Runner versions through graceful fallback behavior when ACTIONS_ORCHESTRATION_ID is unavailable.
bd88d33 to
a94f469
Compare
Contributor
|
Hi @LudovicTOURMAN! Can you run |
Contributor
Author
|
Oh yes, my bad. |
rodrigo-roca
approved these changes
Feb 5, 2026
Contributor
rodrigo-roca
left a comment
There was a problem hiding this comment.
LGTM, just left a few minor comments
Contributor
Author
|
Thanks for the feedback @rodrigo-roca |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problems
This PR fixes two related issues (cf Issue) with GitHub Actions job display name extraction from Runner diagnostic logs:
Problem 1: Escaped Quotes and Special Characters ✅
The current regex for extracting job display names fails when job names contain escaped quotes or other special characters.
Failing Example:
End-to-End Tests (@org/backend, "features/a*", apps/backend)End-to-End Tests (@org/backend, \(truncated at first quote)Root Cause:
In Worker diagnostic logs, job names are stored as JSON strings with proper escaping. The current regex
/"jobDisplayName":\s*"([^"]+)"/uses[^"]+which stops at the first quote character, even when it's escaped as\".Problem 2: Wrong Worker Log on Non-Ephemeral Runners 🆕
On non-ephemeral (reusable) runners, multiple
Worker_*.logfiles accumulate from different job executions. The current implementation iterates through logs and returns the first jobDisplayName found, which may belong to a previous job run rather than the current one.Real-World Failing Scenario:
We encountered this issue in production where:
build-amd64-base-rails-assetsDocker build / Docker buildfrom an older log fileRoot Cause:
No filtering mechanism to identify which Worker log corresponds to the currently executing job.
Solutions
Solution 1: Proper Escape Handling ✅
Updated regex:
/"jobDisplayName":\s*"((?:[^"\\]|\\.)*)"/(?:[^"\\]|\\.)*to correctly match JSON-escaped strings\",\\,\n,\t,\uXXXX, etc.Proper unescaping: Added
unescapeJsonString()function usingJSON.parse()Solution 2: Worker Log Identification 🆕
Use the
ACTIONS_ORCHESTRATION_IDenvironment variable to identify the correct Worker log file:process.env.ACTIONS_ORCHESTRATION_ID(format:<guid>.<job-id>.__default)"planId": "<guid>"Why this works:
ACTIONS_ORCHESTRATION_IDis available in GitHub Actions environment (Runner v2.331.0+)"planId": "<guid>"Guidin Runner source code)Test Coverage
Existing Tests (Escape Sequences) ✅
Added comprehensive tests covering:
New Tests (Worker Log Identification) 🆕
Added 4 new test cases:
Bonus Fix 🎁
Fixed test helpers to properly JSON-escape job names using
JSON.stringify(), which resolved 8 pre-existing test failures.All 1012 tests now pass ✅
Issues We Faced
During development and testing, we encountered several challenges:
Test Failures Due to Invalid JSON: The test helper functions were directly interpolating job names into JSON templates without escaping, causing invalid JSON when job names contained quotes or special characters. Fixed by using
JSON.stringify()in test helpers.Multiple File Reads: Initial test expectations were incorrect - the implementation reads logs multiple times (once while searching for planId, then again to extract job name). Adjusted test assertions to match actual behavior (3 reads instead of 2).
Real Production Issue: On non-ephemeral runners with multiple Worker logs, datadog-ci was consistently extracting job names from old logs instead of the current job. This PR completely resolves this by using the unique planId from
ACTIONS_ORCHESTRATION_ID.Verification
Tested against real-world failing cases:
Compatibility
ACTIONS_ORCHESTRATION_IDenvironment variableThis PR fixes critical issues that were causing incorrect job identification in Datadog CI Visibility, especially on non-ephemeral runners commonly used in production environments.