From edda6d023c934ce69d526ff24801b48add41b9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20=C4=B0rgin?= Date: Mon, 16 Nov 2026 07:13:38 +0300 Subject: [PATCH 1/2] fix(generator): an internal-raw stream documents its owner's per-call options The raw event door's requestOptions XML repeated the caller-facing stream rules, but only the shared event feed opens that method, and the pipeline refuses it as a one-shot stream. An internal-raw family's raw methods are opened only by the family's hand-written owner, which decides the per-call options, so a stream operation in such a family now says that instead. Every other stream keeps its sentence. --- .../Events/Internal/EventsRawClient.cs | 2 +- .../Emission/StreamOperationEmissionTests.cs | 17 ++++++++++++++ .../Emission/OperationMethodEmitter.cs | 22 ++++++++++++++----- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs b/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs index 76cd522a5..a6f94944b 100644 --- a/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs +++ b/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs @@ -21,7 +21,7 @@ internal EventsRawClient(Pipeline pipeline) /// Subscribe to events. Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed. /// /// The request shaping the query. - /// The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan. + /// The per-call options; only the hand-written owner of this family calls this method, and it supplies them. /// The cancellation token. /// The 'IEvent' stream. /// The API returned a declared error status (declared: 400, 401); streaming API errors always throw. diff --git a/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs b/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs index c3fde3e01..5ca3d64c7 100644 --- a/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs +++ b/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs @@ -1,3 +1,4 @@ +using OpenCode.Sdk.Tools.Generator.Binding.Models; using OpenCode.Sdk.Tools.Generator.Emission; using OpenCode.Sdk.Tools.Tests.Generator.Emission.Support; using OpenCode.Sdk.Tools.Tests.Support; @@ -86,4 +87,20 @@ await Assert var diagnostics = await GeneratedSourceCompiler.CompileWithSdkCoreAsync(sources); await Assert.That(diagnostics).IsEmpty(); } + + [Test] + [Arguments(false, "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.")] + [Arguments(true, "The per-call options; only the hand-written owner of this family calls this method, and it supplies them.")] + public async Task Emit_Should_Document_Stream_Request_Options_By_Family_Emission(bool internalRaw, string expected) + { + var plan = await EmitterPlanFixture.CreateStreamPlanAsync(); + var operation = plan.Clients.SelectMany(static client => client.Operations).Single(); + + var xml = OperationMethodEmitter + .Emit(operation, internalRaw ? EmissionMode.InternalRaw : EmissionMode.Public) + .GetLeadingTrivia() + .ToFullString(); + + await Assert.That(xml).Contains($"/// {expected}"); + } } diff --git a/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs b/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs index fed441e82..e41c3c5c6 100644 --- a/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs +++ b/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs @@ -53,7 +53,7 @@ public static MethodDeclarationSyntax Emit(OperationPlan operation, EmissionMode .AddAttributeLists(ExperimentalAttributeSyntax.Emit(emission is EmissionMode.Public && !classMarked ? operation.ExperimentalDiagnostic : null)) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(EmitParameters(operation, methodParameters)))) .WithBody(SyntaxFactory.Block(statements)) - .WithLeadingTrivia(EmitDocumentation(operation, methodParameters)); + .WithLeadingTrivia(EmitDocumentation(operation, emission, methodParameters)); } /// @@ -252,7 +252,21 @@ private static ExpressionSyntax EmitRoute(OperationPlan operation) return EmissionSyntax.Invocation(member, [.. arguments]); } - private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, IReadOnlyList methodParameters) + /// + /// Describes the per-call options. An internal-raw stream is opened only by its family's + /// hand-written owner, which decides those options, so the caller-facing stream rules do not + /// describe it. + /// + private static string RequestOptionsDocumentation(OperationPlan operation, EmissionMode emission) => + (operation.Stream, emission) switch + { + (null, _) => "The per-call options.", + (_, EmissionMode.InternalRaw) => "The per-call options; only the hand-written owner of this family calls this method, and it supplies them.", + _ => "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.", + }; + + private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, EmissionMode emission, + IReadOnlyList methodParameters) { var parameters = new List(); parameters.AddRange(methodParameters.Select(static parameter => @@ -285,9 +299,7 @@ private static SyntaxTriviaList EmitDocumentation(OperationPlan operation, IRead parameters.AddRange(operation.DeclaredHeaders.Select(static header => new DocumentedParameter(header.Name, $"The '{header.WireName}' request header; omitted when null."))); - parameters.Add(new DocumentedParameter(ReservedNamePolicy.RequestOptionsParameter, operation.Stream is null - ? "The per-call options." - : "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.")); + parameters.Add(new DocumentedParameter(ReservedNamePolicy.RequestOptionsParameter, RequestOptionsDocumentation(operation, emission))); parameters.Add(new DocumentedParameter(ReservedNamePolicy.CancellationTokenParameter, "The cancellation token.")); From 29bd1b10adc71cfee64c941083587f770fbf2088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20=C4=B0rgin?= Date: Mon, 16 Nov 2026 12:51:50 +0300 Subject: [PATCH 2/2] fix(generator): the internal-raw stream sentence says only who decides (#909) The raw event door's method is never called: the shared feed opens every attempt on the stream plane with no per-call options, and the pipeline refuses the raw route. So the sentence no longer says that the owner calls the method and supplies the options; it says that the family's hand-written owner decides which apply, which holds for this door and for any later internal-raw stream. --- src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs | 2 +- .../Generator/Emission/StreamOperationEmissionTests.cs | 2 +- .../Generator/Emission/OperationMethodEmitter.cs | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs b/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs index a6f94944b..b2530be02 100644 --- a/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs +++ b/src/OpenCode.Sdk/Events/Internal/EventsRawClient.cs @@ -21,7 +21,7 @@ internal EventsRawClient(Pipeline pipeline) /// Subscribe to events. Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed. /// /// The request shaping the query. - /// The per-call options; only the hand-written owner of this family calls this method, and it supplies them. + /// The per-call options; the family's hand-written owner decides which apply. /// The cancellation token. /// The 'IEvent' stream. /// The API returned a declared error status (declared: 400, 401); streaming API errors always throw. diff --git a/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs b/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs index 5ca3d64c7..5ef48cfee 100644 --- a/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs +++ b/tests/OpenCode.Sdk.Tools.Tests/Generator/Emission/StreamOperationEmissionTests.cs @@ -90,7 +90,7 @@ await Assert [Test] [Arguments(false, "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.")] - [Arguments(true, "The per-call options; only the hand-written owner of this family calls this method, and it supplies them.")] + [Arguments(true, "The per-call options; the family's hand-written owner decides which apply.")] public async Task Emit_Should_Document_Stream_Request_Options_By_Family_Emission(bool internalRaw, string expected) { var plan = await EmitterPlanFixture.CreateStreamPlanAsync(); diff --git a/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs b/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs index e41c3c5c6..c833b6839 100644 --- a/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs +++ b/tools/OpenCode.Sdk.Tools/Generator/Emission/OperationMethodEmitter.cs @@ -253,15 +253,14 @@ private static ExpressionSyntax EmitRoute(OperationPlan operation) } /// - /// Describes the per-call options. An internal-raw stream is opened only by its family's - /// hand-written owner, which decides those options, so the caller-facing stream rules do not - /// describe it. + /// Describes the per-call options. An internal-raw stream's family has a hand-written owner that + /// decides which per-call options apply, so the caller-facing stream rules do not describe it. /// private static string RequestOptionsDocumentation(OperationPlan operation, EmissionMode emission) => (operation.Stream, emission) switch { (null, _) => "The per-call options.", - (_, EmissionMode.InternalRaw) => "The per-call options; only the hand-written owner of this family calls this method, and it supplies them.", + (_, EmissionMode.InternalRaw) => "The per-call options; the family's hand-written owner decides which apply.", _ => "The per-call options; NoThrow is refused. NetworkTimeout bounds only the opening and is refused for reconnecting streams, including Timeout.InfiniteTimeSpan.", };