Skip to content

dagql: recipe ID DAG dedupe, directive views - #13776

Merged
vito merged 3 commits into
mainfrom
llm-workspace-dagql
Jul 31, 2026
Merged

vito merged 3 commits into
mainfrom
llm-workspace-dagql

Conversation

@vito

@vito vito commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Engine internals the agent work exposed, split out so they can be reviewed as ordinary dagql changes.

Recipe ID DAG round-trip. Recipe IDs round-tripped through ResultCall frames with no memoization in either direction, so a shared sub-DAG — a base object reached via a long receiver chain and referenced by many args — was rebuilt once per path, unrolling the DAG into a tree. Resuming a long agent session, whose accumulated state is one large heavily shared ID DAG, blew up to ~10^8 frames and tens of GB and OOMed the host; fixing expansion alone surfaced the same blowup on the reconstruction side at ~2.6e8 objects, and then again in clone() at ~3.3e8 objects. All three now memoize, keyed by recipe digest, sharedResultID/frame identity, and source frame respectively. IDs are content-addressed, immutable and acyclic, and frames are frozen provenance cloned before mutation, so sharing one node per distinct sub-ID is safe.

Directive views. DirectiveSpec gains a ViewFilter, honoured at install time, so a directive introduced for a new API surface no longer appears in the schema served to older clients — matching how fields and objects are already gated.

@sipsma

sipsma commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Value-scoped session resource handles. Session resource handles propagate through every execution dependency, like secrets, which makes anything derived from a handle-carrying result private to the creating session. That's right for secrets and wrong for a resource whose content is ordinary content-addressed data. Value-scoped handles follow value embedding instead — the result itself and results attaching it via AttachDependencyResults — and persist the embedded set with the cache, so data read out of such a result stays shareable across sessions while dead-client gating still applies through the embedding edges.

@vito I haven't read the code or the details yet, but in terms of the explanation here this doesn't sound correct at all and like it might be re-inventing something that already exists.

Secret handles are given a handle derived from the content of the secret. Sessions can get cache-hits between each other even when secrets are used provided they are using secrets that are equivalent.

More generally, this is just the same caching logic of everything else in the dagql cache: any two things that have any two digests in common are considered equivalent.

  • Not specific to secrets or specific to content. You can attach arbitrary extra digests to things and if two things have overlapping sets of digests they are considered the same. Applies to any session resources and really any dagql results in general

@vito

vito commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@sipsma oh yeah I'm already dropping that (hence the note above it) - felt weird from the start and it turns out it was to support a variant of the same problem that exposing currentWorkspace to modules ran into. Basically the fix is to make it so Query.llm doesn't inherit the workspace, and make you use withWorkspace to set one that your function accepts as an argument, which fixes the caching behavior

@vito
vito force-pushed the llm-workspace-dagql branch 2 times, most recently from e9845d6 to fe37ad3 Compare July 30, 2026 21:01
@vito
vito requested review from a team as code owners July 30, 2026 21:01
@vito
vito changed the base branch from dagger-1-0-conversion to main July 30, 2026 21:04
@vito
vito force-pushed the llm-workspace-dagql branch from fe37ad3 to bab9aed Compare July 30, 2026 21:43
vito added 3 commits July 30, 2026 17:54
Recipe IDs round-tripped through ResultCall frames without memoization in
either direction, so a shared sub-DAG — a base object reached via a long
receiver chain and referenced by many args — was rebuilt once per path,
unrolling the DAG into a tree. Resuming a long agent session, whose
accumulated state is one large heavily shared ID DAG, blew up to ~10^8
frames and tens of GB, OOMing the host; fixing expansion alone surfaced
the same blowup on the reconstruction side at ~2.6e8 objects.

Thread a per-decode memo through both directions: expansion keys on
recipe digest, reconstruction on sharedResultID for by-ID refs and on
*ResultCall identity for inline frames. IDs are content-addressed,
immutable, and acyclic, and frames are frozen provenance cloned before
any mutation, so sharing one node per distinct sub-ID is safe and
collapses the tree back into a DAG.

Signed-off-by: Alex Suraci <[email protected]>
The recipe expansion and reconstruction fixes made frames store as compact
shared DAGs, but clone() still deep-copied them: a shared node reached via
N paths was re-expanded once per path, unrolling the DAG back into a tree.
Cloning one large shared frame exploded to ~3.3e8 objects and ~28GB before
the engine OOMed, captured live by the memory recorder mid-spike.

Memoize clone() by the source *ResultCall (the only shared join point) so
each distinct frame is cloned once and reused. The copy stays fully
independent of the original (distinct nodes); only sharing within one clone
is preserved, which is safe because frames are frozen provenance, never
mutated in place below the top-level spine. The now-unused Arg/Literal/Ref
clone wrappers are dropped in favor of the memo-threading cloneWith.

Signed-off-by: Alex Suraci <[email protected]>
Directives could not be gated by API version, so a directive introduced
for a new API surface would appear in the schema served to older clients.
Give DirectiveSpec a ViewFilter and honour it when installing, matching
how fields and objects are already gated.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the llm-workspace-dagql branch from bab9aed to 6030fc3 Compare July 30, 2026 21:57
@vito vito changed the title dagql: recipe ID DAG dedupe, directive views, structural args dagql: recipe ID DAG dedupe, directive views Jul 30, 2026
@vito
vito requested review from grouville and sipsma July 31, 2026 16:59
@vito
vito merged commit 0205ad1 into main Jul 31, 2026
87 checks passed
@vito
vito deleted the llm-workspace-dagql branch July 31, 2026 17:38
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