Skip to content

add support for internal-only args; use for dag-op - #10586

Merged
sipsma merged 3 commits into
dagger:mainfrom
sipsma:hidden-args
Jun 16, 2025
Merged

sipsma merged 3 commits into
dagger:mainfrom
sipsma:hidden-args

Conversation

@sipsma

@sipsma sipsma commented Jun 13, 2025 •

Copy link
Copy Markdown
Contributor

Another spin-off from the persistent dagql cache work


This adds support for marking arguments to fields as internal, in which case they can only be set by internal server-side self calls and never by external clients in graphql requests. They won't show up in introspection schema requests either, so they never make it to SDKs or docs.

We have wanted this in a variety of situations for a while, but the immediate motivation here is to update DagOp to use it to distinguish the "outer" lazy implementation and the "inner" call that actually triggers the execution of the operation.

Previously we have accomplished that by plumbing things through context, but this no longer worked with the persistent dagql cache. That new caching implementation has logic such that even when digests of a call don't match, you can still get cache hits based on the inputs all being equivalent. Since inner/outer DagOp calls had the exact same inputs to the exact same field, they started incorrectly hitting cache for each other.

Now, DagOps have internal args that indicate whether the real/inner operation should be executed unlazily and other metadata previously plumbed just through the LLB op. This fixes the persistent cache use case since now there are actual inputs to the call that distinguish the outer+inner calls.

Besides the need from the persistent cache, this approach feels like a good step in that it moves just a bit more logic/data away from LLB and into "dagger-native" code (i.e. into our actual API schema).

This should be generally useful too for other situations where we have been forced to add args that really shouldn't be public in the interest of supporting internal server self calls. I pushed a second commit that uses it to hide the namespace arg from cacheVolume, which is something we've wanted for a while.


TODO:

  • I'll give a quick shot at updating the namespace arg to CacheVolume to use this too since it's one of those APIs we didn't actually want to be public

@sipsma
sipsma requested review from jedevc and vito June 13, 2025 21:49
Comment thread core/dagop.go
Comment on lines -722 to -727
// loadDagOpID loads the target ID from the server.
//
// It takes two contexts, the first to load the receiver with, the second to
// load the current call with. This *ensures* that we aren't accidentally
// applying the dagop to multiple calls - only the most recent.
func loadDagOpID(ctx context.Context, loadCtx context.Context, srv *dagql.Server, id *call.ID) (dagql.Typed, error) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedevc this was a surprise nice side effect; we can get rid of the little "dance of two contexts" here since now whether something should run in dag-op context is determined by args in the call rather than the actual context.Context

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Yes, agreed, this is a much better way of doing it 😁

@jedevc jedevc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I don't fully understand how/why this fixes the inputs thing from the pure dagql cache, but I'll take your word for it 😁

I think I can use this in the context of #10457 for the execution metadata? Maybe? Although it's a bit of a pain, since that whole struct caches kinda weirdly (by design).

Regardless, this is much neater than the context juggling we were hacking around with before.

Comment thread core/schema/cache.go
type cacheArgs struct {
Key string
Namespace string `default:""`
Namespace string `internal:"true" default:""`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably worth adding a changelog for 😢

Yeah, it was always designed as an internal arg, but I think I have seen a couple cases of folks attempting to use it. No need to do any backwards compat, but should probably be in the changelog at least!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, added!

@sipsma

sipsma commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

I'll be honest, I don't fully understand how/why this fixes the inputs thing from the pure dagql cache, but I'll take your word for it 😁

@jedevc It's basically that before this change:

  1. The "outer" dagop call would look like foo(bar: "abc"), with returned result digest xxh3:123123
  2. The "inner" dagop cal would look like foo(bar: "abc"), with returned result digest xxh3:456456

The new cache logic is fancy enough to see "oh look, two calls to the same field with the exact same inputs, that's a cache hit", even when the exact return result digest doesn't match (since we handle multiple digests for a given result more robustly now).

But after this change:

  1. The "outer" dagop call would look like foo(bar: "abc", isDagOp: false), with returned result digest xxh3:123123
  2. The "inner" dagop cal would look like foo(bar: "abc", isDagOp: true), with returned result digest xxh3:456456

So it can actually see that the calls are distinct now and doesn't try to share cache for them.

@jedevc

jedevc commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Right! Thanks, that clears it up a lot 🎉

sipsma added 3 commits June 16, 2025 09:54
This adds support for marking arguments to fields as internal, in which
case they can only be set by internal server-side self calls and never
by external clients in graphql requests. They won't show up in
introspection schema requests either, so they never make it to SDKs or
docs.

We have wanted this in a variety of situations for a while, but the
immediate motivation here is to update DagOp to use it to distinguish
the "outer" lazy implementation and the "inner" call that actually
triggers the execution of the operation.

Previously we have accomplished that by plumbing things through context,
but this no longer worked with the persistent dagql cache. That new
caching implementation has logic such that even when digests of a call
don't match, you can still get cache hits based on the inputs all being
equivalent. Since inner/outer DagOp calls had the exact same inputs to
the exact same field, they started incorrectly hitting cache for each
other.

Now, DagOps have internal args that indicate whether the real/inner
operation should be executed unlazily and other metadata previously
plumbed just through the LLB op.

Besides the need from the persistent cache, this apprach feels like a
good step in that it moves just a bit more logic/data away from LLB and
into "dagger-native" code (i.e. into our actual API schema).

This should be generally useful too for other situations where we have
been forced to add args that really shouldn't be public in the interest
of supporting internal server self calls, though this commit only
updates DagOp-ified APIs for now.

Signed-off-by: Erik Sipsma <[email protected]>
We never actually wanted this to be public, but previously didn't have a
choice. Now we can mark it as internal so external clients can't set it;
only our server-side internal calls can.

Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma merged commit 4116659 into dagger:main Jun 16, 2025
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