Skip to content

Handoff step: best-effort catch narrower than upstream's #871

Closed

Description

@Blind-Striker

What

The background service's persistent-terminal handoff step is best-effort in upstream's first-party client: any failure of the step is caught, and the old service is still terminated. The SDK's step catches two exception types only. An exception of any other type ends StopAsync, or the EnsureAsync election, before the terminate.

Upstream at the pin (v2.3.0)

  • stop catches any failure of the handoff or clear and only warns, then terminates: packages/client/src/promise/service.ts:105-111. The Effect twin does the same at packages/client/src/effect/service.ts:133-137.
  • ensure's replacement wraps the whole stop in .catch(() => undefined): packages/client/src/promise/service.ts:84. A failure of the replacement stop, terminate included, never ends ensure.

The SDK today

Paths are at the head of the #842 change, e105aceb, which lifts the election's step into a shared type unchanged. On master before it, the same catch is in ServiceElection.PrepareOrClearAsync, and the stop's own sidecar clear catches only OpenCodeServerException.

  • The shared step, ServicePtyHandoffStep.RunAsync (src/OpenCode.Sdk/Hosting/BackgroundService/Internal/Handoff/ServicePtyHandoffStep.cs:28), catches only OpenCodeServerException and ArgumentException { ParamName: "endpoint" }. Both ServiceStopper and ServiceElection.ReplaceAsync use it.
  • ServiceElection.ReplaceAsync (src/OpenCode.Sdk/Hosting/BackgroundService/Internal/Ensure/ServiceElection.cs:178) catches only OpenCodeServerException around the read, the step and the terminate.

The failure path

When the handoff seam throws anything else:

  • StopAsync throws, and the registered service keeps running, where upstream's stop terminates it.
  • EnsureAsync's version-mismatch replacement throws out of the election, and the old service keeps running, where upstream's ensure goes on probing.

An example is an I/O failure that the seam does not map to OpenCodeServerException. It has not been checked whether any concrete exception type escapes the seam's mapping today. The gap is in the shape of the catch.

Decision needed

Parity widens a guarded catch. The step's catch carries a slopwatch SW003 suppression whose reason names upstream's best-effort catch, and a wider catch also meets the analyzers' general-catch rules. So it is the maintainer's call: widen to upstream's catch-all (with the caller's cancellation still propagating), or keep the narrow set and record it as a divergence.

Found in review of the handoff-mode change for StopAsync (#842), which shares this step and does not change its catch beyond the endpoint case.

Activity

  1. added this to the Next milestone on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions