Skip to content

fix: replace piped while loops with temp files to avoid pipefail SIGPIPE#24350

Merged
lpcox merged 6 commits intomainfrom
fix/token-analyzer-pipefail
Apr 3, 2026
Merged

fix: replace piped while loops with temp files to avoid pipefail SIGPIPE#24350
lpcox merged 6 commits intomainfrom
fix/token-analyzer-pipefail

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 3, 2026

Problem

The token usage analyzer workflows use set -euo pipefail in their bash steps. The pattern jq | head -50 | while read causes jq to receive SIGPIPE (exit 141) when head closes the pipe early. With pipefail, this propagates as a pipeline failure, silently aborting the artifact download loop.

Discovered while debugging run 23953754099 which failed with exit code 5 after PR #24335 fixed the ./gh-aw binary issue.

Fix

Replace piped jq | head | while read and find | while read loops with a temp file approach:

  1. Write results to a temp file: jq ... > /tmp/.../run-ids.txt
  2. Read from the temp file: while read ... done < /tmp/.../run-ids.txt

This avoids SIGPIPE entirely since jq writes to a file, not a pipe.

Affected workflows

  • copilot-token-usage-analyzer.md (2 pipelines fixed)
  • claude-token-usage-analyzer.md (2 pipelines fixed)

The token usage analyzer workflows use set -euo pipefail which causes
jq | head | while read pipelines to fail with exit 141 (SIGPIPE) when
head closes the pipe early, silently aborting artifact downloads.

Write to temp files first, then read from them in while loops.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 3, 2026 17:57
Copy link
Copy Markdown
Contributor

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

Updates the Copilot/Claude token usage analyzer workflows to avoid set -euo pipefail failures caused by piped while read loops during artifact download/merge.

Changes:

  • Reworked artifact download loops to read run IDs from a temp file rather than ... | while read.
  • Reworked JSONL merge loops to read file paths from a temp file rather than find ... | while read.
  • Regenerated the corresponding compiled/locked workflow YAMLs to reflect the template changes.

Reviewed changes

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

File Description
.github/workflows/copilot-token-usage-analyzer.md Uses temp files for run-id and JSONL file iteration in bash steps.
.github/workflows/copilot-token-usage-analyzer.lock.yml Regenerated lockfile reflecting the updated bash step logic.
.github/workflows/claude-token-usage-analyzer.md Uses temp files for run-id and JSONL file iteration in bash steps.
.github/workflows/claude-token-usage-analyzer.lock.yml Regenerated lockfile reflecting the updated bash step logic.

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

lpcox and others added 5 commits April 3, 2026 11:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit 18c5399 into main Apr 3, 2026
56 checks passed
@lpcox lpcox deleted the fix/token-analyzer-pipefail branch April 3, 2026 18:21
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.

2 participants