Repository navigation
fix(sdk/csharp): client session start, request timeout and error handling - #14
Merged
pjmagee merged 4 commits intoNov 16, 2026
Conversation
HttpClient cancels a request after 100 seconds by default. One GraphQL query can wait much longer than that, for a long exec or for a service to start, and then failed with a TaskCanceledException although the engine was still working. The client now has no request timeout; a caller bounds a call with its CancellationToken. Signed-off-by: Dominik Niebuhr <[email protected]>
- Control characters in a string argument were written into the query unescaped, which the engine rejects. They are now escaped as \uXXXX. - Integer arguments were formatted with the current culture. - An error whose path contains a list index could not be deserialized, because the path was typed as a list of strings. The original error was lost behind a JsonException. - A failed HTTP request with a body that is not JSON threw a JsonException. It now throws a DaggerException with the status code and the body. Signed-off-by: Dominik Niebuhr <[email protected]>
This was referenced Nov 16, 2026
dominik-niebuhr
force-pushed
the
csharp/client-session-and-fixes
branch
2 times, most recently
from
November 16, 2026 09:39
082506c to
1d7937d
Compare
The client only worked under `dagger run` or inside a Dagger container, where DAGGER_SESSION_PORT and DAGGER_SESSION_TOKEN are set. Anywhere else it threw, so `dotnet run`, `dotnet test` and the test runner of an IDE needed a wrapper. The READMEs already promised that a compatible CLI is downloaded and run automatically; this adds the code for it, following sdk/go/engineconn: 1. A provided session is used as before. A port without a token is an error instead of a reason to start a second session. 2. _EXPERIMENTAL_DAGGER_CLI_BIN names the CLI to run. 3. Otherwise the CLI release the SDK is built for (CliVersion) is downloaded from dl.dagger.io into the user's cache directory, checked against the published checksum, and CLIs of other versions are removed from the cache. 4. When that release is not published, as for a development build, `dagger` from the PATH is used with a warning. The CLI is started as `dagger session` with the SDK labels and the announced version. Like the Go SDK, the client waits up to five minutes for the session to be reported and, on dispose or process exit, up to five minutes for the CLI to end after its input is closed. Client.Dag no longer caches a failed connection attempt: the next access tries again, which matters now that connecting can involve a download and an engine start. CliVersion is pinned to the version in internal/version/VERSION and has to be bumped with it, like the version files of the other SDKs. Signed-off-by: Dominik Niebuhr <[email protected]>
An xUnit test project that starts PostgreSQL as a Dagger service from a test fixture and reaches it through Host.tunnel. The same `dotnet test` works on a developer machine, under `dagger run` and inside a Dagger container. Signed-off-by: Dominik Niebuhr <[email protected]>
dominik-niebuhr
force-pushed
the
csharp/client-session-and-fixes
branch
from
November 16, 2026 12:30
1d7937d to
114e03e
Compare
Owner
|
Merged @dominik-niebuhr, thank you! will test on windows later. |
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.
Follow-up to my comment on dagger#15187: fixes for the client-library side, as four commits you can take together or cherry-pick one by one. All of it is under
sdk/csharp.1.
fix: remove the 100 s request timeout (GraphQLClient.cs)HttpClientcancels a request after 100 seconds by default, so a single query that waits for a long exec or a service start failed withTaskCanceledExceptionwhile the engine was still working. The client now has no request timeout; a caller bounds a call with itsCancellationToken.2.
fix: query values and error responses (Types.cs,GraphQLResponse.cs,QueryExecutor.cs)Found while reading the hand-written client code:
\uXXXX).pathcontains a list index could not be deserialized (List<string>), which hid the real error behind aJsonException.JsonException; it now throws aDaggerExceptionwith the status code and body.Note: the type of the public property
GraphQLError.Pathchanges fromList<string>toList<JsonElement>, which is source-breaking for anyone who reads it.3.
feat: start a session when the environment provides none (CliSession.cs,CliDownloader.cs,CliVersion.cs,GraphQLClient.cs, READMEs)Without
DAGGER_SESSION_PORT/DAGGER_SESSION_TOKENthe client threw, sodotnet run,dotnet testand IDE test runners needed adagger runwrapper. The READMEs already promised that a compatible CLI is downloaded and run automatically (the sentence is the one from the Python README), but there was no code for it. This adds it, followingsdk/go/engineconn:_EXPERIMENTAL_DAGGER_CLI_BINnames the CLI to run.dl.dagger.iointo the user's cache directory (XDG_CACHE_HOME, else the platform default, asdagger-<version>), checked againstchecksums.txt, and CLIs of other versions are removed from the cache.daggerfrom thePATHis used with a warning. ThePATHis searched explicitly, because starting a process by name in .NET also looks next to the running program and in the current directory.The CLI is started as
dagger sessionwith the SDK labels and--version. Like the Go SDK, the client waits up to five minutes for the session to be reported and, on dispose or process exit, up to five minutes for the CLI to end after its input is closed. The client connects to127.0.0.1, where the session listens.Client.Dagno longer caches a failed connection attempt (it was aLazy<Query>, which keeps the exception for the life of the process). The next access tries again, which matters now that connecting can involve a download and an engine start.Two things for you to decide:
CliVersion.Valueis1.0.0-beta.28, the value ofinternal/version/VERSIONand of the other SDKs' version files on your base commit. It is a constant in a.csfile rather than a csproj property because the SDK sources are also compiled into modules without the csproj. It has to be bumped with releases. The other SDKs get this from a generate function per SDK in.dagger/modules/release/generate.go; there is none for C# yet, and I did not add one because it is outsidesdk/csharp. Until1.0.0-beta.28is published, every self-started session takes thePATHfallback.System.Formats.TarandSystem.IO.Compression.4.
docs: integration test example (examples/integration-test-example)An xUnit v3 project that starts PostgreSQL as a Dagger service from a test fixture and reaches it through
Host.tunnel. It runs in VSTest mode, sodotnet testworks from any directory and from the examples solution without aglobal.json. It needs commit 3 and therefore uses aProjectReference.How it was checked (engine and CLI v1.0.0-beta.27, macOS arm64)
dotnet test Dagger.SDK.Tests, nodagger runwrapper (pinned release not published, so the CLI from thePATHis used)dotnet csharpier check .insrcdagger functionsinexamples/constructor-exampleagainst the working-tree SDK, which compiles the SDK sources the way a module doesSystem.IOusing)daggeron thePATH, an empty cache and the pin set to1.0.0-beta.27WithExec(["sleep", "130"])with a self-started session (on an earlier revision)dagger sessionprocess left afterwardsdotnet test, from its own directory and fromexamples/dagger run dotnet test(on an earlier revision)dotnet testinside a Dagger container (mcr.microsoft.com/dotnet/sdk:10.0)withExecin the traceNot checked: Windows and Linux hosts. The download tests build a zip or a tar.gz depending on the platform and need no network, so they should run on Windows; the
CliSessionTestcases that use a shell script as a stand-in CLI report inconclusive there. The Windows cache path (%LOCALAPPDATA%\cache\dagger, as in the Go SDK) and the zip extraction have not run on a real Windows machine. Yourcsharp-client-devchecks against a dev engine have not run either.🤖 Posted by Claude on behalf of Dominik · Claude Code 2.1.325 · claude-fable-5-2