Skip to content

dagql: persist only complete cache results - #13936

Merged
sipsma merged 8 commits into
mainfrom
sipsma/remote-cache-track2-publication-boundary
Aug 26, 2026
Merged

sipsma merged 8 commits into
mainfrom
sipsma/remote-cache-track2-publication-boundary

Conversation

@sipsma

@sipsma sipsma commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Persisted cache ownership could be installed before a result finished dependency attachment or persisted-payload loading. If attachment then failed, the persisted edge retained a lookup-visible result whose barrier permanently returned that error. Equivalent calls kept selecting the failed result instead of re-executing. Graceful shutdown also serialized all live results without distinguishing complete state from in-progress or failed attachment, allowing an incomplete result to look healthy after restart. Publication adoption could also select a same-class sibling whose attachment was still open and persist it before the attachment outcome was known.

This change moves persistence to the success boundary, makes shutdown persistence select only complete cache state, and restricts adoption to cleanly attached results.

Runtime changes

  • Fresh and adopted publications commit aggregate persistence intent at the final successful handoff, immediately before dropping the temporary publication ownership.
  • Persistable cache hits retain the expiry calculated at hit selection, wait for dependency attachment and payload loading to succeed, then install the persisted edge in a fresh graph-lock section.
  • Request, digest, canonical-ID, and publication-adoption candidate selection exclude results whose attachment barrier closed with an error.
  • Publication adoption additionally selects only cleanly attached canonical equivalents, falling back to the result the resolver returned. Adoption skips the attach barrier and the handoff commits the persisted edge without re-checking attachment, so an open-barrier sibling that later failed attachment would otherwise end up registered, persisted, and errored: retained until prune or restart, invisible to lookup, and excluded from the shutdown flush.
  • Persisted-edge upserts verify that the result is still registered by ID, preventing a deferred upsert from recreating ownership after collection. MakeResultUnpruneable reports an explicit error for an already-collected result.
  • Shutdown walks from persisted roots and writes only roots whose complete transitive dependency closure is registered and cleanly attached, deriving all related result, dependency, output-class, term, snapshot-link, and persisted-edge rows from that selected closure. Every serialized dependency row is asserted to stay inside the selection; import's explicit reference checks reject dangling rows at restart.
  • The operation-lease failure path now cancels its shared call context before returning.

Deliberate behavior

A hit selected while attachment is still open may wait and observe that attachment failure once. Once the barrier records the error, later equivalent lookups skip the result and re-execute. The failed hit's session ownership remains until that session releases it.

A persistable call still commits its persisted edge after successful publication when its final waiter is refused because the session was released. The edge is prunable and has no session owner.

Candidate gathering now briefly takes each candidate's attachment mutex while holding the graph lock on every lookup. These are small critical sections, but this is a new lookup hot-path lock acquisition. Persistable hits, which are uncommon, also take a second graph-lock section after attachment and payload loading succeed.

Model changes

The TLA+ model now matches the success-boundary persistence, errored-candidate filtering, and clean-adoption behavior, models publication attachment failure as its separate graph-lock and attachment-lock actions, and models flush selection as clean persisted-root closure.

  • poisoned, poisoned_restart, and lost_cancel are green configurations.
  • flush_closure is a new green configuration.
  • poisoned_adoption is a new green configuration gating the adoption fix: two calls in one equivalence class plus a persistable third invocation, the minimum shape in which adoption of an open sibling is constructible. Weakening the adoption pick back to the pre-fix selector violates NoRetainedPoisonedEntry.
  • NoRetainedPoisonedEntry and NoErroredLookupSelection are additionally checked in flush_closure, poisoned_restart, and rollback, covering their distinct attachment-failure interleavings.
  • flush_roundtrip now checks referential integrity.
  • A release-enabled configuration checks that admitted persistence intent remains durable after a successful call quiesces, including final-waiter refusal.
  • flush_inflight and flush_drained remain intentionally expected-red for the separate shutdown-quiescence gap: a transient publication hold can still exist at capture time. They do not represent incomplete-result laundering.

The model removes the old lost-cancel ghost counter because the corrected local cancel has no observable persistent state after the lease-failure action. The deterministic Go test and go vet guard that call.

Validation

  • go test ./dagql -count=1 and go test ./engine/server -count=1
  • One targeted go test -race ./dagql -run ... -count=1 covering the publication-boundary, flush-closure, lost-cancel, refused-final-waiter, adoption, and canonical-race cases
  • The new adoption regression test fails when the clean-attachment filter is disabled and passes with it
  • go vet ./dagql ./engine/server — the two former dagql/cache.go lost-cancel diagnostics are gone; only the pre-existing engine/server/session_attachables.go diagnostic remains
  • dagger check tla-check:cache-lifecycle — every configured expected outcome matched
  • Direct exhaustive TLC run of poisoned_adoption — clean; the weakened-selector run violates NoRetainedPoisonedEntry as expected
  • gofmt and git diff --check

Stack

This is the second layer of a same-repository stack and depends on #13934, including its engine-lifetime-unique numeric result IDs, which the registry membership checks here rely on. Its base is therefore sipsma/remote-cache-track1-session-edges, not main.

Base automatically changed from sipsma/remote-cache-track1-session-edges to main August 26, 2026 04:30
sipsma added 8 commits August 25, 2026 21:30
TestRetireSessionIsPointerConditional hand-built a registry holding a
different session object under an ID being retired. Retirement runs once
per initialized-session teardown and the failed-initialization path never
retires, so that state cannot occur. The pointer-conditional guard in
retireSession stays as cheap defense; the test pinned nothing reachable.

Signed-off-by: Erik Sipsma <[email protected]>
The recursive call-frame and payload-envelope reference walkers re-checked
a property the flush already guarantees by construction: the snapshot is
selected as complete clean persisted-root closures, so every reference a
written row can contain is inside the selected set. Both reviewers of the
original change proved the walkers could not fire on any legitimate state;
they defended only a hypothetical future encoder bug. Their fail-closed
outcome (abort the flush, store wiped on next boot) traded a localized
failure confined to affected keys for a total wipe. The inline
dependency-row guard stays: it is the direct assertion that written dep
rows stay inside the selection.

The FlushReferentialIntegrity model invariant is unchanged; it gates the
closure walk, which remains. Its comment now credits the closure walk and
import's explicit reference checks.

Signed-off-by: Erik Sipsma <[email protected]>
Numeric result IDs are engine-lifetime unique, so registry membership is
equivalent to the previous exact-pointer comparisons in
upsertPersistedEdgeLocked and MakeResultUnpruneable. This removes the last
registry pointer-identity comparisons in dagql production code.

Signed-off-by: Erik Sipsma <[email protected]>
A persistable call whose fn returned an already-attached result could adopt
a same-class sibling whose dependency attachment was still open: candidate
gathering excludes only failed attachments, selection prefers the lowest
result ID, adoption skips the attach barrier, and the final handoff commits
the persisted edge without re-checking attachment. If the sibling's
attachment then failed, the result ended up registered, persisted, and
errored: retained until prune or restart, invisible to lookup, excluded
from the shutdown flush. The model reported exactly this state once
NoRetainedPoisonedEntry was checked in a configuration where adoption is
constructible.

The adoption pick now restricts candidates to cleanly attached results and
falls back to the returned result itself, which resolvers can only hold
cleanly attached. The errored-original fallback branch and its caller
error arms are removed: every result-returning API waits at the attach
barrier and returns errors instead of values, so no caller can present an
errored original.

The model mirrors the fix. FnComplete's reuse outcome requires a cleanly
attached result, CanonicalPick filters to cleanly attached candidates and
falls back to a collected returned result (which PubIndexReuse then
refuses, matching Go's index-time refusal), and the unreachable
PubAdoptReject action is removed. A new poisoned_adoption configuration
gates the fixed bug: two calls in one class plus a persistable third
invocation, the shape adoption needs. Weakening the pick in a scratch copy
violates NoRetainedPoisonedEntry; the fixed spec passes exhaustively.
NoRetainedPoisonedEntry and NoErroredLookupSelection are additionally
checked in flush_closure, poisoned_restart, and rollback, whose
attachment-failure interleavings they cover cheaply.

Signed-off-by: Erik Sipsma <[email protected]>
Source-map line numbers shifted after the poisoned_adoption entry was
added to the checker map.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the sipsma/remote-cache-track2-publication-boundary branch from fe970fe to 645bf02 Compare August 26, 2026 04:30
@sipsma
sipsma merged commit 07ca50a into main Aug 26, 2026
1 check passed
@sipsma
sipsma deleted the sipsma/remote-cache-track2-publication-boundary branch August 26, 2026 04:30
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