Skip to content

engine, cli: let a Dagger CLI join the session of the client that serves it - #14875

Merged
sipsma merged 4 commits into
mainfrom
sipsma/cli-joins-with-session
Oct 27, 2026
Merged

sipsma merged 4 commits into
mainfrom
sipsma/cli-joins-with-session

Conversation

@sipsma

@sipsma sipsma commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

A Dagger CLI started as a child of dagger api with-session, dagger run or dagger session was refused with connecting a Dagger CLI to the session served by `dagger run` is not supported yet (added in #14708). Those commands forwarded every request from their children to the engine as their own, so a CLI child's /init and /shutdown would have acted on the parent's client, and the child exiting would have ended the parent's whole session.

This lets such a CLI join the session as its own client, the same way a CLI inside a container exec already joins its caller's session.

  • A client that serves its children now passes a child's client metadata on to the engine in a new X-Dagger-Child-Client-Metadata header, under its own metadata, instead of overwriting it. Each hop appends, so a child of a child works too.
  • The engine registers that child as a nested client of the client that serves it. The child shares that client's session, token and host access (attachables). Its version, labels and what it loads are what it declares on each request, as for an exec's clients. Its shutdown ends only itself.
  • A client's children are closed when it closes.
  • SDK clients send no client metadata, so they are still served as the parent, unchanged.
  • The same applies to a CLI connected through dagger listen, which before this would have acted as the dagger listen client.

This matters for dagger/go#80, which runs Go module tests under dagger api with-session: a test that runs the dagger CLI as a subprocess fails there today.

How it was verified

  • TestContainer/TestNestedDaggerCLIServesChild used to expect the refusal. It now expects CLI children to work, and adds with-session cases: a CLI child, a CLI child reading host files, two CLI children in turn followed by a query from the parent's session, and a child of a child. Each case runs both in an exec that joins the caller's session and with daggerInDaggerNewSession, where with-session is the root client of its own session. All 16 cases pass. Against main, the 12 CLI-child cases fail with "not supported yet" and the other 4 pass.
  • New unit test TestClientServesChildClients.
  • golangci-lint.

…ves it

`dagger api with-session`, `dagger run` and `dagger session` refused a
Dagger CLI child: they forwarded every request to the engine as their own,
so a CLI child's shutdown would have ended their client.

A client now passes a child's client metadata on to the engine as its
child's, under its own. The engine registers that child as a nested client
of the client that serves it, as it does for a CLI in a container exec: it
shares that client's session and host access, and its shutdown ends only
itself. A client's children close when it closes.

Signed-off-by: Erik Sipsma <[email protected]>
A child's requests declare its version, labels and what it loads, which
replace its parent's. Registering the child with its parent's values made
its first request conflict with them.

Signed-off-by: Erik Sipsma <[email protected]>
Registering a child needs its parent's executable scope. A child's /init,
/shutdown and attachables requests admitted the parent as a bootstrap-only
request, which has that scope only if the parent had already sent a query.

Signed-off-by: Erik Sipsma <[email protected]>
@grouville
grouville self-requested a review October 27, 2026 07:15
@sipsma
sipsma merged commit ce2c108 into main Oct 27, 2026
92 checks passed
@sipsma
sipsma deleted the sipsma/cli-joins-with-session branch October 27, 2026 07:41
sipsma added a commit that referenced this pull request Oct 28, 2026
A command under `dagger run`, `dagger api with-session` or `dagger
session`, or in a container exec, joins that session as a nested client
(#14875), whatever session it asks for. With --detach it printed the ID
of a session that did not exist, and its work ended with the session it
ran in; --session was ignored.

Refuse both there, with an error that says why.

Signed-off-by: Erik Sipsma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants