Skip to content

fix: issue-sync-helper.sh dirname failure in stripped PATH environments#2606

Closed
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/dirname-posix-compat
Closed

fix: issue-sync-helper.sh dirname failure in stripped PATH environments#2606
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/dirname-posix-compat

Conversation

@alex-solovyev
Copy link
Copy Markdown
Collaborator

@alex-solovyev alex-solovyev commented Feb 28, 2026

Summary

  • Replace dirname with POSIX-compatible ${BASH_SOURCE[0]%/*} parameter expansion in issue-sync-helper.sh and issue-sync-lib.sh
  • Fixes dirname: command not found error in stripped PATH environments (Claude Code MCP pulse sessions)
  • All 6 pulse-enabled repos were affected — TODO sync was silently failing

Root Cause

dirname is an external command that requires PATH to include /usr/bin. Claude Code MCP pulse sessions run with a stripped PATH that doesn't include it. The ${var%/*} parameter expansion is a bash builtin that produces identical results without requiring any external command.

Verification

  • ShellCheck passes cleanly on both files
  • ${BASH_SOURCE[0]%/*} produces identical output to dirname "${BASH_SOURCE[0]}" for both absolute and relative paths

Closes #2605

Summary by CodeRabbit

  • Chores
    • Refactored internal build scripts to improve directory path handling and enhance robustness across different shell execution environments. All existing functionality and behavior remain unchanged.

Replace `dirname` with ${BASH_SOURCE[0]%/*} in issue-sync-helper.sh and
issue-sync-lib.sh so they work in stripped PATH environments (e.g., Claude
Code MCP pulse sessions) where `dirname` is not available.

Closes #2605
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where issue synchronization scripts failed in environments with stripped PATH variables due to the unavailability of the dirname command. By replacing dirname with a Bash-builtin parameter expansion, the scripts are now more robust and compatible, ensuring reliable operation and preventing silent failures in various execution contexts.

Highlights

  • dirname Replacement: Replaced the external dirname command with the POSIX-compatible Bash parameter expansion ${BASH_SOURCE[0]%/*} in issue-sync-helper.sh and issue-sync-lib.sh.
  • Environment Compatibility: Resolved dirname: command not found errors that occurred in stripped PATH environments, specifically in Claude Code MCP pulse sessions.
  • Impact and Resolution: Fixed silently failing TODO sync across all six pulse-enabled repositories by ensuring script directory resolution is robust against environment variations.
Changelog
  • .agents/scripts/issue-sync-helper.sh
    • Updated the SCRIPT_DIR assignment to use Bash parameter expansion for directory resolution.
  • .agents/scripts/issue-sync-lib.sh
    • Modified the SCRIPT_DIR assignment to leverage Bash parameter expansion, enhancing script portability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dd5b1e and 4ccb409.

📒 Files selected for processing (2)
  • .agents/scripts/issue-sync-helper.sh
  • .agents/scripts/issue-sync-lib.sh

Walkthrough

Two shell scripts replace the dirname command with BASH parameter expansion (${BASH_SOURCE[0]%/*}) to resolve the script's directory path. This eliminates dependency on external commands in stripped PATH environments where dirname is unavailable.

Changes

Cohort / File(s) Summary
Shell Script Directory Resolution
.agents/scripts/issue-sync-helper.sh, .agents/scripts/issue-sync-lib.sh
Replaced dirname "${BASH_SOURCE[0]}" with parameter expansion ${BASH_SOURCE[0]%/*} to resolve script directory without relying on PATH-dependent external commands. Functional behavior unchanged; improves robustness in stripped PATH environments.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Poem

🔧 No more dirname in the PATH
Parameter expansion lights the way
Stripped environments now rejoice
Shell scripts speak with confident voice
Pure POSIX, no commands astray ✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/dirname-posix-compat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@marcusquinn
Copy link
Copy Markdown
Owner

Pulse supervisor: PR has a merge conflict (likely TODO.md divergence from main). Dispatching a worker to rebase and resolve. CI is still pending — will merge once CI passes and conflict is resolved.

@alex-solovyev
Copy link
Copy Markdown
Collaborator Author

Closing as duplicate of #2608, which fixes the same issue but also covers session-miner-pulse.sh (3 files vs 2). Superseded by #2608.

@alex-solovyev
Copy link
Copy Markdown
Collaborator Author

Duplicate of #2608 — closing in favour of the more complete fix.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve script robustness by replacing the external dirname command with a bash parameter expansion. This is a good goal for portability. However, the current implementation introduces a regression in an edge case where the script is invoked without a path prefix, which can cause the script to fail. I've added comments with suggestions for a more robust implementation that handles this edge case correctly while still avoiding the dirname dependency.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if the script is in the current directory and invoked as bash issue-sync-helper.sh, ${BASH_SOURCE[0]} will be issue-sync-helper.sh.

  • dirname "issue-sync-helper.sh" correctly returns .
  • echo "${BASH_SOURCE[0]%/*}" returns issue-sync-helper.sh, which causes cd to fail.

This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)" || exit

# Resolves SCRIPT_DIR from BASH_SOURCE so it works when sourced from any location.
if [[ -z "${SCRIPT_DIR:-}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While ${BASH_SOURCE[0]%/*} is a good replacement for dirname to avoid an external command dependency, it behaves differently when ${BASH_SOURCE[0]} does not contain a /. For example, if this library is sourced from a script in the current directory that is invoked as bash script.sh, ${BASH_SOURCE[0]} will be issue-sync-lib.sh.

  • dirname "issue-sync-lib.sh" correctly returns .
  • echo "${BASH_SOURCE[0]%/*}" returns issue-sync-lib.sh, which causes cd to fail.

This introduces a regression that can break the script in some invocation scenarios. A more robust approach would be to handle this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)"

@marcusquinn
Copy link
Copy Markdown
Owner

Confirmed duplicate of #2603. After rebasing onto main, this branch's commit was empty (zero diff) — the fix from #2603 (commit 3dd5b1e) with defensive PATH export and edge-case handling already covers this.

@marcusquinn marcusquinn deleted the bugfix/dirname-posix-compat branch February 28, 2026 08:15
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.

fix: issue-sync-helper.sh fails with 'dirname: command not found' in stripped PATH environments

2 participants