Skip to content

Bind session-bound results to the session that made them - #15162

Closed
sipsma wants to merge 9 commits into
mainfrom
sipsma/session-bound-results
Closed

sipsma wants to merge 9 commits into
mainfrom
sipsma/session-bound-results

Conversation

@sipsma

@sipsma sipsma commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

What users see today

Two kinds of result were meant never to be reused by another session, but sometimes were:

  • A collection listing whose producer is cached per session or per call. A later dagger check could be planned from another session's items, and then fail with collection "..." does not contain key "..." in the current subset. This is the intermittent failure of TestCheckPlanningFromGitAcrossSessions/items_of_a_collection_cached_per_session_are_checked_again in CI.
  • A failed check's run. A later session could report the earlier session's failure without running the check again.

Both results only declined persistence. That kept them off disk, but their cache keys don't name the session, so another session was served them whenever something else still held them. Two things did:

  • a second session open at the same time;
  • a cache-usage pass. Garbage collection runs one when a session ends, at most once a minute, and it holds every result while it measures disk usage. A session that ended during such a pass left its results available to the next one.

The change

  • dagql.BindToSession declines persistence, and also makes the result usable only by the session that computed it. The result requires a handle that only that session holds. The same lookup filter that gates hits on secrets and sockets then refuses it to every other session, which computes its own. Results built on it inherit the requirement, and releasing the session drops the handle.
  • The listing resolver binds a listing whose collection's producer is cached per call, session or client. A failed check's run is bound. A passing run whose own call is session-scoped still only declines persistence.
  • A bound value doesn't adopt another session's live entry of the same recipe, and a session's lookup prefers its own bound value. Without this, a session whose check failed while another session's run of it passed would get the pass.
  • The binding is saved with the record, so a bound value kept as the dependency of a saved entry stays unusable after a restart.
  • A transfer leaves out a bound value and every root that depends on it, since it is no use in another cache.

Listings whose producers are cached across sessions, and passing checks, stay shared and kept as before (#15080).

Tests

  • New dagql unit tests cover: one session only; no adoption of another session's entry; still bound after a restart; never transferred.
  • Two new subtests of TestChecks/TestCheckPlanningFromGitAcrossSessions run dagger check in the test's own session, which stays open, then again in a new session. One checks a per-session collection, the other a failing check. Both fail on main and pass with this change, with no dependence on timing.

Performance

Fresh-engine dagger check -l of dagger/dagger, followed by the same listing in a new session. 15 interleaved pairs against main, on one machine:

main this change
first listing (median) 5.35 s 5.33 s
second listing (median) 0.87 s 0.93 s

The second-listing difference is within run-to-run spread: the per-pair difference has a median of +14 ms and a mean of −39 ms. The listing is still reused across sessions, and all 60 runs produced identical output.

A resolver could decline to persist its result, so it wasn't kept past the
sessions using it. But its key still didn't name the session, so while
anything else held the result, another session's lookup was served it: a
second session open at the same time, or a cache usage pass, which holds
every result while it measures disk usage, when the first session ended
during it.

BindToSession declines persistence and also makes the result usable only by
the session that computed it. The result requires a handle that only that
session holds, and the lookup filter that gates hits on session resources
refuses it to any other session, which computes its own beside it. What is
built on the result inherits the requirement. Session release drops the
handle, so nothing is served the result after that.

Signed-off-by: Erik Sipsma <[email protected]>
A listing whose collection's producer is cached per call, session or client
declined persistence, so a later session would list the items again. But
the listing's key doesn't name the session, so another session was still
served it while anything held it: one open at the same time, or the next one
when a cache usage pass held the listing past its session's end. That
session then planned its checks from items its own producer never returned,
and checking one failed with "does not contain key".

Bind such a listing to its session, so every other session lists the items
its own producer returns.

Signed-off-by: Erik Sipsma <[email protected]>
A failed check's run declined persistence so the next session runs the
check again. But its key doesn't name the session, so while anything held
the run another session was served it: one open at the same time, or the
next one when a cache usage pass held the run past its session's end. That
session reported the old failure without running the check.

Bind a failed run to its session, so every other session runs the check
again.

Signed-off-by: Erik Sipsma <[email protected]>
When a computation finished and its recipe already had a live entry, its
publication adopted that entry and dropped the new value. A value bound to
its session is that session's own outcome, though: a check that failed in
one session while another session's run of it passed would have reported
the pass.

A bound value now registers beside the live entry, not indexed, as a value
does when its session doesn't cover the entry's requirements, and its
session hits it from then on.

Signed-off-by: Erik Sipsma <[email protected]>
A bound value that registered beside another session's live entry of its
recipe was still not what its session's next lookup returned: lookup takes
the first candidate the session may use, by result number, and the other
session's older entry came first. A session whose check failed while
another's run of it passed would have got the pass on its next request.

A lookup now returns a candidate bound to the session when there is one.
Only the session holds its handle, so a bound candidate it may use is its
own. Once a usable candidate is found, unbound ones are skipped without
checking them, so lookups of results nothing binds cost what they did.

Signed-off-by: Erik Sipsma <[email protected]>
A value bound to its session can be saved, or sent to another cache, as the
dependency of an entry that is kept: a cached module function can return an
object holding a failed check, for example. Its record carried the decline
mark but not the binding, so after a restart, or in the receiving cache, the
value came back unbound and a later session was served the old failure.

The record now carries the binding. Restore, and both ways a merge installs
a record, put it back on the entry, where it names a session that holds no
handle there, so no session is served the value or what is built on it.
Dropping a stored value drops it with the value.

Signed-off-by: Erik Sipsma <[email protected]>
A merge could drop a bound value's record for an unbound entry the
receiving cache already held for its recipe, and point what was built on it
at that entry, which no binding restricts. And a cache that restored an
imported bound record cleared the binding from its envelope, so a record
it later sent from that entry went out unbound.

A bound value is no use to another cache, where its session doesn't
exist, and what is built on it shares its binding. A transfer now leaves out
every root whose closure reaches one, and a restored entry's envelope keeps
its binding.

Signed-off-by: Erik Sipsma <[email protected]>
Its signature gained the test when the Go modules moved to the per-package
build; the new subtest called it the old way.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Everything this held is carried in #15273, which brings together the engine side of the remote cache: all nine commits are there, eight with identical patches and one (core: bind a failed check's run to its session) with only its code comment reworded. Closing in favor of that pull request.

@sipsma sipsma closed this Nov 25, 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.

1 participant