Repository navigation
fix(hosting): keep persistent-terminal handoff failures best-effort, as upstream does - #900
Merged
Merged
Conversation
In 1.1.0 an OpenCodeServerException already let StopAsync terminate; the change is every other exception type. EnsureAsync keeps polling and carries the last replacement failure into its timeout. The caller's cancellation still ends both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StopAsyncand theEnsureAsyncversion-mismatch replacement now treat a failed persistent-terminal handoff or clear as best-effort, whatever the exception type, as the pinned client does. Before, a failure other than anOpenCodeServerExceptionendedStopAsyncbefore it terminated the old service, and endedEnsureAsyncat once. Only the caller's cancellation still ends them early.Closes #871
Upstream at the pin (
v2.3.0)stop(packages/client/src/promise/service.ts:103-112, and its Effect twin inpackages/client/src/effect/service.ts) catches any failure of the handoff or the clear, warns, and then terminates.ensurewraps the whole replacement stop in.catch(() => undefined)(promise/service.ts:84), terminate included, and polls again.What changes
ServicePtyHandoffStep.RunAsync, the stepStopAsyncand the replacement share:OpenCodeServerException or ArgumentException { ParamName: "endpoint" }.catch (Exception failure) when (failure is not OperationCanceledException || !cancellationToken.IsCancellationRequested).ServiceElection.ReplaceAsync: the same filter, in place ofcatch (OpenCodeServerException)._lastReplaceFailure) widens toException.OpenCodeServerException, whose type and message do not change.StopAsyncorEnsureAsynclinks or derives it. The only derived deadline tokens live insideServicePtyHandoff, which already turns a deadline cancellation into a swallow.SW003reason now states what the code does: every failure is caught; the SDK has no warning channel here, so the failure is dropped, where upstream warns; only the caller's cancellation propagates.ReplaceAsyncneeded no suppression. The suppression ledger is unchanged.client-runtime.mdand the connection-modes guide already describe the step as best-effort.An existing test, reversed on purpose
EnsureAsync_Should_Propagate_An_Unrelated_Handoff_Argument_Error_Without_Signallingpinned the narrow catch, which this change reverses by the maintainer's decision on #871. It becomesEnsureAsync_Should_Replace_The_Old_Service_When_Handoff_Preparation_Fails:ArgumentExceptionwithParamName"options",ArgumentExceptionwith a nullParamName, andIOException;Tests
ServiceStopperTests:StopAsync_Should_Terminate_When_Handoff_Preparation_Failsgoes from two rows to four. The rows are:IOException;OperationCanceledExceptionthat is not the caller's.A clear-path
IOExceptionrow is added as well. The terminate oracle sits in afinally, so a regression fails at that assertion.StopAsync_Should_Propagate_Caller_Cancellation_During_Handoffis unchanged.ServiceEnsurerTests:IOExceptionthat the election carries into its timeout as the inner exception;ServicePtyHandoffStepTests(new): the step's own contract. The caller's cancellation propagates with its token.IOException,OpenCodeServerException, and a cancellation that is not the caller's are swallowed on both the handoff branch and the clear branch.Mutants (each built with the analyzers on, on net10.0, net11.0 and net472):
StopAsyncit cannot be told apart, because the terminator then throws the caller's cancellation before any signal. That is why the step has its own test file.ReplaceAsyncback toOpenCodeServerException: killed by the terminate-IOExceptiontimeout test.ReplaceAsyncwith no filter: survives, and is equivalent at the public boundary. A swallowed caller cancellation surfaces again, with the caller's token, at the election's next delay or loop check. Nothing that touches the outside world runs in between: no spawn and no signal. A direct proof would need a new seam, and this change does not justify one.Follow-up
The same narrow catch exists one level down, in
ServicePtyHandoff.PrepareAsync: the ticket request, the shutdown fallback and the sidecar publish. Upstream catches everything there too. That decision is recorded as #895, and this PR leaves it alone.Verification
4b840811(masterc99a58a8), on Linux, net10.0 and net11.0, SDK11.0.100, Bun 1.4.4 at the pin: every step passed.verify-clones0 new.OpenCode.Sdk.Tools.TestsexceptNativeAot: 2,819.OpenCode.Sdk.Tests: 4,261 on each target framework.ServiceElectionpass: 9 on each.38b6d7e8(master0bb25bc4): GATE PASS.OpenCode.Sdk.Tests4,249 / 4,249 / 4,241 on net10.0 / net11.0 / net472;PersistentPtys→Pty) and the persistent-terminal shutdown (feat(hosting): discover the background service and shut its persistent terminals down in one call (#848) #898).ServiceStopperTestsconflicted: this change's try/finally around a stop call that refactor: align the stop option's Pty name and mode type with upstream #897 renamed. It keeps the try/finally, with the new names.