Repository navigation
fix(hosting): the handoff preparation's inner steps are best-effort (#895) - #905
Merged
Merged
Conversation
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.
The persistent-terminal handoff preparation now treats a failure of each of its three inner steps as best-effort, whatever the exception type, as the pinned client's
preparedoes: the ticket request, the terminal-shutdown fallback and the sidecar publish. Only the caller's cancellation still ends the preparation.Closes #895
Upstream at the pin (
v2.3.0)prepareinpackages/client/src/pty-handoff.ts:.catch(async (cause) => { ... })takes any failure, re-reads the sidecar for a concurrent preparation, warns, and otherwise shuts the terminals down and returnsnull;.catch(() => {});.catch((cause) => console.warn(...)).What changes
All in
ServicePtyHandoff. Each step's catch becomescatch (Exception failure) when (failure is not OperationCanceledException || !cancellationToken.IsCancellationRequested), the form the outer step took in the earlier best-effort change (#871):PrepareAsync, the ticket request: wasOpenCodeException or OperationCanceledException or ArgumentException { ParamName: "endpoint" }. Any failure now goes to the concurrent-preparation check and the shutdown fallback.ShutdownAsync, the shutdown fallback: the same narrow set before. A failed shutdown no longer skips the null-sidecar publish.TryPublishAsync, the publish: wasOpenCodeServerException.FailureClassification.CallerCancellation, is unchanged. Every filter receivesPrepareAsync's own token; the request and shutdown deadlines are linked tokens that reach only the operations, so a deadline expiry is swallowed, as upstream'sAbortSignal.timeoutrejection is.What a consumer sees:
StopAsyncwithPty = Handoffand theEnsureAsyncreplacement already continued after a failed preparation (#871). Now, after a ticket request fails with an exception other than anOpenCodeException, the SDK still asks the old service to shut its persistent terminals down and publishes the empty handoff sidecar, as opencode's CLI does.Suppressions and documentation
SW003reasons now state what the code beside them does:ShutdownAsync: upstream drops a failed shutdown with.catch(() => {}), and the SDK drops it silently as upstream does; only the caller's cancellation propagates, and a null sidecar is published next.TryPublishAsync: upstream catches every publish failure and only warns; the SDK has no warning channel here, so the failure is dropped.PrepareAsync's catch, where the drop happens. No tool asked for a suppression there.TryPublishAsync's summary now says only the caller's cancellation fails the preparation.client-runtime.mdalready described the preparation as best-effort, with only the caller's cancellation propagating. The code now matches that text.An existing test, reversed on purpose
PrepareAsync_Should_Propagate_An_Unrelated_Shutdown_Argument_Errorpinned the narrow shutdown catch, which this change reverses by the maintainer's decision on #895. It becomesPrepareAsync_Should_Swallow_A_Failed_Shutdown_Fallback:ArgumentExceptionwithParamName"options", and anIOException;Tests
ServicePtyHandoffTestsgrew past the repository's file-size limit, so the best-effort proofs moved to a newServicePtyHandoffBestEffortTests, and the shared helpers became members ofServicePtyHandoffScenario. The moved tests are unchanged apart from the helper references; nothing was dropped.IOException: the preparation takes the concurrent check, then the shutdown, then the null sidecar;IOExceptionor anArgumentException: the preparation completes without a sidecar;ServicePtyHandoffCancellationTestsalready proves this for the ticket and shutdown steps.OpenCodeException: the pipeline maps transport failures, the ticket adapter maps JSON failures, and the onlyArgumentExceptionthe pipeline throws was already admitted. The test therefore makes the injected clock's first timer creation, the request deadline, throw anIOException. An independent reader traced the call order and judged this a fair proof. The test aims at a recording loopback server and asserts it received no request, so it can never reach a real service.Mutants (each built with the analyzers on, on net10.0, net11.0 and net472):
IOExceptionticket row fails at "Expected to not throw any exception".IOExceptionrow fails at "Expected to not throw any exception".OpenCodeServerException: killed. The publish row'sArgumentExceptionfails at "Expected to not throw any exception".Review
An independent reader reviewed the change against
preparestep by step, and every finding but two was fixed. Not changed:trueis equivalent.Verification
bf641755(master422c45ad), on Windows, on net10.0, net11.0 and net472: every step passed.verify-clones0 new.OpenCode.Sdk.Tools.TestsexceptNativeAot: 2,819.03238e37(feat(events)!: one shared event feed per client (2.0.0) #902) was clean. It overlaps this change only inCHANGELOG.md.b1c32308(master03238e37), on Linux, net10.0 and net11.0, SDK11.0.100, Bun 1.4.4 at the pin: every step passed.verify-clones0 new.--help, andgenerate --verify: current.OpenCode.Sdk.Tools.TestsexceptNativeAot: 2,823.OpenCode.Sdk.Tests: 4,369 on each target framework.ServiceElectionpass: 9 on each.