Skip to content

idle-power-manager: fix fragile switch_profile success detection#11

Merged
mlutonsky merged 2 commits intomainfrom
copilot/fix-fragile-switch-profile-detection
Mar 14, 2026
Merged

idle-power-manager: fix fragile switch_profile success detection#11
mlutonsky merged 2 commits intomainfrom
copilot/fix-fragile-switch-profile-detection

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 14, 2026

switch_profile() detected success by grepping stdout for "true", which could false-positive on any output containing that string (e.g., error messages referencing a profile named true-performance). Replace with a direct exit-code check.

Changes

  • switch_profile(): Drop stdout capture and grep -q "true"; use gdbus call ... > /dev/null 2>&1 and branch on exit code directly.
# Before
result=$(gdbus call ... "$profile" 2>&1)
if echo "$result" | grep -q "true"; then ...

# After
if gdbus call ... "$profile" > /dev/null 2>&1; then ...
Original prompt

idle-power-manager: fix fragile switch_profile success detection

File to modify: idle-power-manager.sh

Problem

The switch_profile() function checks success by grepping stdout for the string "true":

if echo "$result" | grep -q "true"; then

This is fragile — it would match any output containing the word "true", including error messages like "profile 'true-performance' not found". Checking the exit code of gdbus call directly is more reliable.

Fix

Refactor switch_profile() to check the exit code of gdbus call directly instead of grepping its output. Replace the entire function body with:

switch_profile() {
    local profile="$1"
    if gdbus call --system \
        --dest com.redhat.tuned \
        --object-path /Tuned \
        --method com.redhat.tuned.control.switch_profile \
        "$profile" > /dev/null 2>&1; then
        return 0
    else
        log "ERROR" "Failed to switch to profile '$profile'"
        return 1
    fi
}

No other changes to the file.

The following is the prior conversation context from the user's chat exploration (may be truncated):

Assistant: ````list type="task"
data:
- title: 'Add ShellCheck CI workflow'
repository: mlutonsky/utils
url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoP2B
state: queued


Assistant: All 10 pull requests have been submitted to the coding agent! Here's the full tracking list:

````list type="task"
data:
    - title: 'Add MIT license'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoO34
      state: queued
    - title: 'Add ShellCheck CI workflow'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoP2B
      state: queued
    - title: 'git-branch-clean: safer branch deletion and fetch error handling'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: fix expensive per-branch python3 Levenshtein loop'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: remove unintentional git pull --all after switch -c'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: validate branch selection input is numeric'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'idle-power-manager: add log rotation'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'idle-power-manager: fix fragile switch_profile success detection'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'idle-power-manager: add DBUS_SESSION_BUS_ADDRESS fallback for systemd'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'Add install.sh to symlink all scripts to ~/.local/bin'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued

The agent is working on all 10. PRs will appear at github.com/mlutonsky/utils/pulls as they're completed — review and merge whichever you find useful!

User: @copilot Accepted Confirmation: Are you sure?

User: @copilot Accepted Confirmation: Are you sure?

Assistant: The Copilot coding agent is now working on all the pull requests! Here's the full tracking list:

data:
    - title: 'Add MIT license'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoO34
      state: queued
    - title: 'Add ShellCheck CI workflow'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoP2B
      state: queued
    - title: 'idle-power-manager: add log rotation'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoQyr
      state: queued
    - title: 'Add install.sh to symlink all scripts to ~/.local/bin'
      repository: mlutonsky/utils
      url: https://github.com/copilot/tasks/pull/PR_kwDORnE_6M7KoUUn
      state: queued
    - title: 'git-branch-clean: safer branch deletion and fetch error handling'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: fix expensive per-branch python3 Levenshtein loop'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: remove unintentional git pull --all after git switch -c'
      repository: mlutonsky/utils
      url: https://github.com/mlutonsky/utils/pulls
      state: queued
    - title: 'git-co: validate branch selection input is numeric'
      repository: mlutonsky/uti...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs), [Azure Boards](https://gh.io/cca-azure-boards-docs) or [Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: mlutonsky <423848+mlutonsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix fragile switch_profile success detection idle-power-manager: fix fragile switch_profile success detection Mar 14, 2026
Copilot AI requested a review from mlutonsky March 14, 2026 18:37
@mlutonsky mlutonsky marked this pull request as ready for review March 14, 2026 18:42
Copilot AI review requested due to automatic review settings March 14, 2026 18:42
@mlutonsky mlutonsky merged commit b9362b4 into main Mar 14, 2026
3 checks passed
@mlutonsky mlutonsky deleted the copilot/fix-fragile-switch-profile-detection branch March 14, 2026 18:44
Copy link
Copy Markdown

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

Improves idle-power-manager.sh’s tuned profile switching reliability by avoiding fragile stdout parsing and using gdbus command success/failure directly.

Changes:

  • Refactor switch_profile() to branch on gdbus call exit status instead of grepping for "true".
  • Stop capturing and parsing gdbus output; suppress output with redirection.

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

Comment on lines +93 to +96
"$profile" > /dev/null 2>&1; then
return 0
else
log "ERROR" "Failed to switch to profile '$profile': $result"
log "ERROR" "Failed to switch to profile '$profile'"
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.

3 participants