Repository navigation
clientdb: append protojson elements directly when encoding attribute lists - #14626
Merged
Merged
Conversation
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 10, 2026
Signed-off-by: Erik Sipsma <[email protected]>
vito
approved these changes
Oct 13, 2026
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 13, 2026
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 13, 2026
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 14, 2026
Signed-off-by: Erik Sipsma <[email protected]>
…lists MarshalProtoJSONs wrapped each protojson encoding in json.RawMessage and passed the slice to json.Marshal, which validates and compacts every element again. For span attributes that carry an encoded call this second pass costs more than protojson itself; in an engine CPU profile of repeated no-change rebuilds, checkValid and appendCompact alone were about 3.5% of engine CPU. Append each element to one buffer instead. The stored array decodes to the same values; only insignificant whitespace and HTML escaping may differ, and the byte scans over stored attributes already tolerate protojson whitespace. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 20, 2026
…en its producer's session is removed Add a test for a failure first seen when a superseded check was cancelled: a php-client/test run of dagger#14627 failed with "acquire shared client scope: session ... is closed", naming the session of dagger#14626's php-client/php-stan check on the same engine (traces 51ab194ff7d2c48ac494ff453b55daf7 and 68db9b2801268c97c90d34fcc9d617f5). dagger#14047 gave client work typed lifecycle leases: a call shared across sessions runs under a lease cloned from the session that started it, and a session marked removed refuses every further clone, even from a lease it still holds. Session removal marks the session removed before it waits for its leases to drain, so shared work can still be running when its producer's session is marked removed. A nested call that work then makes fails to clone the producer's scope, and the call's other waiters receive that error although their own sessions are alive. The test builds two sessions with the client lifecycle tests' harness, a real dagql cache, and a call both share. It waits for the second session to join the call, marks the producer's session removed as session removal begins, then lets the shared work make its nested call, and asserts the desired behaviour: the surviving waiter gets the call's value, whether from the shared work or by taking it over. It fails today with the producer's closure, every run. It covers the early teardown window, before the cache releases the producer's session. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
added a commit
to sipsma/dagger
that referenced
this pull request
Oct 21, 2026
…en its producer's session is removed Add a test for a failure first seen when a superseded check was cancelled: a php-client/test run of dagger#14627 failed with "acquire shared client scope: session ... is closed", naming the session of dagger#14626's php-client/php-stan check on the same engine (traces 51ab194ff7d2c48ac494ff453b55daf7 and 68db9b2801268c97c90d34fcc9d617f5). dagger#14047 gave client work typed lifecycle leases: a call shared across sessions runs under a lease cloned from the session that started it, and a session marked removed refuses every further clone, even from a lease it still holds. Session removal marks the session removed before it waits for its leases to drain, so shared work can still be running when its producer's session is marked removed. A nested call that work then makes fails to clone the producer's scope, and the call's other waiters receive that error although their own sessions are alive. The test builds two sessions with the client lifecycle tests' harness, a real dagql cache, and a call both share. It waits for the second session to join the call, marks the producer's session removed as session removal begins, then lets the shared work make its nested call, and asserts the desired behaviour: the surviving waiter gets the call's value, whether from the shared work or by taking it over. It fails today with the producer's closure, every run. It covers the early teardown window, before the cache releases the producer's session. 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.
The engine stores every span's attribute, event and link lists in the per-client telemetry store as a JSON array of protojson messages (
clientdb.MarshalProtoJSONs). It wrapped each protojson encoding injson.RawMessageand passed the slice tojson.Marshal, which validates and compacts every element a second time. For span attributes, which carry the encoded call, that second pass cost more than protojson itself.This change appends each element to one buffer instead.
Effect on stored data
The array decodes to the same values. Only insignificant whitespace (protojson's deliberately unstable spacing) and HTML escaping (
<vs<) may differ.Every reader either parses the array (
UnmarshalProtoJSONsand its callers: span/log reconstruction, the trace subscriber, the Cloud forwarder, archive restore, trace import and inspection) or scans the bytes for a quoted key. Those scans (protoJSONStringAttr, and the markers incall_index.go,telemetry_store.go,archive_index.goandsession_cloud_forwarder.go) already tolerate protojson whitespace. The empty-list encoding is still exactly[], whichcausalLinkTargetsrelies on.Stored rows can be slightly smaller or larger. Spill and archive size budgets count those bytes, so they can trip at a slightly different point.
Measurements
Microbenchmark (
BenchmarkMarshalProtoJSONs, a realistic span attribute set including a 2 KiB encoded call): 46.3 µs → 12.5 µs per encode, 15.3 → 13.9 KB and 211 → 170 allocations.Engine CPU profiles of per-package Go builds (yq v4.49.2, one exec per package, 262 packages, concurrency 16, on a 12-CPU VM):
checkValid+appendCompactwere about 3.5% of engine CPU;json.Marshalwas about 2.4% andcheckValid+appendCompactabout 2.5%.End to end: an ABBA series (4 fresh engines per arm) measured this together with a second, independent telemetry fix (cache evidence no longer clones the call's recipe; separate PR). Medians of wall time, main → both fixes:
The edit result is suggestive rather than established. Nothing regressed, and every run rebuilt exactly the expected packages.
Tests
TestMarshalProtoJSONscovers:[]for nil and empty input, nil elements, and invalid UTF-8 still failing.It runs in the package tests (
test-split/test-packages).BenchmarkMarshalProtoJSONscompares the two encoders.In CI (on this PR's head commit, rebased onto main):
TestMarshalProtoJSONsand its five subtests ran and passed in thetest-split/test-packagescheck (trace):dagger trace f0bdaf18fa6e092b5217ee5a6ea020e2 --test TestMarshalProtoJSONs. All checks are green.