Skip to content

fix(cli): add fallback arch detection in PowerShell installer#529

Merged
Aureliolo merged 3 commits intomainfrom
fix/ps1-arch-detection
Mar 17, 2026
Merged

fix(cli): add fallback arch detection in PowerShell installer#529
Aureliolo merged 3 commits intomainfrom
fix/ps1-arch-detection

Conversation

@Aureliolo
Copy link
Copy Markdown
Owner

Summary

  • RuntimeInformation::OSArchitecture returns $null on some Windows systems where the .NET type isn't loaded (older CLR, misconfigured environments)
  • Installer now wraps the RuntimeInformation call in try/catch and falls back to $env:PROCESSOR_ARCHITECTURE — available on every Windows version since XP, every PowerShell since 2.0
  • Both detection paths produce the same amd64 / arm64 output
  • Error message still shows the detected value when architecture is genuinely unsupported

Test plan

  • Verify installer works on PowerShell 5.1 (Windows 10/11 default)
  • Verify installer works on PowerShell 7+ (where RuntimeInformation always works)
  • Simulate fallback: run with $env:PROCESSOR_ARCHITECTURE = "AMD64" after forcing the try/catch to fail
  • Verify unsupported architecture still errors cleanly (e.g. x86)

Closes #521

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 enhances the robustness of the PowerShell CLI installer by introducing a more resilient architecture detection mechanism. It addresses an issue where the primary .NET "RuntimeInformation" API might fail on certain Windows systems, ensuring that the installer can reliably determine the system's architecture using a fallback to environment variables, thereby improving compatibility and user experience.

Highlights

  • Robust Architecture Detection: The PowerShell installer now includes a "try/catch" block for "System.Runtime.InteropServices.RuntimeInformation::OSArchitecture" to handle cases where the .NET type might not be loaded, preventing "$null" returns.
  • Fallback Mechanism: A fallback to the "$env:PROCESSOR_ARCHITECTURE" environment variable has been implemented for architecture detection, ensuring compatibility across various Windows versions and PowerShell environments.
  • Consistent Output: Both the primary .NET "RuntimeInformation" and the fallback environment variable methods now consistently produce "amd64" or "arm64" outputs for supported architectures.
  • Error Handling: The installer maintains clear error messaging, displaying the detected (unsupported) architecture value when an unsupported architecture is encountered.
Changelog
  • cli/scripts/install.ps1
    • Implemented a "try/catch" block around the "System.Runtime.InteropServices.RuntimeInformation::OSArchitecture" call.
    • Added logic to use "$env:PROCESSOR_ARCHITECTURE" as a fallback for architecture detection if the .NET API fails or returns null.
    • Ensured that both detection paths map to "amd64" or "arm64" consistently.
    • Updated error messages to display the specific unsupported architecture detected by either method.
Activity
  • No human activity has been recorded on this pull request yet.
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

coderabbitai bot commented Mar 17, 2026

Warning

Rate limit exceeded

@Aureliolo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cf332ab8-bd97-449a-8136-342814b2b2f3

📥 Commits

Reviewing files that changed from the base of the PR and between 1f51653 and 92399a7.

📒 Files selected for processing (1)
  • cli/scripts/install.ps1
📝 Walkthrough

Walkthrough

The PowerShell installer now attempts to read RuntimeInformation::OSArchitecture inside a try/catch and falls back to PROCESSOR_ARCHITECTURE when unavailable, mapping detected values to amd64/arm64 and emitting explicit errors for unsupported architectures. Several compose and env files add MEM0_TELEMETRY=false.

Changes

Cohort / File(s) Summary
Architecture Detection Fallback
cli/scripts/install.ps1
Wraps access to [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture in try/catch; if unavailable or null, falls back to $env:PROCESSOR_ARCHITECTURE. Maps known values to amd64/arm64 and retains explicit error paths for unsupported values; emits a verbose note when falling back.
Telemetry env additions
cli/internal/compose/compose.yml.tmpl, cli/testdata/compose_custom_ports.yml, cli/testdata/compose_default.yml, cli/testdata/compose_digest_pins.yml, docker/.env.example, docker/compose.yml
Adds MEM0_TELEMETRY=false to backend service environment across compose templates, testdata, and docker examples; includes explanatory comment in .env.example. No logic/control-flow changes beyond adding the variable.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/Invoker
    participant Script as install.ps1
    participant Runtime as RuntimeInformation
    participant Env as PROCESSOR_ARCHITECTURE

    rect rgba(200,220,255,0.5)
    User->>Script: invoke installer
    Script->>Runtime: try read OSArchitecture
    alt Runtime returns value
        Runtime-->>Script: OSArchitecture (X64/Arm64/other)
        Script->>Script: map to amd64/arm64 or error
    else Runtime unavailable or null
        Script->>Env: read PROCESSOR_ARCHITECTURE
        Env-->>Script: AMD64/ARM64/other
        Script->>Script: map to amd64/arm64 or error
    end
    Script->>User: proceed with download/install or error
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR contains out-of-scope changes: adding MEM0_TELEMETRY environment variable to multiple compose files and .env.example is unrelated to the architecture detection fix. Remove changes to docker compose files and .env.example that add MEM0_TELEMETRY, as they are unrelated to the PowerShell installer architecture detection fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix(cli): add fallback arch detection in PowerShell installer' accurately describes the main change—adding architecture detection fallback logic to the PowerShell installer script.
Description check ✅ Passed The PR description is well-related to the changeset, explaining the RuntimeInformation issue, the fallback mechanism using environment variables, and providing a test plan.
Linked Issues check ✅ Passed The PR satisfies all acceptance criteria from issue #521: it adds try/catch around RuntimeInformation, implements fallback to PROCESSOR_ARCHITECTURE environment variables, produces consistent amd64/arm64 outputs, and preserves error messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ps1-arch-detection
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/ps1-arch-detection
📝 Coding Plan
  • Generate coding plan for human review comments

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

@Aureliolo Aureliolo temporarily deployed to cloudflare-preview March 17, 2026 22:16 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@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

The pull request successfully adds a fallback mechanism for architecture detection in the PowerShell installer, which is a great improvement for compatibility. I've suggested a refactoring of the detection logic to make it more concise and maintainable by reducing code duplication.

Comment on lines +38 to 57
$OsArch = $null
try {
$OsArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
} catch {
# Type not available — fall through to env var detection.
}

if ($null -ne $OsArch) {
$WinArch = switch ($OsArch) {
([System.Runtime.InteropServices.Architecture]::X64) { "amd64" }
([System.Runtime.InteropServices.Architecture]::Arm64) { "arm64" }
default { Write-Error "Unsupported architecture: $OsArch"; exit 1 }
}
} else {
$WinArch = switch ($env:PROCESSOR_ARCHITECTURE) {
"AMD64" { "amd64" }
"ARM64" { "arm64" }
default { Write-Error "Unsupported architecture: $env:PROCESSOR_ARCHITECTURE"; exit 1 }
}
}
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.

medium

While the logic is correct, the architecture detection can be simplified to reduce code duplication. You can determine the architecture source first (either from .NET RuntimeInformation or the environment variable), normalize the resulting string, and then use a single, simpler switch statement to determine the $WinArch. This makes the code more concise and easier to maintain.

$DetectedArchStr = $null
try {
    $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
    if ($null -ne $arch) {
        $DetectedArchStr = $arch.ToString()
    }
} catch {
    # Type not available, fall through to env var.
}

if (-not $DetectedArchStr) {
    $DetectedArchStr = $env:PROCESSOR_ARCHITECTURE
}

# Normalize architecture string (e.g. "X64" -> "AMD64")
$NormalizedArch = $DetectedArchStr.ToUpper() -replace "X64", "AMD64"

$WinArch = switch ($NormalizedArch) {
    "AMD64" { "amd64" }
    "ARM64" { "arm64" }
    default { Write-Error "Unsupported architecture: $DetectedArchStr"; exit 1 }
}

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/scripts/install.ps1`:
- Around line 41-43: The empty catch block should emit a verbose message for
observability: inside the catch after the type-detection try, call Write-Verbose
with a concise message such as "Type not available — falling back to env var
detection" and include the caught error details (e.g. $_ or
$Error[0].Exception.Message) so users running the script with -Verbose can see
why execution fell through; update the catch block in install.ps1 accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a1c59e7a-6c5c-484e-9481-373795a6c7cf

📥 Commits

Reviewing files that changed from the base of the PR and between 35e8338 and 222590f.

📒 Files selected for processing (1)
  • cli/scripts/install.ps1
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: CLI Test (windows-latest)
  • GitHub Check: Analyze (python)
🧰 Additional context used
🪛 PSScriptAnalyzer (1.24.0)
cli/scripts/install.ps1

[warning] 41-43: Empty catch block is used. Please use Write-Error or throw statements in catch blocks.

(PSAvoidUsingEmptyCatchBlock)


[warning] Missing BOM encoding for non-ASCII encoded file 'install.ps1'

(PSUseBOMForUnicodeEncodedFile)

🔇 Additional comments (2)
cli/scripts/install.ps1 (2)

33-36: LGTM!

Clear documentation explaining the two-tier detection strategy and referencing the root cause issue.


45-57: LGTM!

Architecture detection logic correctly implements both paths with consistent output values (amd64/arm64) and appropriate error handling for unsupported architectures.

Note: The exit 1 statements after Write-Error are technically unreachable since $ErrorActionPreference = "Stop" promotes the error to terminating, but they serve as defensive guards if that preference is ever changed.

@Aureliolo Aureliolo temporarily deployed to cloudflare-preview March 17, 2026 22:34 — with GitHub Actions Inactive
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/scripts/install.ps1`:
- Around line 42-43: The PowerShell script cli/scripts/install.ps1 contains
non-ASCII characters (e.g., the string literal "RuntimeInformation unavailable;
using PROCESSOR_ARCHITECTURE fallback.") but is not saved with a UTF-8 BOM;
reopen cli/scripts/install.ps1 in your editor and resave the file as UTF-8 with
BOM (UTF-8 with signature) so it satisfies PSUseBOMForUnicodeEncodedFile and
avoids encoding issues on Windows PowerShell 5.1—no source changes needed, only
change the file encoding and commit.
- Around line 53-57: The architecture detection switch that sets $WinArch
currently reads only $env:PROCESSOR_ARCHITECTURE and fails on WOW64; update the
logic used when computing $WinArch (the switch block) to first check
$env:PROCESSOR_ARCHITEW6432 (if defined and non-empty) and use that as the
architecture value, then fall back to $env:PROCESSOR_ARCHITECTURE, keeping the
same mapping cases ("AMD64" -> "amd64", "ARM64" -> "arm64") and the same error
path; ensure this change is applied where $WinArch is assigned so WOW64 (32-bit
PowerShell on 64-bit OS) resolves correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fe09be2a-c9f3-49a1-8853-344363d5be9f

📥 Commits

Reviewing files that changed from the base of the PR and between 222590f and f219f57.

📒 Files selected for processing (1)
  • cli/scripts/install.ps1
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: CLI Test (windows-latest)
  • GitHub Check: Analyze (python)
🧰 Additional context used
🪛 PSScriptAnalyzer (1.24.0)
cli/scripts/install.ps1

[warning] Missing BOM encoding for non-ASCII encoded file 'install.ps1'

(PSUseBOMForUnicodeEncodedFile)

🔇 Additional comments (1)
cli/scripts/install.ps1 (1)

33-51: Good hardening of architecture detection path.

The try/catch + null check flow is clean, preserves existing behavior when RuntimeInformation works, and keeps explicit unsupported-arch errors.

Comment on lines +42 to +43
# Type not available — fall through to env var detection.
Write-Verbose "RuntimeInformation unavailable; using PROCESSOR_ARCHITECTURE fallback."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
python - <<'PY'
from pathlib import Path
p = Path("cli/scripts/install.ps1")
b = p.read_bytes()
print("has_utf8_bom:", b.startswith(b"\xef\xbb\xbf"))
print("non_ascii_byte_count:", sum(x > 127 for x in b))
PY

Repository: Aureliolo/synthorg

Length of output: 105


Save install.ps1 as UTF-8 with BOM to resolve PowerShell encoding rule violation.

The file contains 9 non-ASCII characters but lacks UTF-8 BOM encoding, which triggers PSUseBOMForUnicodeEncodedFile in PSScriptAnalyzer and can impact compatibility with Windows PowerShell 5.1. Either save the file with UTF-8 BOM or remove the non-ASCII characters.

🧰 Tools
🪛 PSScriptAnalyzer (1.24.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'install.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/scripts/install.ps1` around lines 42 - 43, The PowerShell script
cli/scripts/install.ps1 contains non-ASCII characters (e.g., the string literal
"RuntimeInformation unavailable; using PROCESSOR_ARCHITECTURE fallback.") but is
not saved with a UTF-8 BOM; reopen cli/scripts/install.ps1 in your editor and
resave the file as UTF-8 with BOM (UTF-8 with signature) so it satisfies
PSUseBOMForUnicodeEncodedFile and avoids encoding issues on Windows PowerShell
5.1—no source changes needed, only change the file encoding and commit.

RuntimeInformation::OSArchitecture returns $null on some Windows
systems with older .NET runtimes, causing the installer to fail with
"Unsupported architecture:". Fall back to $env:PROCESSOR_ARCHITECTURE
which is available on all Windows versions.

Closes #521
Addresses PSScriptAnalyzer PSAvoidUsingEmptyCatchBlock warning.
Users running with -Verbose can now see why the fallback was used.
- Check PROCESSOR_ARCHITEW6432 before PROCESSOR_ARCHITECTURE to get
  the real OS architecture when running 32-bit PowerShell on 64-bit
  Windows (WOW64 scenario)
- Replace em-dash with ASCII dash to avoid PSUseBOMForUnicodeEncodedFile
  warning and potential encoding issues on Windows PowerShell 5.1
@Aureliolo Aureliolo force-pushed the fix/ps1-arch-detection branch from 1f51653 to 92399a7 Compare March 17, 2026 22:46
@Aureliolo Aureliolo merged commit 0250afb into main Mar 17, 2026
35 of 36 checks passed
@Aureliolo Aureliolo deleted the fix/ps1-arch-detection branch March 17, 2026 22:46
@Aureliolo Aureliolo temporarily deployed to cloudflare-preview March 17, 2026 22:47 — with GitHub Actions Inactive
Aureliolo added a commit that referenced this pull request Mar 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.2](v0.3.1...v0.3.2)
(2026-03-17)


### Features

* **settings:** route structural data reads through SettingsService
([#525](#525))
([289f604](289f604))


### Bug Fixes

* **cli:** add fallback arch detection in PowerShell installer
([#529](#529))
([0250afb](0250afb)),
closes [#521](#521)


### CI/CD

* bump the minor-and-patch group with 2 updates
([#517](#517))
([46bdd1a](46bdd1a))
* bump wrangler from 4.73.0 to 4.74.0 in /.github in the minor-and-patch
group ([#511](#511))
([903b71a](903b71a))


### Maintenance

* bump node from `7a4ef57` to `44bcbf4` in /docker/sandbox
([#515](#515))
([3cbddd1](3cbddd1))
* bump python from `6a27522` to `584e89d` in /docker/backend
([#513](#513))
([0715910](0715910))
* bump python from `6a27522` to `584e89d` in /docker/sandbox
([#514](#514))
([787dfe1](787dfe1))
* bump the minor-and-patch group across 1 directory with 2 updates
([#527](#527))
([e96c0d4](e96c0d4))
* bump the minor-and-patch group across 2 directories with 3 updates
([#512](#512))
([b95ba3d](b95ba3d))
* **docker:** disable Mem0 telemetry in container config
([#531](#531))
([9fc29eb](9fc29eb))
* improve GitHub issue templates with structured forms
([#528](#528))
([4fb66cf](4fb66cf)),
closes [#522](#522)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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(cli): PowerShell installer fails when OSArchitecture returns empty

1 participant