Skip to content

fix(service): bake WinSW admin env and retry stop-path probes - #805

Merged
Wibias merged 14 commits into
devfrom
fix/764-winsw-env-and-liveness-probe
Jul 31, 2026
Merged

fix(service): bake WinSW admin env and retry stop-path probes#805
Wibias merged 14 commits into
devfrom
fix/764-winsw-env-and-liveness-probe

Conversation

@Wibias

@Wibias Wibias commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #764

Closes the remaining gaps after #780:

  • Always bake OPENCODEX_HOME into WinSW XML and pass install-time OPENCODEX_ACL_TIMEOUT_MS so the native SCM service sees them (SCM does not inherit the interactive user env). Admin auth stays file-backed (admin-api-token) — never embed OPENCODEX_ADMIN_AUTH_TOKEN in the XML.
  • Retry short /healthz transport timeouts on the service-stop liveness path (SERVICE_STOP_LIVENESS: 1500ms x 3 attempts) so a just-bound proxy is not treated as absent.

Test plan

  • bun test tests/winsw.test.ts tests/proxy-liveness.test.ts tests/service.test.ts tests/service-stop-verification.test.ts
  • bun run typecheck
  • CI green

Summary by CodeRabbit

  • Bug Fixes

    • Improved service liveness checks by retrying temporary connection failures.
    • Standardized liveness verification during service stopping and cleanup.
    • Ensured generated service configuration consistently includes the configured home directory and ACL timeout.
    • Prevented API and administrator token values from being included in service configuration.
  • Tests

    • Added coverage for retry behavior, service cleanup checks, and secure service configuration generation.

Close the remaining #764 gaps: native WinSW now inherits install-time OPENCODEX_ADMIN_AUTH_TOKEN / OPENCODEX_ACL_TIMEOUT_MS, and service stop liveness retries short transport timeouts instead of treating a just-bound proxy as absent.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Wibias, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f195ae31-45b1-431c-b98c-e7ee737f6ab4

📥 Commits

Reviewing files that changed from the base of the PR and between b1d0f8a and 3e95ba3.

📒 Files selected for processing (6)
  • src/server/proxy-liveness.ts
  • src/service.ts
  • tests/api-storage-cleanup.test.ts
  • tests/proxy-liveness.test.ts
  • tests/service.test.ts
  • tests/winsw.test.ts
📝 Walkthrough

Walkthrough

The change adds bounded retries to proxy identity checks, applies a shared liveness policy to service stop and orphan cleanup, and updates WinSW XML to include configured environment values while excluding authentication tokens.

Changes

Service lifecycle updates

Layer / File(s) Summary
WinSW environment serialization
src/lib/winsw.ts, tests/winsw.test.ts
WinSW XML always emits OPENCODEX_HOME and optionally emits trimmed OPENCODEX_ACL_TIMEOUT_MS. Tests verify that authentication token names and values remain absent.
Retry-aware liveness policy
src/server/proxy-liveness.ts, tests/proxy-liveness.test.ts
LivenessIo gains retry options, and SERVICE_STOP_LIVENESS defines a 1500 ms timeout with three attempts. Transport failures retry with 100 ms delays. Definitive failures return immediately. Tests cover both paths.
Service stop and orphan cleanup integration
src/service.ts, tests/service.test.ts
Service stop verification and orphan recovery use SERVICE_STOP_LIVENESS. Tests verify that the shared policy is passed to findLiveProxy.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant service
  participant proxyIdentityAt
  participant healthz
  participant sleepFn
  service->>proxyIdentityAt: findLiveProxy(SERVICE_STOP_LIVENESS)
  proxyIdentityAt->>healthz: request /healthz
  healthz-->>proxyIdentityAt: transport failure
  proxyIdentityAt->>sleepFn: wait 100 ms
  sleepFn-->>proxyIdentityAt: retry
  proxyIdentityAt->>healthz: request /healthz
  healthz-->>proxyIdentityAt: proxy identity
  proxyIdentityAt-->>service: live proxy result
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses environment propagation and liveness retries, but it does not fix wrapper termination, task-removal safety, account preflight, or non-interactive install hangs in #764. Implement and test the remaining #764 lifecycle fixes, or link a narrower issue that limits scope to environment propagation and liveness retries.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two primary changes: WinSW environment configuration and retrying stop-path liveness probes.
Out of Scope Changes check ✅ Passed The code and tests remain focused on WinSW configuration, proxy liveness retries, and service stop behavior described in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/764-winsw-env-and-liveness-probe

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7a74d096d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread src/lib/winsw.ts Outdated
Wibias added 2 commits July 31, 2026 08:27
Codex P1: uninstall retains the WinSW XML, so baking the admin secret would leave it on disk. Keep ACL timeout + always-bake OPENCODEX_HOME so file-backed admin auth still resolves under SCM.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
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 `@tests/service.test.ts`:
- Around line 664-668: Extend the service source assertions in
tests/service.test.ts to verify the default findProxy closure uses
proxyStillLiveAfterStop, in addition to the existing orphan-cleanup assertions.
Add a focused assertion near the checks for findLiveProxy and
SERVICE_STOP_LIVENESS, targeting the default stop-verification path.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1f3bfcac-e94b-4fdf-a28f-76191a0e4e53

📥 Commits

Reviewing files that changed from the base of the PR and between f2b61ee and 29b961d.

📒 Files selected for processing (6)
  • src/lib/winsw.ts
  • src/server/proxy-liveness.ts
  • src/service.ts
  • tests/proxy-liveness.test.ts
  • tests/service.test.ts
  • tests/winsw.test.ts

Comment thread tests/service.test.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
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 `@src/server/proxy-liveness.ts`:
- Around line 92-107: Bound proxy discovery by one aggregate caller deadline:
update findLiveProxy and proxyIdentityAt to propagate the remaining budget and
derive each probe’s timeout/retries from it, so multi-candidate discovery cannot
exceed proxyStillLiveAfterStop or stopTrackedProxyIfRunning verification
windows. Preserve immediate returns for successful or definitive non-transport
responses, and add a focused all-transport-failure regression test near the
existing service tests in tests/service.test.ts.
- Line 90: Update the attempts normalization in proxyIdentityAt so NaN is
converted to the documented one-attempt default before applying Math.trunc and
the 1–5 bounds. Preserve the existing clamping behavior for valid numeric values
and ensure the loop still performs one fetch attempt when attempts is NaN.

In `@tests/winsw.test.ts`:
- Around line 33-37: Update the WinSW XML test around the OPENCODEX_HOME
assertions to parse the generated XML, extract and decode the OPENCODEX_HOME
environment value, and compare it with getConfigDir(). Keep the existing
assertions that secret token values are absent, and apply the same
resolved-value validation to the additional assertion range.
- Around line 39-49: Add a unique sentinel value for OPENCODEX_API_AUTH_TOKEN in
the env passed to buildWinswXml within the test, then assert that this sentinel
does not occur in the generated XML, alongside the existing token-name
assertion.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2bc9965b-f27b-45a3-a50e-a077ce8aaf15

📥 Commits

Reviewing files that changed from the base of the PR and between ebd4cdf and b1d0f8a.

📒 Files selected for processing (6)
  • src/lib/winsw.ts
  • src/server/proxy-liveness.ts
  • src/service.ts
  • tests/proxy-liveness.test.ts
  • tests/service.test.ts
  • tests/winsw.test.ts

Comment thread src/server/proxy-liveness.ts Outdated
Comment thread src/server/proxy-liveness.ts
Comment thread tests/winsw.test.ts Outdated
Comment thread tests/winsw.test.ts
Wibias added 5 commits July 31, 2026 10:00
Stop-path discovery now shares a wall-clock deadline so multi-candidate
SERVICE_STOP_LIVENESS retries cannot overrun the verification window, and
tests assert resolved OPENCODEX_HOME plus absent API/admin token values.
The preview route test was failing at Bun's 5s default under runner contention while siblings already used 20s.
@Wibias

Wibias commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Merging this.

Why it helps: WinSW services now see OPENCODEX_HOME (and ACL timeout when set) without embedding admin tokens in XML, and stop-path /healthz probes retry briefly so a just-bound proxy is not treated as dead.

@Wibias
Wibias merged commit b1f33ab into dev Jul 31, 2026
13 checks passed
@Wibias
Wibias deleted the fix/764-winsw-env-and-liveness-probe branch July 31, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant