Skip to content

Second to last step is not cached #8955

Closed

Description

@marcosnils

Problem

Edit: check my last comment below: #8955. Seems like the original issue can't be reproduced anymore verbatim. However, there seems to be some other variations that still show a similar cache invalidation behavior.

I have the following pipeline:

func (m *Test) Test() *dagger.Container {
	return dag.Container().From("alpine").
		WithExec([]string{"sleep", "5"})
}

If I run that multiple times, I'll get a cached output as expected. Now, the moment that I add another exec after the last one, for some reason, the second to last exec gets re-executed and not computed from the cache.

i.e:

// Returns a container that echoes whatever string argument is provided
func (m *Test) Test() *dagger.Container {
	return dag.Container().From("alpine").
		WithExec([]string{"sleep", "5"}).
		WithExec([]string{"sleep", "2"})
}

if I run this, the sleep 5 exec will get re-executed.

cc @jedevc @sipsma

Activity

  1. added
    kind/bug
    on Dec 3, 2024
  2. marcosnils commented on Jan 28, 2025

    @marcosnils
    ContributorAuthor

    👋 I can't seem to repro the above issue anymore. However, there's a new variation of this issue which manifested after a user reported a cache invalidation confusion here: https://discord.com/channels/707636530424053791/1120503349599543376/1333424111799763039

    Here's the new code to reproduce:

    // Returns a container that echoes whatever string argument is provided
    func (m *Second) Foo(context *dagger.Directory) *dagger.Container {
    	return dag.Container().From("alpine:latest").
    		WithMountedDirectory("/src", context).
    		WithExec([]string{"sleep", "5"})
    }
    
    // Returns lines that match a pattern in the files of the provided Directory
    func (m *Second) Bar(context *dagger.Directory) *dagger.Container {
    	return m.Foo(context).WithExec([]string{"sleep", "2"})
    }

    If you run dagger call foo --context . stdout and then dagger call bar --context . stdout, you'll notice that the sleep 5 will get re-executed. There's two catches which are also very odd:

    1. If you remove the withMountedDirectory, caching works as expected
    2. If you add another step below sleep 5 and run the same test as above, you'll notice that when calling bar, sleep 5 will be cached now, but the last step of the foo function won't.

    Something 🐟 is happening here.

  3. helderco commented on Jan 28, 2025

    @helderco
    Contributor

    If you remove the withMountedDirectory, caching works as expected

    This seems related to:

  4. jedevc commented on Jan 28, 2025

    @jedevc
    Contributor

    Good call, that's definitely worth making sure of.

    That said, there's still something else going on - the above shouldn't be going through the slow content cache. We should be able to look this up in the fast definition cache, so it seems likely that we're somehow generating subtly different buildkit operations between runs (and if we are, then why aren't we getting the same results)?

  5. jedevc commented on Jul 3, 2025

    @jedevc
    Contributor

    Okay, the issue is here:

    return "session:" + ls.src.Name + ":" + digestString, digestString, nil, true, nil

    Introduced in #8818 I think - when we stopped "freezing" blobs of the local source. The dagql IDs are all correct with the MakeDirectoryContentHashed function, but, this doesn't change the LLB. The session: prefix is magical - and is essentially breaking cache here.

    The solution will be part of our dagop work - when we port the code out of buildkit and into dagop, we can upload the entire directory, then snapshot it into buildkit, to get a consistent hash.

  6. jedevc commented on Jul 3, 2025

    @jedevc
  7. sipsma commented on Mar 1, 2026

    @sipsma
    Contributor

    #11856 has the fix

  8. locked and limited conversation to collaborators on Mar 24, 2026
  9. converted this issue into a discussion #12215 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

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions