Skip to content

Volatile variables: env vars that don’t invalidate exec cache - #12903

Closed
shykes wants to merge 9 commits into
mainfrom
volatile-vars
Closed

shykes wants to merge 9 commits into
mainfrom
volatile-vars

Conversation

@shykes

@shykes shykes commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor

tl;dr — New Container.withVolatileVariable lets you pass non-secret env vars (commit SHA, branch ref, CI run ID) into execs without invalidating cache and without the log redaction you get from the withSecretVariable workaround.

Fixes #12902

Today the only way to pass changing metadata into execs without busting cache is withSecretVariable with a fixed cacheKey — but these values aren't secrets, so you get unwanted redaction. withVolatileVariable fixes this: it sets a non-secret env var visible to withExec but excluded from cache identity. If an exec reruns for another reason, it sees the latest volatile values.

Volatile variables are not persisted into OCI image config, not returned by envVariable/envVariables, and not available to expand: true. This is an expert-only escape hatch — if the value actually affects the exec result, Dagger will silently serve stale cache.

Example

dag.container()
  .from("mcr.microsoft.com/playwright:v1.52.0-noble")
  .withVolatileVariable("CURRENTS_COMMIT_SHA", process.env.GITHUB_SHA!)
  .withVolatileVariable("CURRENTS_GITHUB_RUN_ID", process.env.GITHUB_RUN_ID!)
  .withExec(["pnpm", "playwright", "test"])

Schema

Full diff

extend type Container {
  """
  Set a non-secret env var for future execs without invalidating exec cache
  when only its value changes. Expert-only: if the value affects exec results,
  stale cache may be reused.
  """
  withVolatileVariable(
    """Name of the volatile variable (e.g., "CI_RUN_ID")."""
    name: String!
    """Value of the volatile variable."""
    value: String!
  ): Container!

  """Remove a volatile environment variable from future execs."""
  withoutVolatileVariable(
    """The name of the volatile variable (e.g., "CI_RUN_ID")."""
    name: String!
  ): Container!
}

Internals

The dagql cache layer gains support for "dynamic inputs" — call arguments whose raw values are rewritten out of cache identity but whose session-bound handles are still propagated and validated on cache hits.

@shykes
shykes force-pushed the volatile-vars branch 2 times, most recently from 5e6f091 to b99bf41 Compare April 3, 2026 23:49
@shykes
shykes marked this pull request as ready for review April 4, 2026 00:14
@shykes
shykes requested review from a team as code owners April 4, 2026 00:14
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@shykes

shykes commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

Now that egraph is merged, we can rebase this and hopefully get it merged too!

@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this May 10, 2026
@shykes shykes removed the kind/stale label May 11, 2026
@shykes shykes reopened this May 11, 2026
@shykes
shykes force-pushed the volatile-vars branch 2 times, most recently from 6f79f23 to 1c35210 Compare May 13, 2026 16:14
@shykes

shykes commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

This has been adapted to theseus. PTAL 🙏

Handle both scp-style and ssh:// GitHub remotes when the version module fetches tags inside alpine/git.

This keeps tag lookup working for worktrees whose origin uses an SSH URL.

Signed-off-by: Solomon Hykes <[email protected]>
shykes added 8 commits May 22, 2026 06:09
Add a helper for deriving the digest a call would have with a different immediate receiver digest.

Volatile exec cache keys use this to normalize receiver history without changing argument or module identity.

Signed-off-by: Solomon Hykes <[email protected]>
Allow dynamic-input callers to transform a broad equivalent cache hit into a detached result for the current request.

The cache publishes the transformed result under the exact request instead of teaching the exact request identity to the broad shared hit.

Signed-off-by: Solomon Hykes <[email protected]>
Cover the cache contract used by volatile-style dynamic inputs: rewrite raw values out of call identity, propagate required session-resource handles, allow sessions with the bound handle to hit cache, and reject unbound sessions.

Signed-off-by: Solomon Hykes <[email protected]>
Add withVolatileVariable and withoutVolatileVariable for non-secret env values that apply only to future execs.

Volatile values stay out of persistent env introspection and image config, are rejected by Dagger-side expansion, and are ignored for exec cache identity while still being rebased onto cache-hit containers for later execs.

Signed-off-by: Solomon Hykes <[email protected]>
Regenerate GraphQL schema, SDK bindings, and generated reference output for withVolatileVariable and withoutVolatileVariable.

Signed-off-by: Solomon Hykes <[email protected]>
Explain when to use volatile variables, how they differ from persistent env and secrets, and why they are an expert-only cache escape hatch.

Signed-off-by: Solomon Hykes <[email protected]>
Reformat persistedContainerExecLazy struct tags to satisfy gofmt and
replace the inlined container-cloning block in withExec with a call to
the existing cloneContainerForSchemaChild helper.

Signed-off-by: Solomon Hykes <[email protected]>
Add two cache-level tests:
- concurrent sessions with divergent volatile values resolve their own
  bindings independently after sharing a broad cache hit
- nested volatile + non-volatile exec chain: changing only the volatile
  value reuses the volatile exec cache while a changed non-volatile
  marker correctly triggers a miss on the child

Scope the dynamic-input / CacheHitTransform mechanism in cache_egraph.go
to clarify that volatile variables are currently the only consumer.

Signed-off-by: Solomon Hykes <[email protected]>
@alexcb alexcb mentioned this pull request May 26, 2026
@alexcb

alexcb commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

merged via #13223

@alexcb alexcb closed this Jun 2, 2026
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.

Volatile variables: env vars that don’t invalidate exec cache

2 participants