From 5b286e005c1159aa55bc5f6765f7bfa409f4adfb Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 27 Jul 2026 18:19:34 +0200 Subject: [PATCH] Fix(ogagent): preserve PowerShell exit code when redirecting output --- CHANGELOG.md | 8 +++++++- src/opengnsys/windows/operations.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcdad0e..969c800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [8.5.6] - 2026-07-21 +## [8.5.9] - 2026-07-23 +### Fixed +- Preserve original exit code in Windows PowerShell script wrapper when redirecting streams, ensuring ogcore receives failure status (e.g., CommandNotFoundException). +- Prevent raw PowerShell CLIXML output from leaking into stderr on Windows when a command fails non-interactively. +- Send `START_SCRIPT` webhook when a script is picked up by the agent, ensuring the UI correctly displays the "In Progress" trace state. Applies to both admin (`client=false`) and user-session (`client=true`) execution paths. + +## [8.5.6] - 2026-07-21 ### Added - Notify `ogcore` via webhook when natively executed scripts finish, bringing `ogagent` in line with `ogLive` functionality (resolves stuck traces in "Enviada" state). diff --git a/src/opengnsys/windows/operations.py b/src/opengnsys/windows/operations.py index cc2aef7..ff1e79d 100644 --- a/src/opengnsys/windows/operations.py +++ b/src/opengnsys/windows/operations.py @@ -152,7 +152,7 @@ def get_etc_path(): def build_popen_args(script): ## turn the script into utf16le, then to b64 again, and feed the blob to powershell ## wrap the script to redirect stderr and output as a simple string to avoid CLIXML wrappers in non-interactive errors - script = f"& {{ {script} }} 2>&1 | Out-String" + script = f"$ProgressPreference = 'SilentlyContinue'; try {{ $errBefore = $Error.Count; $output = & {{ {script} }} 2>&1; $errAfter = $Error.Count; $exitcode = $LASTEXITCODE; $output | Out-String; if ($exitcode) {{ exit $exitcode }} elseif ($errAfter -gt $errBefore) {{ exit 1 }} }} catch {{ $_ | Out-String; exit 1 }}" u16 = script.encode ('utf-16le') ## utf16 b64 = base64.b64encode (u16).decode ('utf-8') ## b64 (which returns bytes, so we need an additional decode(utf8)) return ['powershell', '-WindowStyle', 'Hidden', '-EncodedCommand', b64]