Repository navigation
Conversation
sipsma
force-pushed
the
test-ci
branch
12 times, most recently
from
April 27, 2022 22:13
6d3bcd2 to
dd5fecf
Compare
sipsma
pushed a commit
that referenced
this pull request
Oct 1, 2023
Initial version of the SDK --------- Signed-off-by: Jean-Christophe Sirot <[email protected]>
sipsma
pushed a commit
that referenced
this pull request
Oct 1, 2023
* Initial commit Signed-off-by: Jean-Christophe Sirot <[email protected]> * Initial version (#1) Initial version of the SDK --------- Signed-off-by: Jean-Christophe Sirot <[email protected]> * Clean up build process & better samples (#2) * build: clean up build update pom.xml dependency management remove unused dependencies remove unused import * build: Add maven exec plugin to run the code samples from the CLI * build: support dependency caching in github action (#3) * fix: add missing sample in the sample code demo app (#4) * feat(log): add debug log when response is contains errors. (#5) Set the log level to debug in integration tests * fix: support macos arm64 architure by cli downloader (#7) * fix: client hangs on close (#8) fix(connection): refactoring of the engine connection package Move CLIRunner and ConnectParams to a dedicated class file Replace JSON-B by JSON-P to deserialize the connection parameters Move the Dagger CLI process execution to the CLI runner (Single-responsibility principle) Fix process hanging when connection to the engine failed Improve code style Add some tests for Connection class --------- Signed-off-by: Jean-Christophe Sirot <[email protected]> * build(workflow): enable build on linux and macos (#9) macos is limited to PR builds So far windows VM does not support Linux containers Signed-off-by: Jean-Christophe Sirot <[email protected]> * build: package jar with dependencies and upload artifacts in github (#11) package jar with dependencies and upload artifact in github upload artifact only on push to main update README.md --------- Signed-off-by: Jean-Christophe Sirot <[email protected]> * Move all files into sdk/java subdir So that this can be imported into dagger/dagger repository Signed-off-by: Gerhard Lazu <[email protected]> * sdk(java): Add experimental warning to README Signed-off-by: Gerhard Lazu <[email protected]> * sdk(java): Rename LICENSE But keep as is, same as we did for other experimental SDKs. Signed-off-by: Gerhard Lazu <[email protected]> * chore: Add /sdk/java to CODEOWNERS Signed-off-by: Gerhard Lazu <[email protected]> * build: rename package name from 'org.chelonix.dagger.*' to 'io.dagger.*' Signed-off-by: Jean-Christophe Sirot <[email protected]> * build(codegen): add introspection query in the codegen plugin resources and use it when schema is not available. Inject the CLI version in the code at build time Signed-off-by: Jean-Christophe Sirot <[email protected]> * build: add linter plugin and lint current code Signed-off-by: Jean-Christophe Sirot <[email protected]> * build: set development version to 1.0.0-SNAPSHOT. Add "release" profile dedicated to deployment Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix: correctly return the dagger CLI path in codegen plugin and fix some log messages Signed-off-by: Jean-Christophe Sirot <[email protected]> * build: Add schema for 0.6.4 Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix: fix coding style for linter Signed-off-by: Jean-Christophe Sirot <[email protected]> * build: fix maven versions plugin groupId Signed-off-by: Jean-Christophe Sirot <[email protected]> * ci: add java sdk CI - add initial build worflow in internal/mage/sdk/java.go - add test & lint actions in github action worflow Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix: replace deprecated API calls in tests - Container.fs -> Container.rootfs - Container.exec -> Container.withExec Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix: Add a static 'from' method to instanciate a Scalar from a String literal Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix(doc): fix javadoc for field parameters in generated code Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix: Fix NPE when CLI download fails and log error Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix(codegen): clarify codegen plugin parameters and Dagger version in generated code Separate CLI and SDK version Use either a previously generated schema or a query a locally installed dagger CLI update the CI to generate the schema matching the used dagger CLI Signed-off-by: Jean-Christophe Sirot <[email protected]> * fix(codegen): fix sdk:java:generate goal Now the generate goal will query the dagger CLI to generate the API JSON schema and write a file A new dagger-codegen:generateSchema plugin goal has been added to the dagger-codegen maven plugin (with some code refactoring between both goals) to generate the schema. The generate schema is copied to plugin resources dir /schemas according to the engine version declared in the pom.xml file afterwards. The schema file naming has been simplifying (removing the 'v' prefix) and the existing files have been renamed accordingly Signed-off-by: Jean-Christophe Sirot <[email protected]> * feat(codegen): add schema for dagger engine 0.8.3 and 0.8.4 Signed-off-by: Jean-Christophe Sirot <[email protected]> * doc(codegen): document how to bump engine dependency Signed-off-by: Jean-Christophe Sirot <[email protected]> * Remove redundant return & go fmt Signed-off-by: Gerhard Lazu <[email protected]> * Make Java SDK workflow standalone, same as the Elixir one Leverage the re-usable _hack_make workflow. Signed-off-by: Gerhard Lazu <[email protected]> * Use same Apache 2.0 license as all other SDKs Engine & CLI use the same Apache 2.0 license. Signed-off-by: Jean-Christophe Sirot <[email protected]> --------- Signed-off-by: Jean-Christophe Sirot <[email protected]> Signed-off-by: Jean-Christophe Sirot <[email protected]> Signed-off-by: Gerhard Lazu <[email protected]> Signed-off-by: Jean-Christophe Sirot <[email protected]> Co-authored-by: Jean-Christophe Sirot <[email protected]> Co-authored-by: Jean-Christophe Sirot <[email protected]> Co-authored-by: Daniel Lavoie <[email protected]>
sipsma
pushed a commit
that referenced
this pull request
Mar 28, 2025
* force opt-in multi-object for testing one of my tests actually benefits from _undo, so let's just keep them all enabled, as this was more out of an abundance of caution Signed-off-by: Alex Suraci <[email protected]> * add evals module + test suite usage: dagger run go test Signed-off-by: Alex Suraci <[email protected]> * beef up default system prompt * do a bit of world-building * clarify immutability/state interaction * nudge it towards using tools to explore before giving up * suggest setting a variable at the end * make system prompt consistent across all models * always apply system prompt (previously OpenAI was excepted) * allow being overridden (previously Gemini didn't) Signed-off-by: Alex Suraci <[email protected]> * support running evals across models Signed-off-by: Alex Suraci <[email protected]> * DNM: add debugging Signed-off-by: Alex Suraci <[email protected]> * switch to _select_varname, list their tools * don't need _objects if we just add a tool for each var * listing tools ahead of time helps Gemini realize it needs to select tools Signed-off-by: Alex Suraci <[email protected]> * don't expand object prompt vars Signed-off-by: Alex Suraci <[email protected]> * add test-all script Signed-off-by: Alex Suraci <[email protected]> * strict builtins Signed-off-by: Alex Suraci <[email protected]> * experiment: strict schemas saw some guessing, don't want none of that Signed-off-by: Alex Suraci <[email protected]> * Revert "experiment: strict schemas" This reverts commit 63f4266. Signed-off-by: Alex Suraci <[email protected]> * wip: bots prompting bots Signed-off-by: Alex Suraci <[email protected]> * better LLM.history formatting Signed-off-by: Alex Suraci <[email protected]> * support setting a system prompt Signed-off-by: Alex Suraci <[email protected]> * Llm -> LLM, multiple attempts Signed-off-by: Alex Suraci <[email protected]> * simplify error responses Signed-off-by: Alex Suraci <[email protected]> * more liberal object lookup, helpful error response Signed-off-by: Alex Suraci <[email protected]> * reveal errored tool calls due to bad args Signed-off-by: Alex Suraci <[email protected]> * add Llm.attempt kind of silly implementation, but gets the job done Signed-off-by: Alex Suraci <[email protected]> * evals: run N attempts Signed-off-by: Alex Suraci <[email protected]> * evals: tweaks for direct calling Signed-off-by: Alex Suraci <[email protected]> * adopt new system prompt Signed-off-by: Alex Suraci <[email protected]> * handle $ var arg prefix Signed-off-by: Alex Suraci <[email protected]> * Llm.history: clean up format * tool calls were showing up as user prompts * indicate errored tools * tweak emoji usage ("laptop" doesn't read as "tool" to me) Signed-off-by: Alex Suraci <[email protected]> * core: add ToolFunc helper otherwise the selecting of arg values and typecasting is a little panic-prone Signed-off-by: Alex Suraci <[email protected]> * fixup _save arg Signed-off-by: Alex Suraci <[email protected]> * fix workspace construction Signed-off-by: Alex Suraci <[email protected]> * checkpoint: Gemini passing 19/20 evals * https://v3.dagger.cloud/dagger/traces/0194a2fd0e94f8226705da24bcf24ab6 * https://v3.dagger.cloud/dagger/traces/8fbf316db60f1fd6dfef1b53933b2904 Signed-off-by: Alex Suraci <[email protected]> * include token usage in history Signed-off-by: Alex Suraci <[email protected]> * refine model, new system prompt * always use structured responses * return {"using":"Foo#123","variable":"foo"} for Objects so LLM knows not to make redundant _use or _saveAs calls * replace _rewind with _use(id) now that we have LLM friendly IDs; _rewind seemed to get it stuck in loops now and then * don't expose 'id' field tool - the LLM always knows them without needing it * enforce that LLM env vars are Objects, don't overload it with String * not 100% sure about this but trying it out, it might make sense to generalize and allow an LLM to return _any_ type, but that gets weird with Arrays. basically: why is String special? * only prompt vars expand in prompts, the rest are left as-is so the LLM can assume they're LLM env vars instead * avoid dumping binary strings * cut long strings off at 8k Signed-off-by: Alex Suraci <[email protected]> * checkpoint: per-type selection instead of per-var * consistently use our new IDs (Container#foo) everywhere * theoretically the LLM doesn't need a concept of variables anymore, they're practically just prompt vars implicitly pre-installed in the environment, and the LLM discovers the rest from there Signed-off-by: Alex Suraci <[email protected]> * bbb/workspace: better span mechanics use Reveal on attempt span instead, which works much better anyway Signed-off-by: Alex Suraci <[email protected]> * bbb/workspace: make object IDs more prominent Signed-off-by: Alex Suraci <[email protected]> * iterate * also add a cache buster (+ Go build caching) for better deoms Signed-off-by: Alex Suraci <[email protected]> * fix cryptic function call/response LLM API errors when an LLM tried to call an unknown tool, we silently ignored it; now we error early Signed-off-by: Alex Suraci <[email protected]> * telemetry: convert Foo#1 to the actual Call arg makes `_select_Container` look much nicer Signed-off-by: Alex Suraci <[email protected]> * llm: more rigorous tool schemas * support input objects (e.g. BuildArg) and enums * error on any unsupported types so we can figure em all out * configure pattern for ID args, make explicit in description for LLMs that don't support them (Gemini) Signed-off-by: Alex Suraci <[email protected]> * nudge LLM along if it forgets to select first also, clean up a bunch of tools that I _think_ we no longer need at all. even _saveAs never provided much use since you can't predict what name it will use. doubling down on this streamlined functional approach until proven wrong. Signed-off-by: Alex Suraci <[email protected]> * clean up failed get call responses showing hashes is no longer useful Signed-off-by: Alex Suraci <[email protected]> * llm(google): avoid panic with no prompt Signed-off-by: Alex Suraci <[email protected]> * update README, regen prompts * remove tool lists from final report, too large Signed-off-by: Alex Suraci <[email protected]> * make telemetry resilient to call conversion errors Signed-off-by: Alex Suraci <[email protected]> * dagql(Int): support conversion from float64 we can't always enable json.Number ahead of time Signed-off-by: Alex Suraci <[email protected]> * llm: support traversing arrays * the telemetry is broken, but it seems to work * also switch from select_Foo to selectFoo, it just looks better Signed-off-by: Alex Suraci <[email protected]> * simplify Evaluate signature it calls it repeatedly now which is redundant, and ends up caching anyway Signed-off-by: Alex Suraci <[email protected]> * bump dagger to v0.17.1 Signed-off-by: Alex Suraci <[email protected]> * llm: only enable default prompt + tools list for Gemini We don't want to rely on a system prompt too much, because we won't have that luxury when embedded as an MCP server. So, let's treat this as a requirement as Gemini only for now, and gradually enable it as needed. Signed-off-by: Alex Suraci <[email protected]> * expose LLM.tokenUsage Signed-off-by: Alex Suraci <[email protected]> * smaller system prompt, fancy evals test pattern This prompt passed 20/20 times! I guess just tell it it's an expert and it loses its imposter syndrome? Signed-off-by: Alex Suraci <[email protected]> * string limit: 8k => 80k Signed-off-by: Alex Suraci <[email protected]> * accept number-only ID args in the spirit of "be liberal in what you accept" - some models might interpret Container#1 as Container #1 Signed-off-by: Alex Suraci <[email protected]> * LLMEnv: cleanup Signed-off-by: Alex Suraci <[email protected]> * properly implement selectFoo(id: "1") compatibility Signed-off-by: Alex Suraci <[email protected]> * regen SDKs + docs Signed-off-by: Alex Suraci <[email protected]> * rm botsbuildingbots moving to my own repo, too experimental Signed-off-by: Alex Suraci <[email protected]> * rm debugging when we bring this back, maybe let's do otel instead? Signed-off-by: Alex Suraci <[email protected]> * fix lints Signed-off-by: Alex Suraci <[email protected]> * fix nil LLM promptVars Signed-off-by: Alex Suraci <[email protected]> * update fixtures Signed-off-by: Alex Suraci <[email protected]> * fix selecting tool object results Signed-off-by: Alex Suraci <[email protected]> * fix OpenAI tool call ID + result inversion Signed-off-by: Alex Suraci <[email protected]> * LLM/TestAPILimit: just send multiple prompts model behavior seems to vary wildly at the moment - it's pretty hesitant to follow instructions, but that seems like a problem independent from the goal of this test Signed-off-by: Alex Suraci <[email protected]> * fix prompt vars not expanding Signed-off-by: Alex Suraci <[email protected]> * llm(env): add currentSelection dummy tool Explanation in comment. Without this tool gpt-4o reliably refuses to operate on the current state. The problem goes away by the mere presence of this tool, without even calling it. Signed-off-by: Alex Suraci <[email protected]> * llm: hint model when we're leaving a state so that it knows it can swap back to it, even if it was never told its ID currentState ALMOST helps with this, but not really, since it doesn't go into message history Signed-off-by: Alex Suraci <[email protected]> * appease linter Signed-off-by: Alex Suraci <[email protected]> * update fixtures Signed-off-by: Alex Suraci <[email protected]> * support dynamic variable discovery For when you can't/don't want to reference them directly in your prompt. Tested with GPT-4o and Claude 3.7 sonnet, but Gemini has trouble. Signed-off-by: Alex Suraci <[email protected]> * llm: always provide tool hints seems like more models need this than don't Signed-off-by: Alex Suraci <[email protected]> * llm: reword available bindings dont want the model to think these are the ONLY possible inputs Signed-off-by: Alex Suraci <[email protected]> * allow variables passed to ID args this is supported, and some models try it Signed-off-by: Alex Suraci <[email protected]> --------- Signed-off-by: Alex Suraci <[email protected]>
sipsma
added a commit
that referenced
this pull request
Mar 6, 2026
Problem
After the earlier object-self persistence cutover and restart test fixes, the
manual `./hack/dev` / `./hack/with-dev dagger --progress=plain call engine-dev
container with-exec --args true stdout` workflow was still not reliable.
There were two concrete classes of failures in the manual flow:
1. Restart could still go bad even after the old import wipe was reduced.
The original failure was:
- `dagql persistence import failed; wiping and cold-starting`
- `import term_result: missing result "xxh3:..."`
We traced that to background dagql prune selecting persisted closure members
and emitting tombstones for them, which left durable `term_results` rows
pointing at missing/tombstoned results on the next import.
2. Once that was mitigated, later manual restart runs still hit follow-on
object/cache failures in real module and engine-dev paths, including:
- imported results losing `originalRequestID`, which made re-export fail with
`result has nil original request ID and no persisted envelope`
- eager object reconstruction in `cache.wait` breaking typed object shells such
as `FunctionCallArgValue`
- mounted directory child decode failing with `missing persisted result key`
- eager mutable `CacheVolume` reopen failing with `... is locked: locked`
- cache-mount use sites expecting a live snapshot even though imported cache
volumes now intentionally decode as logical identities first
Solution
Keep the earlier object-self import design, then harden the real manual
workflow around it.
The main behavioral changes are:
- protect persisted closure members from automatic dagql prune tombstoning
- restore enough imported identity (`originalRequestID`) for decoded persisted
results to be re-exportable later
- make cache object reconstruction more tolerant when a typed object shell is
present but eager object wrapping would be wrong or premature
- allow persisted child object references to fall back to normal ID load when
they are intentionally not present in the imported persisted-result index
- treat imported cache volumes as logical cache identities, not eagerly reopened
mutable refs, and lazily initialize their snapshots at actual mount/exec use
sites instead
Implementation details
Dagql cache / persistence
- `dagql/cache_prune.go`
- skip `depOfPersistedResult` entries during automatic prune so persisted
closure members are not tombstoned out from under restart import.
- `dagql/cache_persistence_import.go`
- restore `originalRequestID` from persisted envelope IDs during import.
- `dagql/cache.go`
- when a completed call returns a typed object through a plain `Result[T]`,
infer `objType` from the current server only for non-list object types.
- in `cache.wait`, if eager object wrapping fails, fall back to returning the
typed result shell instead of erroring immediately.
- `dagql/cache_persistence_resolver.go`
- when persisted child object resolution misses the imported-result index,
fall back to normal `dagql.NewID[T](id).Load(...)` rather than failing.
Core object / cache volume behavior
- `core/cache.go`
- `CacheVolume.DecodePersistedObject` now restores logical cache identity and
selector only; it no longer eagerly grabs a mutable snapshot at decode time.
- `core/container.go`
- prepare cache-volume mounts before container sync so persistence prep can
stabilize cache-mounted containers.
- `WithMountedCache` now lazily initializes the cache volume snapshot if the
imported cache-volume object has not opened it yet.
- `core/container_exec.go`
- mount preparation for exec now lazily initializes cache-volume snapshots if
needed rather than treating missing snapshot handles as fatal.
- `core/persisted_object.go`
- imported child object loads can fall back to normal ID load when the
imported cache has no persisted-result-key entry for that child.
Planning / tracking
- `scratch/WHITEBOARD.md`
- added Phase 8 for the manual engine-dev workflow, including the problem
statement, checklist, and progress log covering the prune diagnosis and the
latest manual repro results.
Validation
Focused validation still passes:
- `go test ./dagql -run 'TestPersistedSelfCodec|TestCachePersistenceImport|TestCachePersistenceWorker|TestCachePersistenceCleanShutdownToggleOnClose|TestCachePersistenceWorkerEqFactTombstoneScopedByOwner|TestCachePersistenceWorkerIdempotentUpsertAndTombstone' -count=1`
- `dagger --progress=plain call engine-dev test --pkg ./core/integration --run='TestEngine/TestDiskPersistenceAcrossRestart'`
- `dagger --progress=plain call engine-dev test --pkg ./core/integration --run='TestModule/TestFunctionCacheControl'`
Manual workflow state after these changes:
- clean run #1 succeeds
- run #2 is strongly warm (`EngineDev.container` and `Container.withExec` cache)
- the old restart wipe signature is gone
- post-restart run now succeeds end-to-end for the manual workflow
Remaining caveat noted in WHITEBOARD:
- post-restart `load module` / `DaggerDev.engineDev` still do real work instead
of being fully warm, even though the workflow is now correct end-to-end.
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Jun 11, 2026
…analyzer
Adds an experimental, cheap wall-clock profiling system (wcprof) for the
engine plus an offline analyzer that finds latency bottlenecks by
counterfactual simulation. Built to systematically catch the class of
problem that CPU/memory profiles can't see: serial wall-clock taxes like
the ~300ms un-pooled CNI netns setup that used to run before every
container start while nothing else made progress.
Why not OTel
============
The existing telemetry path is unsuitable for this both in cost and in
shape: AroundFunc proto-encodes the full call DAG per span, every span is
written to per-client SQLite databases (fanned out to all parent clients),
and repeated/cache-hit calls are deliberately suppressed via
ShouldEmitTelemetry, so most calls never appear at all. Spans also only
give a tree + timestamps; they can't say *why* an op was idle mid-flight.
Design
======
The engine is unusually well-shaped for this: since evaluation became
dagql-native, every cross-operation blocking relationship flows through a
handful of choke points we own (dagql singleflight, lazy-eval waiters,
service starts, cache-volume locks, exec completion channels, the
nested-client boundary). That means the true waits-for graph can be
*recorded* at the choke points rather than inferred from span nesting.
The recipe digest is already computed for every call for cache lookup, so
op identity is free.
wcprof records three fixed-size event types into sharded in-memory
buffers with interned strings (~72B/event, default cap ~4M events,
disabled = one atomic load per hook site):
- ops: timed intervals with kind (call, call_exec, lazy, exec,
exec_phase, service_start, session_phase, internal), class
(e.g. Container.withExec, exec.setupNetwork), instance ident (recipe
digest / exec id), structural parent (via context), outcome
(hit/executed/joined/do_not_cache/...), and a work-type tag separating
engine overhead from user work (container process runtime) and
external I/O.
- waits: exact blocked-on intervals (who waited on which op or named
resource, why, from when to when), recorded by the waiter at the choke
point itself.
- links: non-blocking correlations, most importantly exec op <-> nested
client ID so module-function calls back into the API stitch under the
exec that hosts them.
Hook points in this commit:
- dagql getOrInitCall: one call op per caller (cache hits and DoNotCache
included -- deliberately recording what OTel suppresses), one shared
call_exec op per resolver execution (waiters record singleflight join
edges against it), and a publish op for result publication cost.
- dagql evaluateOne: lazy ops classed by the call that *created* the lazy
value (cost attribution) with wait edges from the triggering/joining
ops (blocking attribution) -- the two views stay separate.
- engineutil executor: per-exec op + named phase ops (setupNetwork,
setupRootfs, ..., runContainer), plus an exec.containerStart vs
exec.processRun split so engine overhead and user process time are
distinguishable.
- core container exec: cache-volume lock waits, prepareMounts /
applyOutputs phases.
- core services: service_start ops with waiter join edges (start
singleflight + health checks).
- engine server serveQuery: per-query session phases (attachables wait,
workspace load, module load, schema build, query root).
Plumbing: hidden `dagger --profile` flag -> ClientMetadata.Profile ->
engine-global recorder (also `_DAGGER_WCPROF=1`); dump+flush endpoint at
GET /debug/wcprof/dump alongside the other engine debug endpoints. The
dump is a JSON header line (string table, open ops for hang visibility)
followed by one JSON event per line.
Analyzer (cmd/wcprof-analyze, engine/wcprof/wcanalyze)
======================================================
Reconstructs the op graph (parents, waits, nested-client re-parenting),
computes self-time (duration minus waits minus child intervals), then
runs a replay-based discrete-event simulation of the recorded schedule
under counterfactual hypotheses: "class X's self-time scaled by f" for
f in {0, 0.5, 0.9}, assuming unlimited resources (never CPU-bound, v1
simplification). Classes are ranked by how much end-to-end makespan each
would actually save -- which handles critical-path shifts, singleflight
dedup (shared work counted once), and dependency chains, unlike naive
"total time per class" tables. Also reports per-class stats with outcome
histograms and duplicate-execution detection, an end-of-workload blocking
chain, dead-air gaps (uninstrumented blocking), and drift diagnostics.
How it worked in practice
=========================
Testbed: `dagger call engine-dev container sync`, cold cache, profiled
via the dev engine (hack/dev). ~223s wall, ~169k ops, ~25MB dump, zero
dropped events, ~36s to analyze.
The simulated baseline makespan is checked against the actual makespan
as a fidelity metric, and that check earned its keep: it caught three
real replay-model bugs during bring-up, found via the included
diagnostics (DriftOrigins, ExplainFinish, fallback-anchor counters):
1. Frame mixing: normalizing the first root's sim time to 0 while ops
reached through cross-tree wait targets anchored at original
timestamps inflated makespan +53%. The simulation now stays entirely
in the original trace's time frame.
2. Ident-based exec waits can resolve to the wrong exec when call
digests are shared across execs; removed in favor of the exec op
being a context-child plus the replay's implicit-join rule, which
models the dependency exactly. (Waits that ended before their
target's recorded end -- abandoned/canceled -- are also no longer
treated as joins.)
3. Fallback anchoring at recorded start times silently re-pinned chains
to original times whenever an op's finish was needed while its parent
was mid-replay, collapsing counterfactual propagation (processRun x0
"saved" 55ms instead of 41.7s). Fallbacks now anchor at parent sim
start + recorded offset.
After those fixes the baseline drift is -0.0% on every run measured
(smoke, two full builds, two synthetic chains).
Results on the testbed: the go build itself (exec.processRun, user work)
dominates at ~42-69s recoverable; the top engine-actionable class is
Host.directory (filesync) at ~4s; HTTPState._resolve has 207s of total
self-time but correctly ranks as a non-bottleneck (parallel to the
build) -- exactly the total-time != bottleneck discrimination this is
for. One real finding already: exec.setupNetwork has p50 125us but p95
1.52s (44-55s total across ~230 execs) -- a netns-pool exhaustion tail,
the same class as the original CNI problem.
Validation (known-answer test)
==============================
A file-gated injection aid (/tmp/wcprof-inject-netns-delay-ms inside the
engine container, only consulted while profiling) injects an artificial
delay in setupNetwork. On a strictly serial 10-exec chain with 300ms
injected: the analyzer ranked exec_phase:exec.setupNetwork #1 and
predicted save@0 = 3.32s; disarming the injection and re-running measured
the chain section shrink from 3.57s to 0.46s (actual recovery 3.11s,
prediction within ~7%, which also covers the organic tail it zeroes).
With the injection disarmed the class dropped out of the rankings
entirely -- no false positive. On the engine-dev build the same injection
predicted only ~2.4s saved despite ~48s wall growth: execs there start in
parallel with the build/download chains, so per-exec start taxes mostly
don't serialize in that workload (and cross-run wall comparisons are
polluted by network variance -- validate within-run via the sim, or on
serial synthetic chains).
Known v1 limitations (deliberate)
=================================
- recorder is engine-global (any profiled client enables it);
per-session scoping is future work
- lock waits are modeled as fixed delays (no release->acquire causality)
- unlimited-resources assumption; parallel self-time includes mutex
contention and scheduler queueing (e.g. egraphMu pressure shows up as
dagql.publishResult self-time -- itself a useful signal)
- leaf I/O internals (git fetch, image pull, filesync) are not yet
sub-instrumented; they appear as self-time of their calling op, and
the unexplained-self-time/dead-air reports are the guide for where to
hook next
Usage
=====
./hack/dev
./hack/with-dev ./bin/dagger --profile call engine-dev container sync
curl -s http://localhost:6060/debug/wcprof/dump > /tmp/wcprof.dump
go run ./cmd/wcprof-analyze /tmp/wcprof.dump
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
that referenced
this pull request
Jun 16, 2026
…analyzer
Adds an experimental, cheap wall-clock profiling system (wcprof) for the
engine plus an offline analyzer that finds latency bottlenecks by
counterfactual simulation. Built to systematically catch the class of
problem that CPU/memory profiles can't see: serial wall-clock taxes like
the ~300ms un-pooled CNI netns setup that used to run before every
container start while nothing else made progress.
Why not OTel
============
The existing telemetry path is unsuitable for this both in cost and in
shape: AroundFunc proto-encodes the full call DAG per span, every span is
written to per-client SQLite databases (fanned out to all parent clients),
and repeated/cache-hit calls are deliberately suppressed via
ShouldEmitTelemetry, so most calls never appear at all. Spans also only
give a tree + timestamps; they can't say *why* an op was idle mid-flight.
Design
======
The engine is unusually well-shaped for this: since evaluation became
dagql-native, every cross-operation blocking relationship flows through a
handful of choke points we own (dagql singleflight, lazy-eval waiters,
service starts, cache-volume locks, exec completion channels, the
nested-client boundary). That means the true waits-for graph can be
*recorded* at the choke points rather than inferred from span nesting.
The recipe digest is already computed for every call for cache lookup, so
op identity is free.
wcprof records three fixed-size event types into sharded in-memory
buffers with interned strings (~72B/event, default cap ~4M events,
disabled = one atomic load per hook site):
- ops: timed intervals with kind (call, call_exec, lazy, exec,
exec_phase, service_start, session_phase, internal), class
(e.g. Container.withExec, exec.setupNetwork), instance ident (recipe
digest / exec id), structural parent (via context), outcome
(hit/executed/joined/do_not_cache/...), and a work-type tag separating
engine overhead from user work (container process runtime) and
external I/O.
- waits: exact blocked-on intervals (who waited on which op or named
resource, why, from when to when), recorded by the waiter at the choke
point itself.
- links: non-blocking correlations, most importantly exec op <-> nested
client ID so module-function calls back into the API stitch under the
exec that hosts them.
Hook points in this commit:
- dagql getOrInitCall: one call op per caller (cache hits and DoNotCache
included -- deliberately recording what OTel suppresses), one shared
call_exec op per resolver execution (waiters record singleflight join
edges against it), and a publish op for result publication cost.
- dagql evaluateOne: lazy ops classed by the call that *created* the lazy
value (cost attribution) with wait edges from the triggering/joining
ops (blocking attribution) -- the two views stay separate.
- engineutil executor: per-exec op + named phase ops (setupNetwork,
setupRootfs, ..., runContainer), plus an exec.containerStart vs
exec.processRun split so engine overhead and user process time are
distinguishable.
- core container exec: cache-volume lock waits, prepareMounts /
applyOutputs phases.
- core services: service_start ops with waiter join edges (start
singleflight + health checks).
- engine server serveQuery: per-query session phases (attachables wait,
workspace load, module load, schema build, query root).
Plumbing: hidden `dagger --profile` flag -> ClientMetadata.Profile ->
engine-global recorder (also `_DAGGER_WCPROF=1`); dump+flush endpoint at
GET /debug/wcprof/dump alongside the other engine debug endpoints. The
dump is a JSON header line (string table, open ops for hang visibility)
followed by one JSON event per line.
Analyzer (cmd/wcprof-analyze, engine/wcprof/wcanalyze)
======================================================
Reconstructs the op graph (parents, waits, nested-client re-parenting),
computes self-time (duration minus waits minus child intervals), then
runs a replay-based discrete-event simulation of the recorded schedule
under counterfactual hypotheses: "class X's self-time scaled by f" for
f in {0, 0.5, 0.9}, assuming unlimited resources (never CPU-bound, v1
simplification). Classes are ranked by how much end-to-end makespan each
would actually save -- which handles critical-path shifts, singleflight
dedup (shared work counted once), and dependency chains, unlike naive
"total time per class" tables. Also reports per-class stats with outcome
histograms and duplicate-execution detection, an end-of-workload blocking
chain, dead-air gaps (uninstrumented blocking), and drift diagnostics.
How it worked in practice
=========================
Testbed: `dagger call engine-dev container sync`, cold cache, profiled
via the dev engine (hack/dev). ~223s wall, ~169k ops, ~25MB dump, zero
dropped events, ~36s to analyze.
The simulated baseline makespan is checked against the actual makespan
as a fidelity metric, and that check earned its keep: it caught three
real replay-model bugs during bring-up, found via the included
diagnostics (DriftOrigins, ExplainFinish, fallback-anchor counters):
1. Frame mixing: normalizing the first root's sim time to 0 while ops
reached through cross-tree wait targets anchored at original
timestamps inflated makespan +53%. The simulation now stays entirely
in the original trace's time frame.
2. Ident-based exec waits can resolve to the wrong exec when call
digests are shared across execs; removed in favor of the exec op
being a context-child plus the replay's implicit-join rule, which
models the dependency exactly. (Waits that ended before their
target's recorded end -- abandoned/canceled -- are also no longer
treated as joins.)
3. Fallback anchoring at recorded start times silently re-pinned chains
to original times whenever an op's finish was needed while its parent
was mid-replay, collapsing counterfactual propagation (processRun x0
"saved" 55ms instead of 41.7s). Fallbacks now anchor at parent sim
start + recorded offset.
After those fixes the baseline drift is -0.0% on every run measured
(smoke, two full builds, two synthetic chains).
Results on the testbed: the go build itself (exec.processRun, user work)
dominates at ~42-69s recoverable; the top engine-actionable class is
Host.directory (filesync) at ~4s; HTTPState._resolve has 207s of total
self-time but correctly ranks as a non-bottleneck (parallel to the
build) -- exactly the total-time != bottleneck discrimination this is
for. One real finding already: exec.setupNetwork has p50 125us but p95
1.52s (44-55s total across ~230 execs) -- a netns-pool exhaustion tail,
the same class as the original CNI problem.
Validation (known-answer test)
==============================
A file-gated injection aid (/tmp/wcprof-inject-netns-delay-ms inside the
engine container, only consulted while profiling) injects an artificial
delay in setupNetwork. On a strictly serial 10-exec chain with 300ms
injected: the analyzer ranked exec_phase:exec.setupNetwork #1 and
predicted save@0 = 3.32s; disarming the injection and re-running measured
the chain section shrink from 3.57s to 0.46s (actual recovery 3.11s,
prediction within ~7%, which also covers the organic tail it zeroes).
With the injection disarmed the class dropped out of the rankings
entirely -- no false positive. On the engine-dev build the same injection
predicted only ~2.4s saved despite ~48s wall growth: execs there start in
parallel with the build/download chains, so per-exec start taxes mostly
don't serialize in that workload (and cross-run wall comparisons are
polluted by network variance -- validate within-run via the sim, or on
serial synthetic chains).
Known v1 limitations (deliberate)
=================================
- recorder is engine-global (any profiled client enables it);
per-session scoping is future work
- lock waits are modeled as fixed delays (no release->acquire causality)
- unlimited-resources assumption; parallel self-time includes mutex
contention and scheduler queueing (e.g. egraphMu pressure shows up as
dagql.publishResult self-time -- itself a useful signal)
- leaf I/O internals (git fetch, image pull, filesync) are not yet
sub-instrumented; they appear as self-time of their calling op, and
the unexplained-self-time/dead-air reports are the guide for where to
hook next
Usage
=====
./hack/dev
./hack/with-dev ./bin/dagger --profile call engine-dev container sync
curl -s http://localhost:6060/debug/wcprof/dump > /tmp/wcprof.dump
go run ./cmd/wcprof-analyze /tmp/wcprof.dump
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
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.
Signed-off-by: Erik Sipsma [email protected]