Skip to content

[rendering-scripts] fix: normalize pi engine bash tool name for correct log rendering - #49304

Merged
pelikhan merged 3 commits into
mainfrom
fix/pi-log-bash-tool-name-normalization-3a2950d0b6a77327
Jul 31, 2026
Merged

[rendering-scripts] fix: normalize pi engine bash tool name for correct log rendering#49304
pelikhan merged 3 commits into
mainfrom
fix/pi-log-bash-tool-name-normalization-3a2950d0b6a77327

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Summary

Normalizes the Pi engine's raw bash tool name to the canonical "Bash" string so the shared log formatter renders bash tool calls correctly, instead of falling through to generic rendering.

Problem

The Pi engine emits tool_use entries where the bash tool's name arrives as lowercase "bash" (from raw.tool_name / part.name). The shared formatter log_parser_format.cjs special-cases the exact string "Bash" (capitalized) to apply bash-specific log rendering. A lowercase "bash" name fails this match, causing incorrect/generic rendering of bash tool calls in Pi engine logs.

Changes

actions/setup/js/parse_pi_log.cjs

  • Added normalizePiToolName(name) helper: returns "Bash" when the trimmed, lowercased input equals "bash", otherwise returns the name unchanged.
  • Applied the helper at both tool_use construction sites: transformPiEntries (schema v1/v2) and transformPiV3Entries (schema v3).
  • Exported normalizePiToolName for unit testing.

actions/setup/js/parse_pi_log.test.cjs

  • Added a dedicated test suite for normalizePiToolName, covering case-insensitivity (e.g. "bash", "Bash", "BASH", with surrounding whitespace) and passthrough for non-bash tool names.
  • Updated existing test expectations to reflect the new canonical "Bash" naming in transformed entries.

Impact

  • High impact on log rendering correctness for the Pi engine: bash tool calls now render via the correct formatter path.
  • No breaking changes — the helper only remaps the bash-specific case; all other tool names pass through unchanged.

Testing

  • New/updated unit tests in parse_pi_log.test.cjs verify normalizePiToolName behavior and updated transform output expectations.

Generated by PR Description Updater for #49304 · auto · 33.1 AIC · ⊞ 6.8K ·

Pi's CLI emits bash tool calls with the lowercase name "bash", but the
shared markdown formatter (log_parser_format.cjs) only special-cases
the exact string "Bash" for compact command bullets and single-line
collapsible summaries. This caused pi-engine step summaries to show
bare "bash" bullets with no command text, and corrupted the detailed
<summary> tags with raw multi-line command dumps.

Add normalizePiToolName() in parse_pi_log.cjs, applied at both the
legacy flat-schema and v3-streaming-schema tool-call sites, following
the same "bash" -> "Bash" normalization already used by
parse_codex_log.cjs and parse_copilot_log.cjs.

Verified against real production log data (run 30616598129, Issue
Monster workflow, pi engine): rendered markdown length increased from
3469 to 5049 chars, <details>/<summary>/fence counts remain balanced,
and bash commands now render as single-line backtick-wrapped snippets
consistent with other engines.
@github-actions github-actions Bot added automated-fix javascript Pull requests that update javascript code rendering labels Jul 31, 2026
@pelikhan
pelikhan marked this pull request as ready for review July 31, 2026 09:19
Copilot AI review requested due to automatic review settings July 31, 2026 09:19
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

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

Fixes Pi engine bash tool-call rendering by aligning tool names with shared formatter expectations.

Changes:

  • Normalizes bash to canonical Bash in legacy and v3 Pi schemas.
  • Updates assertions for normalized names and rendered commands.
Show a summary per file
File Description
actions/setup/js/parse_pi_log.cjs Normalizes Pi bash tool names before formatting.
actions/setup/js/parse_pi_log.test.cjs Verifies normalized and rendered bash calls.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories.

@github-actions

Copy link
Copy Markdown
Contributor Author

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test Quality Sentinel Report

🔶 Test Quality Score: 50/100 — Needs Improvement

Analyzed 2 test(s): 1 design, 1 implementation, 0 violation(s).

📊 Metrics (2 tests)
Metric Value
Analyzed 2 (JavaScript)
✅ Design 1 (50%)
⚠️ Implementation 1 (50%)
Edge/error coverage 0 (0%)
Duplicate clusters 0
Inflation No (0.15:1)
🚨 Violations 0
Test File Classification Issues
should transform tool_use entry correctly actions/setup/js/parse_pi_log.test.cjs:162 Design test Assertion updated to verify normalization behavior
renders assistant text, tool calls, and tool results from a v3 stream actions/setup/js/parse_pi_log.test.cjs:256 Implementation test Assertion refined to check tool command output

Verdict

Failed. 50% implementation tests (threshold: 30%). While both tests verify correct behavior with appropriate assertions, the high ratio of implementation-focused tests relative to design tests indicates insufficient contract-level coverage. Consider adding a dedicated unit test for the new normalizePiToolName() function to improve design-level coverage.

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 16.2 AIC · ⊞ 8.4K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

❌ Test Quality Sentinel: 50/100. 50% implementation tests (threshold: 30%). Review flagged tests in the comment above.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — the fix is clean and well-reasoned; one minor observation on test coverage.

📋 Key Themes & Highlights

Key Themes

  • Normalisation follows existing convention: normalizePiToolName() mirrors the pattern already used in parse_codex_log.cjs and parse_copilot_log.cjs — consistent, low-risk.
  • Both schema branches covered: both the legacy flat-schema tool_use path (line 162) and the v3-streaming transformPiV3Entries path (line 292) are fixed — root cause fully addressed.
  • Test assertions updated correctly: the two updated assertions now encode the expected normalised value ("Bash", ls) rather than the old buggy output.
  • Minor gap: normalizePiToolName is exported but has no dedicated unit test. An isolated test would catch future variants (e.g., "BASH", "bash_20250124") before they reach rendering.

Positive Highlights

  • ✅ Root cause identified and fixed, not just the symptom.
  • ✅ Production verification with real log data (5 MB, run 30616598129) with before/after evidence.
  • ✅ Structural HTML balance validated (details/summary counts unchanged).

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 23.9 AIC · ⊞ 7K
Comment /matt to run again

expect(entries[0].message.content[0].type).toBe("tool_use");
expect(entries[0].message.content[0].name).toBe("bash");
expect(entries[0].message.content[0].name).toBe("Bash");
expect(entries[0].message.content[0].id).toBe("t1");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] No direct unit test for normalizePiToolName — the function is exported but only covered implicitly through integration-level assertions.

Adding a dedicated test would guard against future regressions (e.g., if Pi starts emitting "BASH" or another variant) and documents the full contract.

💡 Suggested test
describe('normalizePiToolName', () => {
  it('maps lowercase bash to Bash', () => {
    expect(normalizePiToolName('bash')).toBe('Bash');
  });
  it('passes through already-normalized names unchanged', () => {
    expect(normalizePiToolName('Bash')).toBe('Bash');
    expect(normalizePiToolName('str_replace_editor')).toBe('str_replace_editor');
  });
});

@copilot please address this.

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.

Added in 9f65de6. A dedicated describe('normalizePiToolName', ...) block covers lowercase bash, uppercase/mixed-case variants, and non-bash tool names (idempotency + no mutation).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

The fix is correct and well-scoped. normalizePiToolName is applied consistently in both transform paths, and the tests are properly updated.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 12.7 AIC · ⊞ 5.3K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: minor hardening suggestion, no blockers

Small, well-scoped fix that correctly follows the existing parse_codex_log.cjs/parse_copilot_log.cjs normalization convention and comes with updated tests.

Themes
  • The added normalizePiToolName correctly fixes the observed lowercase "bash" rendering bug and is exercised by updated unit tests against a real production log.
  • One non-blocking hardening note posted: the match is case-sensitive and only covers exact "bash", so any future casing variance ("BASH", " bash") would silently reintroduce the same bug with no diagnostic signal. Suggested a trim().toLowerCase() comparison plus idempotency test coverage.
  • Scope is minimal and change is low-risk; no correctness, security, or concurrency issues found in the diff.

🔎 Code quality review by PR Code Quality Reviewer · auto · 28 AIC · ⊞ 7.8K
Comment /review to run again

* formatters (e.g. log_parser_format.cjs special-cases "Bash", not "bash").
* @param {string} name - Raw tool name as emitted by Pi
* @returns {string} Normalized tool name
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Case-sensitive match only handles exact lowercase "bash"; if Pi ever emits a different casing the bug silently resurfaces with no diagnostic.

💡 Details

normalizePiToolName does name === "bash" ? "Bash" : name. This is fine for the currently observed payload, but it's a brittle point-fix rather than a true normalization: if Pi's API ever emits "BASH", " bash", or changes casing in a future release, this silently falls through unnormalized and reintroduces the exact rendering bug this PR is fixing — with no test or logging to catch the regression.

Suggested hardening:

function normalizePiToolName(name) {
  return typeof name === "string" && name.trim().toLowerCase() === "bash" ? "Bash" : name;
}

Also add a test case for an already-correct "Bash" input and an unrelated tool name (e.g. "read") to confirm idempotency and that non-bash names are never mutated.

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.

Addressed in 9f65de6. normalizePiToolName now uses typeof name === "string" && name.trim().toLowerCase() === "bash" to handle all casing variants robustly.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill on this PR, address the open review feedback from the automated reviewers (notably the test-quality suggestion to add a dedicated unit test for normalizePiToolName() and the code-quality hardening note about tolerant bash-name normalization), then rerun the relevant checks once ready. Run details: https://github.com/github/gh-aw/actions/runs/30620427124

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 7.69 AIC · ⊞ 5.7K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor Author

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Hey 👋 — thanks for the automated fix! This is a well-targeted rendering defect fix in the pi engine log parser.

A quick note on process: This repository's CONTRIBUTING.md states that non-core team members should not open traditional pull requests directly, and should instead discuss via issues. Since this PR originates from an internal automated agentic workflow bot rather than an external contributor, this appears to be an accepted exception — but flagging for maintainer awareness.

What looks great:

  • ✅ Focused fix: normalizes bash tool name rendering following the exact same pattern as parse_codex_log.cjs and parse_copilot_log.cjs
  • ✅ Comprehensive testing: verified against real production logs (5MB agent-stdio.log from run 30616598129) with structural validation
  • ✅ Test updates: correctly updated stale assertions to match the corrected behavior
  • ✅ Complete description: clear root cause, changes, and verification results

This PR looks ready for review and merge!

Generated by ✅ Contribution Check · auto · 52.5 AIC · ⊞ 8.7K ·

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Both items were already addressed in 9f65de6:\n- normalizePiToolName hardened to use trim().toLowerCase() for robust casing-variant handling\n- Dedicated unit tests added covering lowercase, uppercase, mixed-case bash variants, and non-bash tool names\n\nLocal validation (make agent-report-progress) passed with 27/27 tests green. CI re-trigger needed from a maintainer to confirm on the runner.

Copilot AI requested a review from gh-aw-bot July 31, 2026 09:53
@pelikhan
pelikhan merged commit 7e291b5 into main Jul 31, 2026
9 checks passed
@pelikhan
pelikhan deleted the fix/pi-log-bash-tool-name-normalization-3a2950d0b6a77327 branch July 31, 2026 10:23
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.84.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix javascript Pull requests that update javascript code needs-review rendering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants