Repository navigation
dagql: persist only complete cache results - #13936
Merged
Merged
Conversation
This was referenced Aug 20, 2026
sipsma
force-pushed
the
sipsma/remote-cache-track2-publication-boundary
branch
from
August 21, 2026 00:04
aff50cc to
f76917b
Compare
This was referenced Aug 24, 2026
vito
approved these changes
Aug 26, 2026
Base automatically changed from
sipsma/remote-cache-track1-session-edges
to
main
August 26, 2026 04:30
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
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
force-pushed
the
sipsma/remote-cache-track2-publication-boundary
branch
from
August 26, 2026 04:30
fe970fe to
645bf02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
MakeResultUnpruneablereports an explicit error for an already-collected result.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, andlost_cancelare green configurations.flush_closureis a new green configuration.poisoned_adoptionis 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 violatesNoRetainedPoisonedEntry.NoRetainedPoisonedEntryandNoErroredLookupSelectionare additionally checked inflush_closure,poisoned_restart, androllback, covering their distinct attachment-failure interleavings.flush_roundtripnow checks referential integrity.flush_inflightandflush_drainedremain 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 vetguard that call.Validation
go test ./dagql -count=1andgo test ./engine/server -count=1go test -race ./dagql -run ... -count=1covering the publication-boundary, flush-closure, lost-cancel, refused-final-waiter, adoption, and canonical-race casesgo vet ./dagql ./engine/server— the two formerdagql/cache.golost-cancel diagnostics are gone; only the pre-existingengine/server/session_attachables.godiagnostic remainsdagger check tla-check:cache-lifecycle— every configured expected outcome matchedpoisoned_adoption— clean; the weakened-selector run violatesNoRetainedPoisonedEntryas expectedgofmtandgit diff --checkStack
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, notmain.