Skip to content

Save & load pipelines #3923

Closed
Closed

Description

@shykes

Overview

I propose adding a new feature to the Dagger API: saving & loading of pipelines.

  • Save: snapshot the state of a pipeline, encode it as text, send it to the client
  • Load: restore the state of a pipeline, decoded from text received from the client

This would be a very powerful primitive that we could use in many ways:

  • Stitching. Allows clients to "stitch" pipelines together into more complex pipelines. This is necessary since some pipelines cannot be expressed as a single GraphQL query. Note: this feature already exists, see next session
  • Shareable content. The encoded pipeline state can be shared and reused across Dagger installations. Because it's text, it's easy for users to send each other a pipeline as a text file, or even copy-paste its contents, like they would a Dockerfile.
  • Callbacks. Possibly, some API features could be built on top of the concept of a "callback": an executable pipeline, passed by the client in encoded form, to be executed by the engine in the future: for example as a secrets provider, or as an events handler, a middleware or hook, scheduled execution, etc. etc. This may or may not require changes to the existing format and call convention (arguments? inputs/outputs?)
    ** Advanced UI. Image a visual UI where you can not only visualize your DAG, but select any part of it and move them around, copy-paste their contents like you copy-paste an image, or export them to another DAG..

Relationship to existing IDs

The foundation for this feature already exists, in the form of content-addressable "IDs" in the Dagger API.

I propose that we keep this feature, but change how we think of it, and how we use it.

  • When we query the "id" of a container, directory, secret or file, we're actually saving the state of the pipeline that produces that object
  • When we lookup by "id" a container, directory, secret or file, we're actually 1) loading the state of the pipeline, and 2) asserting the type of the pipeline's output (eg. a file "id" can't be loaded into a container).

Pipeline Executable Format

To implement this feature, we need to specify a standard format to encode/decode the pipeline "code". The starting point of this format should be the current ID format. The process of formalizing the specification will probably require some clarifications, cleanup etc. This is probably a good thing.

Activity

  1. shykes commented on Nov 18, 2022

    @shykes
    ContributorAuthor
  2. sipsma commented on Nov 18, 2022

    @sipsma
    Contributor

    Many thoughts, but one immediate note is that this has significant overlap with some of the problems and possible solutions to session stickiness that @vito and I talked about previously. Specifically, see possible solution A) Pin sources in returned IDs in this issue: #3613

    This issue and that one aren't the exact same (just overlapping venn diagrams), but that other issue may have some helpful context around the general idea of making IDs more re-usable.

  3. shykes commented on May 11, 2023

    @shykes
    ContributorAuthor

    pinging @kjuulh who expressed interest in this topic today :)

  4. vito commented on Sep 11, 2023

    @vito
    Contributor

    Spent some time thinking about this and have a proposal to pick apart. There are still some loose ends and potential paths to explore, but there's enough to riff on async for now.

    I started by defining a protocol format for IDs on the basis that they're closest thing we have to "save/loadable pipelines" and we've been kicking the can down the road with regard to their structure and format. We're going to want a canonical way to serialize/deserialize these, and JSON ain't it, so I sketched out a Protobuf definition and a Cap'n'Proto equivalent. The advantage of Cap'n'Proto is that there is 0 cost to marshaling/unmarshaling, which will be handy for all those times that we want to take a digest. The disadvantage is that the generated Go code copies the ID struct all the time. (Upstream issue)

    I like to think of these IDs as "constructor-addressed content." They embed a recipe for creating content, and if the content isn't found, the recipe can be used to create it.

    The structure should be unsurprising: an ID contains the sequence of chained GraphQL field selections that created it, paired with the GraphQL return type.

    But there are some interesting twists:

    1. Each field selector can be marked as tainted if the field is not "pure" (same inputs=>same output).
      • This would be used for secrets, host directories, or any other APIs that are not reproducible.
      • Further, a selector automatically becomes tainted if any of its inputs are tainted.
      • There are some interesting paths we could take here for withExec / modules:
        • Make withExec tainted by default, but module functions pure by default, encouraging people to modularize CLIs.
        • Make withExec tainted by default, with an optional param to indicate that it's pure.
        • Add a withPureExec API.
    2. Each selector can mark itself as meta, allowing it to be removed from the ID without changing its semantics.
      • Examples of this are pipeline, withFocus, withoutFocus.
      • Each ID has an additional "canonical" form with all meta selectors recursively removed.

    Future possibilities, need more thought:

    • Allow IDs to embed the digest of the content they create so we can verify that they created the right content, or even detect IDs that are actually impure.
    • Embed the Dagger engine version in IDs for ultimate pinning. Combined with Stateless engine or stateful engine? #5484 this could be used to spin up the exact correct engine version for evaluating the ID.
    • Store IDs in a database and refer to them via RFC-6920 ni://sha-256;... URIs.
    • Technically these IDs can be used to refer to any value in the DAG, not just Objects/Nodes. Not sure what to do with that. Are these just 'lazy' refs?
      • Tentative answer: it's far simpler to have these IDs always refer to object types.
    • We can have a publishing phase where we take an ID, canonicalize it, bake in the digest, and fail if it is tainted. You can publish it in your GitHub releases, and people can verify that the exact same assets are created.
    • All kinds of fun data visualization possibilities...
    • As an alternative to Buildkit's source pinning (Replace session stickiness with source pinning #3613 / Save & load pipelines #3923 (comment)) we could allow queries like container.from("alpine") to return an ID that is actually equivalent to container.from("alpine@sha256:..."). It's a bit sneaky but I think this practice could save our butts more easily than using Buildkit's source pinning, and it's more general.
      • This would also apply to git.branch("main").tree.
    • There's a lot of overlap with the memoization functionality I was thinking about, and those twists above address the open questions I had (not vouching for the linked design, just pointing out the overlap).
    • We can tell you where exactly the 'tainted' flag comes from, which could be helpful with troubleshooting.
    • IDs can be used as generic query cache keys. For this use case they would include meta fields, since it's important to preserve things like pipeline and focus.
    • IDs can be used as a form of publishing reproducible artifacts into a registry-type thing, in a more lightweight manner than uploading the artifacts themselves. For this use case you would use the canonical representation.
  5. vito commented on Oct 13, 2023

    @vito
    Contributor

    Follow-up before I forget: one pretty neat property following above is that SDKs would be able to construct IDs client-side. This means that rather than making multiple requests to calculate IDs and then pass them in to another request, the client can compute one big DAG and send it all at once.

  6. shykes commented on Oct 13, 2023

    @shykes
    ContributorAuthor

    @vito thanks for keeping this fire going! A few questions to fan the bikeshedding flames:

    • Is pure/tainted the same concept as hermetic / non-hermetic or reproduceable/non-reproduceable? I'm trying to understand if we're dealing with one concept with fuzzy terminology, or several distinct concepts. (For the rest of this comment I will assume they are all the same concept).

    • Do we need to encode pure/tainted in the ID payload itself? It would make more sense to me if we didn't, since that information is already encoded in the Dagger API spec itself, so encoding it in the ID would be redundant. Or am I missing something?

    • Re-inventing an entire format to serialize what is essentially a graphql operation + additional metadata, seems like a slippery slope to me. I would be more reassured if we built on top of the existing GraphQL specs for encoding GraphQL documents (which by the way can contain multiple operations). Then an ID would be literally a GraphQL document inside an envelope containing additional metadata, like engine version, cached digests, etc. This clean layering seems very important to me.

  7. vito commented on Oct 14, 2023

    @vito
    Contributor

    @shykes Fun questions!

    Is pure/tainted the same concept as hermetic / non-hermetic or reproduceable/non-reproduceable?

    Same concept - sorry, I might hop around a lot based on how the sentence flows 😅

    Do we need to encode pure/tainted in the ID payload itself?

    There are cases where the same API may be tainted given one input (from("alpine")) and pure given another (from("alpine@sha256:...")), so I think it's important to include this distinction.

    Part of me also just likes having all of the relevant metadata together at one point in time.

    In the context of having clients construct IDs ahead-of-time, however, it might make things more difficult. I think there's a path forward where the server always returns "fully hydrated" IDs, so if you submit a query with a hand-constructed ID like [container, from("alpine")] as an input, the full ID you get back actually includes whatever ID was returned on the object returned by from("alpine").

    (This is also a related concept mentioned above where querying container.from("alpine") would actually return a 'pure' ID representing whatever alpine resolved to at the time, but that's orthogonal; if it returned an impure ID, you'd get that back instead.)

    Re-inventing an entire format to serialize what is essentially a graphql operation + additional metadata, seems like a slippery slope to me. I would be more reassured if we built on top of the existing GraphQL specs for encoding GraphQL documents (which by the way can contain multiple operations). Then an ID would be literally a GraphQL document inside an envelope containing additional metadata, like engine version, cached digests, etc. This clean layering seems very important to me.

    To my knowledge there is no prior art for what we're trying to do here, but I'd be very happy to be wrong.

    Traditionally GraphQL is used for querying "real" data that exists somewhere (or across various systems). The queries themselves are immaterial. Our case is somewhat unique in that the queries represent repeatable (assuming hermetic) transformations applied to immutable objects, giving the queries a whole new use case described by this issue. (The "transformations applied to immutable objects" phrasology is lifted from a chat with @sipsma.)

    Further, I think it's important to have a standard canonical representation for cases like this where the data encoding is a critical component of caching. GraphQL documents, much like JSON, don't have a canonical representation. Overloading them could lead to awkward footguns like relying on presence/absence of whitespace and the ordering of fields (which some language APIs might not let you control). @jedevc also had some fun rants about "3-space-indented JSON" ending up as a de-facto standard somewhere in Docker/OCI. 😱 I remember being bitten by something similar in the past where I was disappointed to realize that the way that I marshalled a manifest JSON really mattered to the digests that come out.

    So considering we plan to use these IDs as cache keys, I think we should care a whole lot about the format, and considering Cap'n'Proto makes calculating digests super cheap, just hit 1.0 recently, and already has bindings in most popular languages, it seems like the ideal choice to me atm. (Also just to note: the language bindings are only important if you want to do client-side ID construction.)

    which by the way can contain multiple operations

    This part in particular is an anti-feature at least as far as IDs are concerned because they need to identify a single object. If we were to use GraphQL documents for IDs we would likely need this to be a validation error. IDs as specified above can still contain multiple operations via their inputs, they just have to produce a single object in the end.

  8. locked and limited conversation to collaborators on Mar 24, 2026
  9. converted this issue into a discussion #12532 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions