GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(windows): settle scheduler verification and record Bun runtime provenance by lidge-jun · Pull Request #887 · lidge-jun/opencodex Conversation
|
📝 WalkthroughWalkthroughThe change adds Bun runtime provenance tracking across launchers, services, shims, tray processes, management responses, and diagnostics. It also adds bounded Windows scheduler verification retries with ownership-safe rollback and state handling. ChangesBun runtime provenance
Windows scheduler verification
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant ocx.mjs
participant bun-runtime
participant ServiceLauncher
participant ManagementAPI
ocx.mjs->>bun-runtime: resolve Bun path and source
bun-runtime-->>ocx.mjs: validated runtime metadata
ocx.mjs->>ServiceLauncher: spawn with provenance environment
ServiceLauncher->>ManagementAPI: report allowlisted bunRuntimeSource
sequenceDiagram
participant WindowsElevation
participant TaskScheduler
participant Verification
participant InstallState
WindowsElevation->>TaskScheduler: create task
WindowsElevation->>Verification: verify registration
Verification->>TaskScheduler: retry transient visibility
Verification-->>WindowsElevation: verified or fail-closed result
WindowsElevation->>InstallState: write state if ownership remains
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a3bbbe45e
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const raw = env[BUN_RUNTIME_SOURCE_ENV]?.trim(); | ||
| return BUN_RUNTIME_SOURCES.find(source => source === raw); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Validate the recorded runtime path before reporting provenance
When a process inherits OCX_BUN_RUNTIME_SOURCE but subsequently runs a different Bun binary, this function still reports the stale source because it never checks the paired OCX_BUN_RUNTIME_PATH. That is the stale-marker scenario the new withProcessRuntimeProvenance() logic and structure/05_gui-and-management-api.md:120-136 explicitly handle; the management endpoint can therefore tell ocx doctor that an override is active even though the service is actually using a bundled/process runtime. Validate that the recorded path resolves to process.execPath before returning the source, otherwise return undefined.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (d.bunRuntimeSource === "override") { | ||
| lines.push(` OPENCODEX_BUN_PATH is already active for this service — the override runtime is itself an affected version (unvalidated — own risk).`); | ||
| lines.push(" Options: point the override at a different runtime, or opt into streamMode \"eager-relay\" via PUT /api/settings (crash risk on this runtime; see docs)."); | ||
| } else if (d.bunRuntimeSource === undefined) { | ||
| lines.push(" this service records no runtime origin (installed before provenance tracking), so OpenCodex cannot tell whether an override is already active."); | ||
| lines.push(" Reinstall the service to record it, or opt into streamMode \"eager-relay\" via PUT /api/settings (crash risk on this runtime; see docs)."); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Document the new runtime-origin remediation workflow
This changes the user-visible Windows memory workflow: doctor can now say that an override is already active or that a legacy service must be reinstalled, but docs-site/src/content/docs/troubleshooting/windows-memory.md:38-86 and its translations still describe only the previous blanket override workflow and do not explain the provenance/legacy-service message. Update the public troubleshooting page and keep the translated versions consistent so users can act on the new diagnostic.
AGENTS.md reference: AGENTS.md:L200-L201
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const origin = d.bunRuntimeSource === "process" ? "the runtime that launched it" : "the bundled runtime"; | ||
| lines.push(` the service is using ${origin}. Options: wait for a bundled runtime update, or set OPENCODEX_BUN_PATH to a runtime you trust (unvalidated — own risk),`); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Avoid bundled-update advice for process runtimes
When bunRuntimeSource is process and the runtime is affected, this branch still recommends waiting for a bundled runtime update. A process service has baked process.execPath precisely because no bundled runtime was selected, and an opencodex bundled-runtime update does not replace that executable or change the existing service definition, so following this option leaves the affected service unchanged. Give process-origin users remediation for the runtime that launched the service (or tell them to reinstall with a bundled/override runtime) instead.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@devlog/_plan/260802_wt5_windows_service_doctor/000_plan.md`:
- Around line 10-13: The Bug A root-cause statement in the plan must say the old
verifier performed one check and rolled back immediately instead of retrying
transient task-visibility or registration-health failures. Keep the proposed
retry scope limited to those transient states, while preserving fail-closed
handling for conflicts, missing assets, and unknown WinSW status.
In `@src/service.ts`:
- Around line 985-1043: Update schedulerVerificationMaySettle to allow retries
when the task is not installed and nativeStatusUnknown is true, without retrying
proven WinSW presence or an installed task with unknown status. Preserve
existing conflict and asset checks, and add a regression test covering this
compound case in the Windows elevation spawn tests.
In `@src/tray/windows-tray.ps1`:
- Around line 6-8: Update the environment propagation logic in windows-tray.ps1
to add an else branch for an empty $BunRuntimeSource that removes both inherited
Bun provenance keys before launching the child. Preserve the existing
explicit-source behavior, and ensure stale values from process.env cannot reach
reportedBunRuntimeSource().
In `@tests/bun-runtime.test.ts`:
- Around line 152-206: Add regression coverage in the
withProcessRuntimeProvenance tests for both samePath behaviors: create a real
temporary file and symlink alias with fs.symlinkSync, then verify an inherited
marker using the alias is preserved when it resolves to process.execPath; also
exercise the win32 case-insensitive branch by temporarily stubbing
process.platform, asserting differently cased equivalent paths compare as equal,
and restoring the platform value in a finally block.
In `@tests/windows-elevation-spawn.test.ts`:
- Around line 963-986: The test “ownership lost around a non-retryable failure
skips rollback too” must use a genuinely non-retryable verification result, such
as unhealthy assets or a conflict, while still revoking ownership and asserting
rollback is not launched. Add a separate test for the successful path where
verify returns okVerify() after revoking ownership, and assert writeInstallState
is not called to cover the final verification-to-write ownership fence.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8562355b-1bd8-468d-972f-c0bfed317fbe
bin/ocx.mjsdevlog/_plan/260802_wt5_windows_service_doctor/000_plan.mddevlog/_plan/260802_wt5_windows_service_doctor/010_implementation.mdsrc/cli/claude.tssrc/cli/doctor.tssrc/cli/index.tssrc/cli/opencode.tssrc/codex/shim.tssrc/lib/bun-runtime.tssrc/lib/winsw.tssrc/server/management/system-restart.tssrc/server/management/system-routes.tssrc/service.tssrc/tray/windows-tray.ps1src/tray/windows.tssrc/update/index.tsstructure/05_gui-and-management-api.mdtests/bun-runtime.test.tstests/codex-shim.test.tstests/doctor.test.tstests/memory-watchdog.test.tstests/ocx-launcher-source.test.tstests/openai-provider-option-tooling.test.tstests/service.test.tstests/windows-elevation-spawn.test.tstests/windows-tray.test.tstests/winsw.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ### Bug A — PR #868: scheduler registration verification never settles | ||
|
|
||
| - Root cause (from PR body, re-verify): post-create Task Scheduler verification retried non-transient states, so registration verification could fail to settle. Fix retries only transient post-create visibility/XML health states, preserves fail-closed behavior for conflicts/missing assets/unknown SCM status, and stops late reconciliation when attempt ownership changes. | ||
| - Grounding: `src/service.ts`, `src/lib/winsw.ts`, `src/lib/windows-elevation.ts`; verification contracts in scheduler/startup/install tests (PR claims 136 focused tests). |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the scheduler root-cause statement.
Line 12 says that the old verifier retried non-transient states. The measured analysis in devlog/_plan/260802_wt5_windows_service_doctor/010_implementation.md lines 14-21 says that it verified once and rolled back immediately. These are different failure mechanisms.
State that the old flow did not retry transient task-visibility or registration-health failures. Keep the new retry scope limited to those transient states. Otherwise, this plan can lead to retries for conflicts, missing assets, or unknown WinSW status, which must fail closed.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@devlog/_plan/260802_wt5_windows_service_doctor/000_plan.md` around lines 10 -
13, The Bug A root-cause statement in the plan must say the old verifier
performed one check and rolled back immediately instead of retrying transient
task-visibility or registration-health failures. Keep the proposed retry scope
limited to those transient states, while preserving fail-closed handling for
conflicts, missing assets, and unknown WinSW status.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /** | ||
| * Bounded post-create backoff, 1.1s total. Task Scheduler's non-elevated view can | ||
| * lag an elevated `/create` by a few hundred milliseconds, so a single verification | ||
| * would roll back a task that is merely not visible yet. | ||
| */ | ||
| const SCHEDULER_SETTLE_DELAYS_MS = [50, 150, 300, 600] as const; | ||
|
|
||
| /** | ||
| * Whether a failed verification is still worth re-checking after a short delay. | ||
| * | ||
| * Retrying is confined to states that a lagging scheduler view actually produces: | ||
| * the task is not visible yet, or it is visible but its registration has not been | ||
| * published in full. Everything else keeps its existing fail-closed meaning and is | ||
| * rejected here so no delay can turn it into a pass: | ||
| * | ||
| * - a proven conflict (both backends present) is a real dual-backend install; | ||
| * - missing assets are missing on disk, which no amount of waiting creates; | ||
| * - a WinSW service that is proven present (`started`/`stopped`) is never absent | ||
| * later. This is checked independently of `conflict`, which only becomes true | ||
| * once the task itself is visible — while the task is still invisible the pair | ||
| * is `conflict: false` with `nativeServiceAbsent: false`, and that must not retry; | ||
| * - unknown SCM status is unproven rather than transient, and has its own | ||
| * task-preserving branch below. | ||
| */ | ||
| function schedulerVerificationMaySettle(v: WindowsSchedulerInstallVerification): boolean { | ||
| if (v.ok) return false; | ||
| if (v.conflict) return false; | ||
| if (!v.assetsHealthy) return false; | ||
| if (!v.nativeServiceAbsent) return false; | ||
| return !v.taskInstalled || !v.registrationHealthy; | ||
| } | ||
|
|
||
| function settleDelay(ms: number): Promise<void> { | ||
| const hook = finalizeHooks?.settleDelay; | ||
| if (hook) return hook(ms); | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| /** | ||
| * Verify the elevated install, re-checking only while the failure looks like a | ||
| * scheduler view that has not caught up yet. Returns `null` when this attempt lost | ||
| * ownership mid-settle: a newer attempt owns the task, so this one must neither | ||
| * write install state nor roll anything back. | ||
| */ | ||
| async function verifyWindowsSchedulerInstallAfterSettle( | ||
| options: ApplyElevatedOptions, | ||
| ): Promise<WindowsSchedulerInstallVerification | null> { | ||
| const verify = finalizeHooks?.verify ?? verifyWindowsSchedulerInstall; | ||
| let verification = verify(); | ||
| for (const delayMs of SCHEDULER_SETTLE_DELAYS_MS) { | ||
| if (!schedulerVerificationMaySettle(verification)) break; | ||
| if (!attemptStillOwned(options)) return null; | ||
| await settleDelay(delayMs); | ||
| if (!attemptStillOwned(options)) return null; | ||
| verification = verify(); | ||
| } | ||
| return verification; | ||
| } | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🏁 Script executed:
#!/bin/bash # Description: Check whether windows-elevation-spawn.test.ts covers the # task-not-installed + native-status-unknown compound transient case. rg -n -B3 -A15 'nativeStatus.*unknown|nativeStatusUnknown' tests/windows-elevation-spawn.test.ts
Repository: lidge-jun/opencodex
Length of output: 7098
🏁 Script executed:
#!/bin/bash set -eu printf '%s\n' '--- source symbols and implementation ---' ast-grep outline src/service.ts --match 'schedulerVerificationMaySettle' --view expanded || true sed -n '960,1115p' src/service.ts printf '%s\n' '--- settle-related tests ---' sed -n '744,955p' tests/windows-elevation-spawn.test.ts printf '%s\n' '--- relevant type and callers ---' rg -n -B5 -A20 'interface WindowsSchedulerInstallVerification|type WindowsSchedulerInstallVerification|schedulerVerificationMaySettle|preserveElevatedTask|nativeStatusUnknown' src/service.ts tests/windows-elevation-spawn.test.ts
Repository: lidge-jun/opencodex
Length of output: 41534
🏁 Script executed:
#!/bin/bash set -eu printf '%s\n' '--- verification probe construction ---' sed -n '850,945p' src/service.ts printf '%s\n' '--- exact compound-case coverage ---' rg -n -B8 -A18 'taskInstalled:\s*false[\s\S]{0,500}nativeStatusUnknown:\s*true|nativeStatusUnknown:\s*true[\s\S]{0,500}taskInstalled:\s*false' tests/windows-elevation-spawn.test.ts || true printf '%s\n' '--- predicate truth table ---' python3 - <<'PY' from itertools import product def current(v): if v["ok"] or v["conflict"] or not v["assetsHealthy"] or not v["nativeServiceAbsent"]: return False return not v["taskInstalled"] or not v["registrationHealthy"] def proposed(v): if v["ok"] or v["conflict"] or not v["assetsHealthy"]: return False proven_present = not v["nativeServiceAbsent"] and not v["nativeStatusUnknown"] if proven_present: return False if not v["nativeServiceAbsent"] and v["taskInstalled"]: return False return not v["taskInstalled"] or not v["registrationHealthy"] for task, absent, unknown, healthy in product((False, True), (False, True), (False, True), (False, True)): v = { "ok": False, "conflict": False, "assetsHealthy": True, "taskInstalled": task, "nativeServiceAbsent": absent, "nativeStatusUnknown": unknown, "registrationHealthy": healthy, } if current(v) != proposed(v): print(v, "current=", current(v), "proposed=", proposed(v)) PY
Repository: lidge-jun/opencodex
Length of output: 4551
Retry when the task is not visible and nativeStatusUnknown is true. At src/service.ts:1009-1014, !v.nativeServiceAbsent blocks settling even when v.nativeStatusUnknown is true and v.taskInstalled is false. The code then rolls back the task. Preserve the current fail-closed behavior for proven WinSW presence and for task-installed unknown status. Add a regression test for this compound case in tests/windows-elevation-spawn.test.ts.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/service.ts` around lines 985 - 1043, Update
schedulerVerificationMaySettle to allow retries when the task is not installed
and nativeStatusUnknown is true, without retrying proven WinSW presence or an
installed task with unknown status. Preserve existing conflict and asset checks,
and add a regression test covering this compound case in the Windows elevation
spawn tests.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Provenance of $BunPath, chosen when the tray entry was built. Optional so an | ||
| # already-installed launcher command from an older version still starts. | ||
| [ValidateSet("", "override", "bundled", "process")][string]$BunRuntimeSource = "", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🏁 Script executed:
#!/bin/bash # Description: Find how windows-tray.ps1 is spawned, to check whether its own # process environment could already carry OCX_BUN_RUNTIME_SOURCE/PATH. rg -n -B5 -A15 'windows-tray\.ps1' src/tray/windows.ts
Repository: lidge-jun/opencodex
Length of output: 849
🏁 Script executed:
#!/bin/bash set -e printf '%s\n' '--- windows-tray.ps1 relevant sections ---' sed -n '1,24p' src/tray/windows-tray.ps1 sed -n '80,112p' src/tray/windows-tray.ps1 printf '%s\n' '--- tray launcher and environment handling ---' sed -n '1,180p' src/tray/windows.ts printf '%s\n' '--- provenance references ---' rg -n -C3 'OCX_BUN_RUNTIME_(SOURCE|PATH)|BunRuntimeSource|opencodex-tray\.vbs|windows-tray\.ps1' src structure 2>/dev/null
Repository: lidge-jun/opencodex
Length of output: 24754
🏁 Script executed:
#!/bin/bash set -e python3 - <<'PY' from pathlib import Path p = Path("src/tray/windows-tray.ps1") text = p.read_text(encoding="utf-8") for key in ("OCX_BUN_RUNTIME_SOURCE", "OCX_BUN_RUNTIME_PATH"): print(key, "occurrences:", text.count(key)) print("parameter default:") for line_no, line in enumerate(text.splitlines(), 1): if "BunRuntimeSource" in line or "EnvironmentVariables" in line: print(f"{line_no}: {line}") PY printf '%s\n' '--- all Windows tray entry creation and invocation sites ---' rg -n -C5 'sourceTrayScriptPath|windows-tray|BunRuntimeSource|OCX_BUN_RUNTIME' src --glob '!src/tray/windows-tray.ps1'
Repository: lidge-jun/opencodex
Length of output: 23021
🏁 Script executed:
#!/bin/bash set -e printf '%s\n' '--- exact script call graph ---' rg -n -C8 'Start-OcxCommand|BunRuntimeSource|ArgumentList|EnvironmentVariables' src/tray/windows-tray.ps1 printf '%s\n' '--- launch command construction ---' rg -n -C12 'sourceTrayScriptPath|powershell|pwsh|opencodex-tray|launcherPath|BunRuntimeSource' src/tray/windows.ts src/tray --glob '!src/tray/windows-tray.ps1' printf '%s\n' '--- design rule ---' rg -n -C5 'marker|describes.*binary|OCX_BUN_RUNTIME' structure src 2>/dev/null
Repository: lidge-jun/opencodex
Length of output: 50376
🌐 Web query:
.NET ProcessStartInfo EnvironmentVariables collection default inherits current process environment Windows PowerShell
💡 Result:
In.NET, the EnvironmentVariables (or the newer Environment property) collection within ProcessStartInfo automatically inherits the environment variables of the current process upon being accessed for the first time [1][2]. Key details include: 1. Lazy Initialization: The collection is populated with the current process's environment variables only when you first access the property [2][3]. Before that first access, the underlying storage is typically null [2][3]. 2. Default Behavior: Because it is initialized with a copy of the current environment, any subsequent modifications you make to this dictionary (such as adding or removing variables) will apply only to the new child process being started, not the current process [4][5]. 3. Windows PowerShell Context: The Start-Process cmdlet in PowerShell provides a high-level wrapper around this functionality [6]. By default, Start-Process inherits environment variables from the parent process [6]. If you use the -Environment parameter in PowerShell 7.4 or later, you can specify a hash table to override or supplement these variables for the new process [6]. Note that if you use -UseNewEnvironment, PowerShell ignores the parent process's environment variables and uses only the default system-level variables (Machine and User scopes) [6]. 4. Important Limitation: You must set the UseShellExecute property to false on the ProcessStartInfo object to manually modify the environment variables [4][5][7]. If UseShellExecute is true, attempting to start the process after accessing or modifying the environment variables will result in an InvalidOperationException [4][5][7]. Additionally, certain operations, such as starting a process with -Verb RunAs in PowerShell, implicitly require UseShellExecute = true, which makes it impossible to modify the environment via these properties [8].
Citations:
Start-Process on Windows: -Environment is quietly ignored when -Verb RunAs is also specified, combination should be prevented. PowerShell/PowerShell#20923🌐 Web query:
site:github.com/lidge-jun/opencodex "BunRuntimeSource" "windows-tray.ps1"
💡 Result:
The term "BunRuntimeSource" is not a recognized standard component, library, or script in the context of Windows development, PowerShell, or the Bun runtime ecosystem [1][2][3]. Based on research into technical repositories that interact with both Bun and Windows automation, the query likely refers to a misunderstanding or a specific internal identifier within the "opencodex" project (a repository utilizing Bun for cross-platform task management) [1][4][3]. In that project, automation scripts (such as install.ps1 or service lifecycle workflows) are used to handle service registration and task scheduling on Windows [4][3][5]. While these scripts utilize Bun as the runtime for the CLI, they do not include a file named "windows-tray.ps1" nor reference a "BunRuntimeSource" as a standalone entity [4][3][5]. If you are encountering a specific error message mentioning "BunRuntimeSource," it is likely a misinterpretation of a stack trace or an internal variable name from a proprietary or niche open-source codebase. You may want to check the specific documentation or issue tracker for the software you are running, as identifiers like these are often implementation-specific to a particular project's build or runtime handling logic [1][2][3].
Citations:
🏁 Script executed:
#!/bin/bash set -e printf '%s\n' '--- Windows tray command execution ---' sed -n '130,195p' src/tray/windows.ts sed -n '550,680p' src/tray/windows.ts printf '%s\n' '--- tray control callers ---' rg -n -C8 'installWindowsTray|startWindowsTray|runWindowsTrayAction|windowsTrayProcessArgs|buildWindowsTrayPowerShellCommand' src/server src/tray --glob '*.ts' printf '%s\n' '--- marker semantics ---' sed -n '112,160p' structure/05_gui-and-management-api.md sed -n '52,115p' src/lib/bun-runtime.ts
Repository: lidge-jun/opencodex
Length of output: 33706
Remove inherited provenance keys when $BunRuntimeSource is empty.
src/tray/windows.ts:542-546 passes process.env to the PowerShell host, and src/tray/windows-tray.ps1:98-103 copies that environment into the child. An older launcher can omit -BunRuntimeSource, allowing a stale marker for another $BunPath to reach the child. reportedBunRuntimeSource() trusts the source value without checking the path, so /api/system/memory and ocx doctor can report incorrect provenance. Add an else branch that removes both keys.
[warning] 8-8: The parameter 'BunRuntimeSource' has been declared but not used.
(PSReviewUnusedParameter)
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tray/windows-tray.ps1` around lines 6 - 8, Update the environment
propagation logic in windows-tray.ps1 to add an else branch for an empty
$BunRuntimeSource that removes both inherited Bun provenance keys before
launching the child. Preserve the existing explicit-source behavior, and ensure
stale values from process.env cannot reach reportedBunRuntimeSource().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| describe("withProcessRuntimeProvenance (execPath relaunch paths)", () => { | ||
| // Under `bun test` the runner may itself BE the bundled binary, in which case | ||
| // `bundled` is the correct answer rather than `process`. Both are legitimate; | ||
| // what matters is that a real origin is always recorded. | ||
| const executingOrigin = bundledBunPath() === process.execPath ? "bundled" : "process"; | ||
|
|
||
| it("records the executable's real origin when the relaunching parent carries no marker", () => { | ||
| // `ocx ensure`, GUI start, restart, and update-relaunch all re-exec | ||
| // process.execPath. Without this they would hand the daemon no provenance at | ||
| // all, and doctor would report unknown for an origin the launcher knew. | ||
| expect(withProcessRuntimeProvenance({})[BUN_RUNTIME_SOURCE_ENV]).toBe(executingOrigin); | ||
| }); | ||
|
|
||
| it("preserves an inherited marker instead of relabeling the same runtime", () => { | ||
| // Re-execing the current runtime does not change how that runtime was obtained, | ||
| // but the claim is only carried forward when the binary it was minted for is the | ||
| // one about to run. The recorded path is what settles that — re-deriving the | ||
| // selection would demote a service installed with a shell-local override. | ||
| const overrideEnv = { | ||
| [BUN_RUNTIME_SOURCE_ENV]: "override", | ||
| [BUN_RUNTIME_PATH_ENV]: process.execPath, | ||
| }; | ||
| expect(withProcessRuntimeProvenance(overrideEnv)[BUN_RUNTIME_SOURCE_ENV]).toBe("override"); | ||
|
|
||
| // Crucially this holds with no OPENCODEX_BUN_PATH in the environment at all: an | ||
| // installed service keeps neither the shell that installed it nor its variables. | ||
| expect(overrideEnv).not.toHaveProperty("OPENCODEX_BUN_PATH"); | ||
|
|
||
| // The pair is re-stamped for the child, so the next relaunch can do the same check. | ||
| expect(withProcessRuntimeProvenance(overrideEnv)[BUN_RUNTIME_PATH_ENV]).toBe(process.execPath); | ||
| }); | ||
|
|
||
| it("drops an inherited marker that no longer describes the running binary", () => { | ||
| // Inheritance travels down a process tree, so a marker can outlive the binary it | ||
| // was minted for: something launched under a marked process but running a | ||
| // different Bun must not relaunch the daemon claiming that other binary's origin. | ||
| const staleOverride = { | ||
| [BUN_RUNTIME_SOURCE_ENV]: "override", | ||
| [BUN_RUNTIME_PATH_ENV]: join(tmp, "some-other-bun.exe"), | ||
| }; | ||
| expect(withProcessRuntimeProvenance(staleOverride)[BUN_RUNTIME_SOURCE_ENV]).not.toBe("override"); | ||
|
|
||
| // A source with no recorded path cannot be corroborated and is not carried forward. | ||
| expect(withProcessRuntimeProvenance({ [BUN_RUNTIME_SOURCE_ENV]: "override" })[BUN_RUNTIME_SOURCE_ENV]).not.toBe("override"); | ||
| }); | ||
|
|
||
| it("replaces an unrecognized inherited value rather than forwarding it", () => { | ||
| expect(withProcessRuntimeProvenance({ [BUN_RUNTIME_SOURCE_ENV]: "system" })[BUN_RUNTIME_SOURCE_ENV]).toBe(executingOrigin); | ||
| }); | ||
|
|
||
| it("leaves every other variable untouched", () => { | ||
| const result = withProcessRuntimeProvenance({ OCX_SERVICE: "1", PATH: "/usr/bin" }); | ||
| expect(result.OCX_SERVICE).toBe("1"); | ||
| expect(result.PATH).toBe("/usr/bin"); | ||
| }); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Add regression coverage for symlink resolution and Windows path casing in samePath.
These tests cover marker preservation and staleness through exact-string path comparisons only. None of them exercise the two behaviors src/lib/bun-runtime.ts's samePath (Lines 116-129) specifically added: symlink resolution via realpathSync, and case-insensitive comparison on win32. The stale-marker test at Line 190 uses a non-existent path, so it only exercises the try/catch fallback to a lexical comparison, not the resolved-path branch.
Add a symlink test: create a real file in tmp, create an fs.symlinkSync alias to it at a different path, put the alias path in BUN_RUNTIME_PATH_ENV, and assert withProcessRuntimeProvenance treats process.execPath-equivalent paths as the same binary through the symlink. This is achievable cross-platform.
For the win32 casing branch, consider stubbing process.platform (e.g., Object.defineProperty(process, "platform", { value: "win32" }) with restoration in a finally) and asserting two differently-cased paths compare equal.
The PR states live Windows validation was unavailable, which makes this coverage gap more important: it is the only way to confirm the claimed fix behaves as intended before a real Windows service exercises it.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/bun-runtime.test.ts` around lines 152 - 206, Add regression coverage in
the withProcessRuntimeProvenance tests for both samePath behaviors: create a
real temporary file and symlink alias with fs.symlinkSync, then verify an
inherited marker using the alias is preserved when it resolves to
process.execPath; also exercise the win32 case-insensitive branch by temporarily
stubbing process.platform, asserting differently cased equivalent paths compare
as equal, and restoring the platform value in a finally block.
Source: Path instructions
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| test("ownership lost around a non-retryable failure skips rollback too", async () => { | ||
| // The settle loop never awaits for a non-retryable verdict, so this is the only | ||
| // path that reaches the pre-rollback ownership fence: a stale attempt must not | ||
| // delete a task that a newer attempt now owns. | ||
| mockParentRollbackSpawn(); | ||
| let owned = true; | ||
| let probes = 0; | ||
| setFinalizeWindowsSchedulerHooksForTests({ | ||
| elevateCreateAndRun: succeedingElevation(), | ||
| verify: () => { | ||
| probes += 1; | ||
| owned = false; | ||
| return unhealthyVerify(); | ||
| }, | ||
| settleDelay: async () => { throw new Error("must not settle a non-retryable verdict"); }, | ||
| stillOwnsAttempt: () => owned, | ||
| writeInstallState: () => { writeCount += 1; }, | ||
| }); | ||
|
|
||
| await expect(finalizeWindowsSchedulerServiceRegistration()).resolves.toEqual({ kind: "done" }); | ||
| expect(probes).toBe(1); | ||
| expect(writeCount).toBe(0); | ||
| expect(parentRollbackLaunches).toBe(0); | ||
| }); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Exercise the actual rollback and final-write ownership fences.
unhealthyVerify() is retry-eligible. It has healthy assets, nativeServiceAbsent: true, and conflict: false. The plan requires retries for this state. Therefore, Line 975 does not create the non-retryable failure described by this test.
Replace this fixture with a non-retryable result, such as assetsHealthy: false or conflict: true. Then revoke ownership in verify and assert that rollback does not start.
Add a separate test where verify revokes ownership and returns okVerify(). Assert that writeInstallState is not called. The current test at lines 945-961 only covers ownership loss during a delay. It does not protect the final successful verification-to-state-write race.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/windows-elevation-spawn.test.ts` around lines 963 - 986, The test
“ownership lost around a non-retryable failure skips rollback too” must use a
genuinely non-retryable verification result, such as unhealthy assets or a
conflict, while still revoking ownership and asserting rollback is not launched.
Add a separate test for the successful path where verify returns okVerify()
after revoking ownership, and assert writeInstallState is not called to cover
the final verification-to-write ownership fence.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Superseded by #892, which lands both fixes natively: post-create scheduler verification now settles only on transient states (published-but-invalid XML rolls back with zero delays, conflicts/missing assets/unknown SCM stay fail-closed), and Bun runtime provenance is reported as a source+path pair through every launcher with legacy payloads reading as unknown. The unified branch additionally enforces the binary half of the pair (source-only or mismatched-path markers report unknown). Thank you — the issue analysis and the direction drove the fix. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.