Skip to content

Services: discovery, trace surfacing, tool-log hygiene - #13832

Merged
vito merged 23 commits into
mainfrom
llm-workspace-services
Aug 26, 2026
Merged

vito merged 23 commits into
mainfrom
llm-workspace-services

Conversation

@vito

@vito vito commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Services were easy to lose in a trace, and easy to drown in.

Discovery. A service's logs hang off its exec span, reachable only via cause-purpose links — dagui followed them, clientdb didn't, so ReadLogs on the asService span returned nothing. clientdb now follows them too, and exec spans are marked dagger.io/service + hostname. ListServices closes the loop: each running service's hostname, ports, and span IDs, ready to feed into ReadLogs.

ReadLogs itself recovers instead of dead-ending: an empty capture answers (no logs beneath span X yet) rather than erroring, the span argument accepts the forms agents actually paste (span=<hex>, [traceparent:…]), and out-of-range offsets or fruitless greps report how much data exists.

Surfacing. Agent runs get a SERVICES section in the final report: hostname, command line, state, and a span=<hex> handle per instance, after the main rows. Agent-only on purpose — an agent may see nothing but the report, while a human already watched the service run in the tree.

Tool-log hygiene. Three leaks into LLM tool results plugged: internal subtrees, whole service log histories, and raw SSE frames from nested LLM HTTP spans (hidden unless the request failed — then the bodies are the diagnosis).

Tool logs are abridged by provenance, not position: the tool's own prints survive verbatim (with a 16 KiB backstop), and only nested output is trimmed to a tail behind a counted marker. Two fixes make that hold: Dang stdio now routes to the user-facing span (prints landed one hop too deep and were abridged away as build noise), and the internal filter only consults spans within the captured subtree (a cause-linked span's unrelated ancestors could silently hide logs).

@vito vito changed the title llm workspace services Services: discovery, trace surfacing, tool-log hygiene Aug 4, 2026
@vito
vito marked this pull request as ready for review August 4, 2026 23:45
@vito
vito force-pushed the llm-workspace-services branch from 2437d4d to f43861d Compare August 5, 2026 00:59
@vito
vito force-pushed the llm-workspace-services branch from f43861d to 784cdd8 Compare August 5, 2026 14:59
@vito
vito force-pushed the llm-workspace-services branch from 784cdd8 to 43f84af Compare August 5, 2026 15:30
@vito
vito force-pushed the llm-workspace-services branch from 43f84af to c6ccfe0 Compare August 6, 2026 14:26
@vito
vito requested review from a team as code owners August 6, 2026 20:06
@vito
vito force-pushed the llm-workspace-services branch from c6ccfe0 to a68d26f Compare August 6, 2026 23:28
@vito
vito force-pushed the llm-workspace-services branch from a68d26f to 77e1efb Compare August 7, 2026 13:48
Base automatically changed from llm-workspace-llm-knobs to main August 7, 2026 14:31
@vito
vito force-pushed the llm-workspace-services branch 4 times, most recently from 96009e0 to 4b75f38 Compare August 7, 2026 16:50
vito and others added 23 commits August 23, 2026 14:24
Services are easy to lose in a trace. The long-lived exec span carrying a
service's stdout/stderr is passthrough-hidden, parented under whichever
call happened to trigger the start, and tied to the API spans that
produced the Service value only by cause-purpose span links. dagui follows
those links when rendering, so the TUI shows the logs right there, but
clientdb's descendant walk did not - ReadLogs on the asService span
returned nothing. Nothing marked service spans either, so there was no
cheap way to find them in a deep trace.

clientdb now indexes cause-purpose links in spanLookup and follows them in
descendants(), mirroring dagui's ingestion exactly. Links are indexed from
every snapshot row, not just the first, because they accrue on live spans
over time. SelectLogsBeneathSpan therefore agrees with what the TUI
renders, and the documented "see traceparent, ReadLogs it" flow reaches
service logs too.

Telemetry stamps the service exec span with dagger.io/service - the
authoritative "a service instance ran here" marker, live exactly while the
service is - plus its hostname. ServiceNameAttr moves to
engine/telemetryattrs as the canonical definition and dagui maps both onto
SpanSnapshot, the seam the surfacing work builds on.

Signed-off-by: Alex Suraci <[email protected]>
Service logs became readable via ReadLogs, given a span ID, but agents had
no way to find that span ID short of a service failing. This closes the
discovery loop: the session's running services are one tool call away.

ListServices reports each running service in the current session -
hostname, exposed ports, the span ID of its long-lived exec span, and the
install span IDs of the API calls that produced it. Feeding either into
ReadLogs tails the service, so a dev engine running as a service no longer
means hunting through the trace tree by hand.

Backing it, the Services registry gains read accessors: RunningServices
takes a locked snapshot, session-scoped or engine-wide, ordered
host-then-digest so listings are deterministic, alongside mutex-guarded
span accessors that stay nil-safe for runtimes recording no service span.
The registry only knows live services; exited ones drop out of the listing
but keep readable logs through their span IDs.

Signed-off-by: Alex Suraci <[email protected]>
This is the consume side of the dagger.io/service marker, following the
tui-surfacing pattern of a reveal-independent walk, a report section and a
console affordance.

dagui gains SurfacedServices/HasServices, sharing the walk used by checks
and conversations: Boundary and Encapsulate containment, nesting under the
nearest surfaced ancestor service, start-time order, cached per DB
mutation. A ServiceNode names itself by hostname and resolves its origin -
the API span that produced the Service value - through the cause links the
engine already emits.

The report grows a SERVICES section: one status line per instance, nested
beneath its host, and under an agent each row carries span=<hex> as the
handle for ReadLogs or the console. Placement is deliberate. It renders
after the main rows and never replaces them, because services are
auxiliary context unlike checks or the conversation, and it stays out of
FinalRender's existence gate so a quiet successful run that merely used a
service does not suddenly print a report. The console tags service spans
with their hostname and matches ?q= against it.

Deferred: live-tree promotion, which needs its own design so services do
not take over the top level the way checks do.

Signed-off-by: Alex Suraci <[email protected]>
captureLogs fed every log beneath a tool-call span into the tool result,
including subtrees marked dagger.io/ui.internal - ComputePaths' "computing
paths" prints leaked into Workspace-returning results ahead of the patch
summary.

Skip any log whose span, or any ancestor strictly below the captured span,
is internal, via a memoized filter walk. This mirrors the TUI's roll-up
rule, so what the model sees agrees with what the TUI shows. Capturing an
internal span's subtree explicitly through ReadLogs still returns its
logs: internal-ness at or above the captured root hides nothing.

For the filter to be safe the tool's real work must not be stamped
internal, and plain srv.Select marks its whole evaluation so. MCP's method
call and syncObject's sync are marked WithNonInternalTelemetry - the
treatment dagger call already gives its user-facing entrypoint - so
intended prints such as a build tool's go build output keep surfacing.

Signed-off-by: Alex Suraci <[email protected]>
A tool call touching a long-lived service captured that service's entire
log history: service exec spans enter the subtree both as tree children of
the Service.start call site and via cause links to the Service value's
install spans. The 8-line tail then dropped the module's deliberate print
beneath thousands of service log lines.

The internal-span filter gains a skipServices mode covering spans marked
dagger.io/service plus the install spans where service stdio actually
lands, detected through their cause-linked service exec child. toolLogs
opts in; ReadLogs does not, so ListServices plus ReadLogs remains the
deliberate path to service logs.

Covered by a replay-driven svc-agent whose service emits 200 noise lines
before its healthcheck passes - red without the filter, green with it.

Signed-off-by: Alex Suraci <[email protected]>
A tool that runs a sub-agent and prints its final report came back with
the report gone, replaced by raw SSE frames and an "N lines omitted"
marker. Two independent causes, one per half of that output.

The SSE noise is LLM HTTP telemetry. llmOTelTransport opens a span per
provider request and tees the raw bodies into span stdio, but that span
carried only Encapsulate, never Internal, so the log filter had nothing to
match: a nested LLM loop's entire wire protocol landed in the enclosing
tool result. Mark it Internal - it is a -vvv debugging affordance - while
failed requests un-hide themselves, since then the bodies are the
diagnosis rather than the noise.

The truncation is the other half, and it bit even with zero noise: the cap
keeps 8 lines from the tail, so any longer report arrived head-snipped.
Abridge by provenance instead of position. Each assembled line is tagged
direct when its record sits on the tool-call span or a direct child, which
is where a Dang print lands; nested work is strictly deeper. Direct lines
are kept verbatim and only nested runs are trimmed, each dropped run
replaced by its own counted marker. Deliberate output is the point of the
call and now survives however loud the work beneath it was.

Line assembly carries provenance across records, since records are not
line-aligned; the subtle case of an empty chunk trailing a
newline-terminated record is covered by tests.

Signed-off-by: Alex Suraci <[email protected]>
Services.stopGraceful discarded the cancel func returned by
context.WithTimeoutCause, leaking the timer and context until the deadline
fired. Capture it and defer cancel(); the deferred call runs after the
context.Cause check, so the force-stop path is unaffected.

Fixes the lostcancel finding from go vet ./core/.

Signed-off-by: Alex Suraci <[email protected]>
captureLogLines coalesced consecutive same-provenance log records by
appending onto the previous segment's string, copying the entire
accumulated run on every record — quadratic on long single-provenance
streams, which is the common shape now that ReadLogs reaches a
service's full log history. Keep one segment per record instead:
assembleLines already merges lines across record boundaries with the
same provenance rules, so behavior is unchanged. Its pending-line
accumulator becomes a strings.Builder too, so a single long line split
across many records (e.g. \r-based progress output) can't reintroduce
the same blowup.

Signed-off-by: Alex Suraci <[email protected]>
ReadLogs errored with "offset 0 is beyond log length 0" whenever a span
had no logs — exactly what an agent hits when tailing a quiet service
it just discovered via ListServices. An empty capture now answers
"(no logs beneath span X yet)" unless the span ID is genuinely unknown
to the session's telemetry, which errors with a pointer to where valid
IDs come from. The other dead ends now carry the numbers needed to
recover: paging past the start reports how many lines exist, and a
grep with no matches reports how many lines were searched instead of
returning an empty string. The span argument is also normalized from
the forms agents actually paste — "span=<hex>" from reports and
[traceparent:...] markers from errors, not just bare IDs. Result
shaping moves into renderReadLogs so these paths are unit-testable.

Signed-off-by: Alex Suraci <[email protected]>
captureLogLines hit gocyclo 31 (limit 30): the per-record span handling
grew this branch — the LLM-noise check, the internal-subtree filter, and
the direct/nested provenance call — all inline in the batch loop. Move
that block onto internalSpanFilter as classifyLogSpan, which already
holds the DB handle and captured root, so the loop reads as
skip/classify/decode and the capture drops to complexity 21. No behavior
change.

Signed-off-by: Alex Suraci <[email protected]>
beneathInternal walked a log span's parent chain all the way to the
trace root, but spans join a capture via cause links (a service exec
span is parented under whatever call triggered the start), so their
chains leave the captured subtree without ever passing through the
capture root. An internal span on that unrelated stretch — engine
machinery that happened to trigger the service — silently hid the
capture's logs, even for an explicit ReadLogs on the install span. The
filter now snapshots the capture's descendant set (the same child-edge
plus cause-link walk the log selection scopes to, newly exposed as
clientdb DescendantSpans) and stops the ancestor walk when the chain
leaves it, the same rule as reaching the root: internal-ness out there
is not between the log and the capture. The snapshot refreshes per
batch so late-arriving spans classify against current containment.

Signed-off-by: Alex Suraci <[email protected]>
A Dang module function's print landed on the wrong span. Both Go and Dang
module functions produce two spans - the user-visible dagql field call
and, inside it, dagql's call_exec profiling span, which is passthrough and
rendered by no frontend. Go's logs arrive on the outer span; Dang's
arrived on the inner one, because the runtime binds stdio with
telemetry.SpanStdio and by then ctx's current span is the profiling span.

Containerized SDKs avoid this by construction, since the executor injects
the user-facing span context as the container's traceparent. An in-engine
runtime has to ask for it, so ask.

beginOTelCallExec's own doc comment warns about exactly this failure mode.
It also cost an LLM tool call its output: a module tool's report is
captured from the tool-call span's subtree, and output one hop too deep is
charged to nested work and abridged away with the build noise.

Signed-off-by: Alex Suraci <[email protected]>
Provenance-based abridging keeps a tool's direct output in full by
design — the report is the point of the call — which left tool results
with no total bound at all: a runaway print (a cat'd file, megabytes of
dumped state) would ride into the model's context wholesale, and eight
max-length nested lines approach 16 KiB on their own. Captured tool
logs now pass through a last-resort byte cap after line-based
abridging: 16 KiB total (roughly 4k tokens), keeping the head and tail
around the usual counted ReadLogs marker since a report's opening and
its conclusion both carry signal, with the head taking the larger
share. Lines are already clamped to 2000 chars upstream, so the cap
always retains a useful spread of them.

Signed-off-by: Alex Suraci <[email protected]>
It shipped alongside SurfacedServices billed as a cheap existence check
for live affordances, but nothing ever called it: unlike HasChecks and
friends, services deliberately stay out of FinalRender's existence gate
so a quiet successful run that merely used a service doesn't print a
report. Dead code, and O(all spans) besides — if a live affordance
needs it later, a counter maintained on import would beat rescanning.

Signed-off-by: Alex Suraci <[email protected]>
The listing sorted by hostname then digest via bytes.Compare over
[]byte conversions — needless allocations for plain strings — and the
tiebreak stopped short: in the all-sessions listing the same service
(same hostname and digest) can run once per session, leaving those
entries in nondeterministic map order. Sort with cmp.Or/cmp.Compare
over the hostname and the full service key instead.

Signed-off-by: Alex Suraci <[email protected]>
Review-nit sweep, no behavior change: drop the comments restating
ReadOnly on the ReadLogs and ListServices builtins; document on
serviceInstallSpan that filtering install-span subtrees is deliberately
coarse (a module function that produces a Service loses its
construction logs along with the stdio, with ReadLogs as the way back
in); and replace the hand-rolled two-digit itoa test helper — which
silently broke at 100 — with fmt.Sprintf at its call sites.

Signed-off-by: Alex Suraci <[email protected]>
The SERVICES section appeared in every run that used a service, which
the goldens caught: a human's report grew a redundant footer, since the
tree above already shows the whole service story — the asService row,
its health checks, hostname, and logs. The section's goal was always
agent discovery (an agent driving the CLI may see nothing but the final
report), so render it only under RunningInAgent, matching the existing
gate on span handles — which are now unconditional within the section.
The "via Container.asService" detail also read as noise: it is the same
for every container service, so show the exec span's own name instead —
the service's command line — skipping it when it already serves as the
display name for a hostname-less service. That leaves ServiceNode.Origin
caller-less; drop it.

Signed-off-by: Alex Suraci <[email protected]>
QA'ing what an LLM experiences — especially when a service it started
crashes — requires reading the verbatim MCP tool results, not a TUI
rendering or this agent's own differently-composed session. `dagger mcp`
serves exactly that surface over stdio (workspace module methods as tools,
plus the ReadLogs/ListServices builtins), but a stdio session must outlive
individual agent tool calls, so a small Go bridge (built from the repo's
own Go module, sharing the CLI's mcp-go version) spawns the CLI once and
serves the session over HTTP, held as a Service in the same session-state
pattern as tui-qa. `start` attaches to an engine-lab engine by address or
nests against the session's own engine; `tools` and `call` return
tools/list and tools/call results verbatim, with isError surfaced as a
marker instead of raised — failure UX is the point. The bundled crasher
fixture serves startCrasher (healthy then dies), startDoomed (dies before
healthcheck), and poke as MCP tools, making service-crash scenarios
one-call reproductions. Fixture and bridge live under .dagger, which the
go tool ignores, so root ./... builds stay unaffected.

Signed-off-by: Alex Suraci <[email protected]>
ReadLogs on a service's exec span (the handle ListServices advertises)
returned only the port-healthcheck lines while ReadTrace on the same
span rendered the full container stdout/stderr — the rows exist in
clientdb but the log-selection walk missed them. Two gaps: service stdio
is deliberately attributed to the install span (Container.asService),
whose own rows the walk excluded as the query root (parity with the old
WITH RECURSIVE SQL), and the exec-to-install cause link was only indexed
in the linked-to-linking direction, so from the exec span the install
span was unreachable entirely.

Index cause links in both directions (causalParents mirrors dagui's
causesViaLinks) and replace descendants() with logScope(): seed the walk
with the root plus the root's cause-link targets, include the seeds' own
rows, then follow the same downward edges as before. Reverse edges are
followed from the root only, so a span merely reached during a tool-call
capture cannot drag unrelated install subtrees in. SelectLogsBeneathSpan
filters against the new scope, DescendantSpans becomes SpanLogScope, and
core/mcp.go's internalSpanFilter classifies against the same scope so
the filter and the selection agree. ReadLogs on either advertised handle
now returns what the renderer shows, while the service runs and after it
dies.

NOTE: HasDescendants are backported from a commit in an upper PR, to
minimize conflicts

Signed-off-by: Alex Suraci <[email protected]>
The moment a service exited — crash included — it vanished from
ListServices, leaving an agent with no record it ever existed and no span
handle to read its logs, exactly when the logs matter most. The registry
now records a tombstone at the single point where it observes an exit
(handleExit, which previously discarded the Wait error): host, ports, the
service and install span contexts, exit time, and the exit code/error
extracted from the Wait error when available. Tombstones are per-session,
capped at 100 (oldest dropped), and cleared when the session's services
stop. ListServices renders running services first, unchanged, then exited
ones with state "exited" and any exitCode/exitError — additive fields, so
the JSON shape stays backward compatible — and the tool description now
tells the model dead services stay listed with logs reachable via ReadLogs.

Signed-off-by: Alex Suraci <[email protected]>
The crasher fixture's tool calls were served from the dagql per-(function,
args) session cache: a second poke of the same URL replayed the first
call's "ok" even after the target service had died — a stale answer for a
model polling a service. The Go SDK's +cache="never" pragma opts the
function call out of that cache so every call re-executes the body. The
CACHE_BUST env variables stay: they serve the complementary layer, busting
the buildkit exec cache (poke) and forcing a distinct service definition
per call (startCrasher/startDoomed) so re-run bodies do fresh work.

Signed-off-by: Alex Suraci <[email protected]>
Append exited service tombstones through a local slice variable so gocritic
recognizes that the append result is assigned back to the same slice.

Signed-off-by: Alex Suraci <[email protected]>
Give the internal-log filtering fixture a unique workspace digest so its
nested exec emits the live output used as the test's positive control.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the llm-workspace-services branch 2 times, most recently from 394b446 to 6336dc5 Compare August 25, 2026 20:47
@vito
vito merged commit 4ef99fb into main Aug 26, 2026
90 checks passed
@vito
vito deleted the llm-workspace-services branch August 26, 2026 00:31
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