Repository navigation
dagql ID format + digest improvements to support ID walking - #6836
Conversation
ce89536 to
699b661
Compare
vito
left a comment
There was a problem hiding this comment.
Super happy to see this, will review/write more but spent way too long on one comment already 😅
There was a problem hiding this comment.
Would prefer the protocol type to not be prefixed with Raw, but I can see how it helps with the rest of the code.
A bit of a context dump:
The protocol details will matter soon since the current plan is to have the frontend parse ID protobuf payloads sent over in Otel span attributes. We tried to avoid a frontend Protobuf dependency, but it's very awkward to translate arguments in particular into span attributes. We're already incentivized to have a stable ID format (#3923), and JS/TS should be good at protobuf anyway, so 🤷♂️ maybe it's fine?
Streaming the protobufs over will be 1000x better with this PR though: now we can just send infividual Fields over the wire, one per span, and have them all go into one big RawID client side, which is really 🔥😎👨🍳🤌💋
In the interest of getting this protocol stable more quickly, I'm siezing an opportunity here for some bikeshedding 😁
While we're changing names, hopefully we can find a better one than "ID." @aluzzardi and I found it too confusing while mocking up the Cloud API, and we landed on "Call" which I still like, since each of these things (currently Fields) corresponds to a function call in our new terminology.
So, building on Call, I dunno, "Chain?" (a...chain of function calls)
| message RawID { | |
| message Fields { | |
| message Chain { | |
| message Call { |
"Thunk?" (an unevaluated 0-arity function; IDs are like serializable thunks)
| message RawID { | |
| message Fields { | |
| message Thunk { | |
| message Call { |
Punt on it and just make "Call" the hero with a boring name for its wrapper?
| message RawID { | |
| message Fields { | |
| message Envelope { | |
| message Call { |
"Scope"?
| message RawID { | |
| message Fields { | |
| message Scope { | |
| message Call { |
I yield the floor 🙏
There was a problem hiding this comment.
Yeah Call SGTM.
For the "outer" type, I actually think DAG (or Dag, etc.) would be technically accurate (besides being on brand and all that 😁). It's more than a Chain because it stores the IDs not only for the chain of bases, it also has the IDs for any args of type ID, the ID of modules, etc. Each of the current *IDDigest fields in the types are the edges and the current RawID_Field type is the vertex type.
So something like:
message DAG {
message Call {
// The digest of the call that the field selection will be evaluated against.
string baseCallDigest = 1;
// ...
// A unique digest of this Call
string digest = 9;
}
// The digest of the Call for the "root" of the DAG. All other Calls
// in this message are referenced by this one via their base, args or module.
string rootCallDigest = 9;
// Map of Call digests to the Call they represent. This structure
// allows us to deduplicate occurrences of the same Call in the DAG.
map<string, Call> callsByDigest = 10;
}
message CallModule {
// The digest of the Call that provides the module.
string callDigest = 1;
// ...
}
message CallArgument {
string name = 1;
CallLiteral value = 2;
}
// A value passed to an argument or contained in a list.
message CallLiteral {
oneof value {
string callDigest = 1;
// ...
}
}WDYT?
There was a problem hiding this comment.
I'm good with that in principle - I almost recommended Graph/DAG but was afraid we'd be tempted to go back to Vertex 😂 - since mixing Graph and Functional terminology felt a little awkward. But maybe it's fine. I definitely see the upside of aligning with DAGger/DAGql. Though I think protobuf has strong opinions that might force it to be Dag instead of DAG.
Aside from that, think I'd prefer to just keep a flat set of types without prefixing or nesting them, just to leave the door open for other shapes/configurations/reuse. I think nesting Call under DAG will force its generated name to be Dag_Call, implying it's only ever used in the context of a DAG, which is true to some extent, but I mentioned earlier that we might be able to send individual Calls over OTel instead of a full DAG (though even in that case they would end up in a DAG eventually).
Same goes for the other types - they should probably just be Argument, Literal, Module. The CallArgument type is actually also used to represent object fields, so maybe it could even have a more generic name like NamedLiteral, but eh, Argument is clearer for the 99% case. If those prefixes are to avoid name clashes with the types used in by code, maybe we should just move the protobuf generated types into something like callpbv1?
There was a problem hiding this comment.
Aside from that, think I'd prefer to just keep a flat set of types without prefixing or nesting them, just to leave the door open for other shapes/configurations/reuse.
Yeah makes sense 👍
If those prefixes are to avoid name clashes with the types used in by code, maybe we should just move the protobuf generated types into something like callpbv1?
Also SGTM, especially in the context of this being used in a wider context by the frontend, etc.
Will make these updates.
There was a problem hiding this comment.
@vito pushed that here: 87af4a1
dagql/call/callpbv1has the proto codegendagql/callhas all the wrappers around those types
I ended up leaving the wrapper type around callpbv1.DAG+callpbv1.Call named ID. Partially because the way its used abstracts over those two types, so neither DAG or Call really fit. And partially because renaming that low-level ID type to e.g. Call ended making a lot of the consuming code super awkward in terms of names.
So I guess the idea is that these wrapper types are specific to the dagql/engine use case and thus ID ends up being a clearer name. All of that is in a separate package from the pb though, so other future consumers won't be impacted.
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
|
@vito I did a double check around CLI performance since it no longer has that global cache of ID digests (not needed anymore). The RSS+cpu usage looks to be about the same when compared with I suspect that improvements might become noticeable with particularly complicated function calls, specifically those that previously resulted in IDs growing huge due to repeated serialization of the same ID across the DAG. But the main reason the performance is about the same seems to be that the performance bottlenecks in the CLI lie elsewhere, specifically in Addressing that is way out of scope, so leaving as is. |
|
@sipsma That makes sense. It's too bad we don't have an offhand example for huge IDs, but it seems like an obvious theoretical issue. Also not surprised there are bottlenecks elsewhere in the TUI as it has had very little optimization done to it yet. Thanks for checking! |
vito
left a comment
There was a problem hiding this comment.
So happy to see all those error return values go away, and the janky digest cache. 🥲
There was a problem hiding this comment.
NB: on my otel branch I changed this to include the receiver, but nothing uses this at the moment, and arguably the receiver is already accessible, so maybe it's helpful to have a distinction in case we want to treat argument + receiver differently in the UI. So I'm good with leaving this as-is.
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>

This is another spin-off of #6747 (sibling to #6806) with the goal of enabling us to efficiently "walk" IDs in order to find all instances of a given type embedded in their DAG.
This is accomplished by updating the dagql ID format to store a map of
digest->fields for ID with that digest, with any other references to IDs being via that digest (whereas previously we recursively repeated every ID every time it occurred), in addition to various associated improvements to only re-calculate those digests when needed.The goal here is to support the aforementioned need for ID walking, but the hope is that this will be beneficial in terms of performance (both memory and cpu) to the engine/CLI/cloud too.
Draft pending:
referencedTypesfunc (which is what implements the logic for "give me all the instances of types implementing a given interface in the DAG of a provided ID")