Skip to content

feat: add windows launch service - #1441

Merged
Teingi merged 8 commits into
oceanbase:masterfrom
Alanxtl:add_windows
Sep 3, 2026
Merged

feat: add windows launch service#1441
Teingi merged 8 commits into
oceanbase:masterfrom
Alanxtl:add_windows

Conversation

@Alanxtl

@Alanxtl Alanxtl commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Closes #1298

Implements RFC 1299.

Rationale for this change

Complete the Windows implementation of the personal Server service lifecycle defined by RFC 1299. Windows users can run PowerContext as a persistent current-user service without administrator privileges or a visible console window.

What changes are included in this PR?

  • Add the Windows Task Scheduler adapter for the current user.
  • Add ownership validation, lifecycle operations, restart policy, and foreign-task protection.
  • Use pythonw.exe to avoid opening a visible CMD window.
  • Redirect Server stdout and stderr to PowerContext-owned log files.
  • Support enabling or disabling automatic startup when the current user logs in.
  • Add Windows-native lifecycle tests and Windows CI coverage.
  • Update README and deployment documentation for Windows.

Are there any user-facing changes?

Windows is now supported by powercontext service install, status, and uninstall.

The service runs as the current user through Task Scheduler and does not install a Windows Service or require administrator privileges. Existing service definitions remain compatible.

How was this change tested?

  • make check
  • make docs-test
  • uv run pytest -q tests/test_service.py tests/test_service_environment.py tests/test_system_cli.py
  • Windows Task Scheduler native lifecycle tests on an isolated Windows environment:
    4 passed, 1 skipped
  • Verified powercontext service install --help
  • tested on my windows

AI usage statement

OpenAI Codex

if result.returncode != 0:
return ManagerState.UNKNOWN
values = _list_output(result.stdout)
status = values.get("status", "").casefold()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] On localized Windows installations, /FO LIST localizes the field names as well as the values, but these lookups only accept the English keys status and last result. For example, 状态: 正在运行 is stored under 状态, so manager_state() returns UNKNOWN; the first install then aborts in start(reload_definition=True) before /Run. Please use a locale-independent Task Scheduler state API and add a non-English regression test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed, now use PowerShell Task Scheduler API

principal = _child(principals, "Principal") if principals is not None else None
settings = _child(root, "Settings")
actions = _child(root, "Actions")
execute = _child(actions, "Exec") if actions is not None else None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] This validates only the first Exec action. Appending a second Exec (for example, cmd.exe) still makes loaded_registration() return OWNED, so a modified task can execute extra commands while passing the status/install/uninstall ownership checks. Please require exactly the expected action, trigger, and principal structure, reject any extras as FOREIGN, and add regression tests for additional elements.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed, now check action、trigger、principal only

def _validate_windows_protection(path: Path) -> None:
"""Require a Windows ACL limited to the interactive user and trusted OS admins."""

account, sid = _windows_user_identity()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P1] This ACL check never verifies the file owner SID. On Windows st_uid is recorded as 0, so a file owned by another account can pass as long as its current DACL contains the allowed principals; that owner can later change the DACL and regain access to the credential file. Please require the current user's owner SID, persist it in the installed identity, and revalidate it on launch.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed, now Windows recheck owner SID


if start_on_login is None:
start_on_login = (
typer.confirm("Enable automatic Server startup when you log in?", default=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Pressing Enter here installs without login auto-start, while the README and English RFC still document bare powercontext service install as enabling startup for future logins; only the Chinese RFC describes this prompt and opt-out. Please choose one default and keep the implementation and both locales in sync.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@Teingi Teingi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Teingi
Teingi merged commit 4e0f78a into oceanbase:master Sep 3, 2026
17 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.

Tracking Issue: local Server availability and service installation

2 participants