Skip to content

fix: mark packaged backend as desktop-managed#146

Merged
zouyonghe merged 2 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/desktop-managed-backend-env-pr
Jul 2, 2026
Merged

fix: mark packaged backend as desktop-managed#146
zouyonghe merged 2 commits into
AstrBotDevs:mainfrom
zouyonghe:fix/desktop-managed-backend-env-pr

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Jul 1, 2026

Copy link
Copy Markdown
Member

Background

AstrBot Desktop manages the packaged backend process from the Tauri shell. The same backend can also serve WebUI pages to an external browser. In that browser path, there is no Tauri desktop bridge, so the original WebUI fallback can call core restart/update APIs directly.

The paired Core-side guard needs a reliable signal that the backend is managed by the desktop shell.

Summary

  • Add ASTRBOT_DESKTOP_MANAGED=1 to packaged backend process environment.
  • Keep the existing ASTRBOT_DESKTOP_CLIENT=1 marker.
  • Centralize both desktop backend environment keys as module constants.
  • Centralize environment injection in configure_desktop_managed_environment().
  • Add a launch test verifying both environment variables are set.

Behavior

For packaged desktop-managed backends, the child process now receives:

ASTRBOT_DESKTOP_CLIENT=1
ASTRBOT_DESKTOP_MANAGED=1

This lets AstrBot Core reject browser/API-triggered self-restart and self-update flows while preserving the existing desktop runtime marker.

Related Core PR

The paired Core PR consumes ASTRBOT_DESKTOP_MANAGED=1 to block unmanaged restart/update paths:

Review / CI Follow-up

  • Addressed Sourcery feedback by centralizing the desktop environment variable names as constants.
  • Fixed the initial cargo fmt --check CI failure.

Tests

rtk cargo fmt --all
rtk cargo test backend::launch::tests

CI status at last check: all reported checks passed, no failing checks.

Summary by Sourcery

Mark packaged backend processes as desktop-managed via dedicated environment configuration.

Bug Fixes:

  • Ensure packaged backend processes are correctly marked as desktop-managed using dedicated environment variables.

Enhancements:

  • Introduce a reusable helper to configure desktop-managed environment variables for backend commands.

Tests:

  • Add a unit test verifying that the desktop-managed environment configuration sets the expected environment variables.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a helper function configure_desktop_managed_environment to set the ASTRBOT_DESKTOP_CLIENT and ASTRBOT_DESKTOP_MANAGED environment variables when running in packaged mode. It also includes corresponding unit tests to verify that these environment variables are correctly set. There are no review comments, and the changes look clean and well-tested, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/backend/launch.rs" line_range="135-137" />
<code_context>
     command.env("PYTHONNOUSERSITE", "1");
 }

+fn configure_desktop_managed_environment(command: &mut Command) {
+    command.env("ASTRBOT_DESKTOP_CLIENT", "1");
+    command.env("ASTRBOT_DESKTOP_MANAGED", "1");
+}
+
</code_context>
<issue_to_address>
**suggestion:** Consider centralizing the ASTRBOT_* environment variable names as shared constants.

These env var keys are now duplicated here and in call sites/tests. Defining shared module-level constants for `ASTRBOT_DESKTOP_CLIENT`, `ASTRBOT_DESKTOP_MANAGED`, and any related `ASTRBOT_*` vars would reduce typo risk and make future changes easier to manage in one place.

Suggested implementation:

```rust
    command.env("PYTHONNOUSERSITE", "1");
}

// Shared environment variable keys for Astrbot desktop flows.
const ENV_ASTRBOT_DESKTOP_CLIENT: &str = "ASTRBOT_DESKTOP_CLIENT";
const ENV_ASTRBOT_DESKTOP_MANAGED: &str = "ASTRBOT_DESKTOP_MANAGED";

fn configure_desktop_managed_environment(command: &mut Command) {
    command.env(ENV_ASTRBOT_DESKTOP_CLIENT, "1");
    command.env(ENV_ASTRBOT_DESKTOP_MANAGED, "1");
}

```

1. Replace any other hard-coded `"ASTRBOT_DESKTOP_CLIENT"` and `"ASTRBOT_DESKTOP_MANAGED"` usages in this module (and possibly others) with `ENV_ASTRBOT_DESKTOP_CLIENT` and `ENV_ASTRBOT_DESKTOP_MANAGED` respectively.
2. If there are additional `ASTRBOT_*` environment variables used elsewhere in `launch.rs`, consider defining corresponding `const ENV_ASTRBOT_...` identifiers alongside these new constants to fully centralize the keys.
3. If tests or helper utilities refer directly to these env var names as string literals, update them to either import and reuse these constants (if appropriate/accessible) or to define their own shared constants in the relevant test modules.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/backend/launch.rs Outdated
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit 35f61e4 into AstrBotDevs:main Jul 2, 2026
4 checks passed
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.

1 participant