Skip to content

Commit 59fbd30

Browse files
authored
simulate: decode zstd-compressed run summaries (#904)
* simulate: decode zstd-compressed run summaries * simulate: protocol summary_zstd from merged main * drop narration comment * decode summary once per run update instead of memoizing globals
1 parent de2017e commit 59fbd30

5 files changed

Lines changed: 41 additions & 16 deletions

File tree

cmd/lk/simulate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ import (
3131
"github.com/urfave/cli/v3"
3232
"gopkg.in/yaml.v3"
3333

34+
"github.com/klauspost/compress/zstd"
3435
"github.com/livekit/livekit-cli/v2/pkg/agentfs"
3536
"github.com/livekit/livekit-cli/v2/pkg/config"
3637
"github.com/livekit/livekit-cli/v2/pkg/util"
3738
"github.com/livekit/protocol/livekit"
3839
lksdk "github.com/livekit/server-sdk-go/v2"
3940
"github.com/livekit/server-sdk-go/v2/pkg/cloudagents"
41+
"google.golang.org/protobuf/proto"
4042
)
4143

4244
func init() {
@@ -601,3 +603,23 @@ func simulationJobCounts(run *livekit.SimulationRun) (total, done, passed, faile
601603
}
602604
return
603605
}
606+
607+
func decodeRunSummary(run *livekit.SimulationRun) *livekit.SimulationRunSummary {
608+
if run == nil || len(run.SummaryZstd) == 0 {
609+
return nil
610+
}
611+
dec, err := zstd.NewReader(nil)
612+
if err != nil {
613+
return nil
614+
}
615+
defer dec.Close()
616+
raw, err := dec.DecodeAll(run.SummaryZstd, nil)
617+
if err != nil {
618+
return nil
619+
}
620+
summary := &livekit.SimulationRunSummary{}
621+
if err := proto.Unmarshal(raw, summary); err != nil {
622+
return nil
623+
}
624+
return summary
625+
}

cmd/lk/simulate_ci.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func writeRunResults(w io.Writer, run *livekit.SimulationRun, ap *AgentProcess)
205205
if run == nil {
206206
return
207207
}
208+
summary := decodeRunSummary(run)
208209

209210
if run.Status == livekit.SimulationRun_STATUS_FAILED && len(run.Jobs) == 0 {
210211
fmt.Fprintf(w, "✗ Simulation failed: %s\n", run.Error)
@@ -249,8 +250,8 @@ func writeRunResults(w io.Writer, run *livekit.SimulationRun, ap *AgentProcess)
249250
}
250251
}
251252

252-
if run.Summary != nil && run.Summary.ChatHistory != nil {
253-
writeChatHistory(w, run.Summary.ChatHistory[job.Id])
253+
if summary != nil && summary.ChatHistory != nil {
254+
writeChatHistory(w, summary.ChatHistory[job.Id])
254255
}
255256

256257
if ap != nil && job.RoomName != "" {
@@ -271,8 +272,8 @@ func writeRunResults(w io.Writer, run *livekit.SimulationRun, ap *AgentProcess)
271272
}
272273
}
273274

274-
if run.Summary != nil {
275-
writeRunSummary(w, run)
275+
if summary != nil {
276+
writeRunSummary(w, run, summary)
276277
} else {
277278
msg := "The summary for this run is not available"
278279
if run.Error != "" {
@@ -283,8 +284,7 @@ func writeRunResults(w io.Writer, run *livekit.SimulationRun, ap *AgentProcess)
283284
}
284285
}
285286

286-
func writeRunSummary(w io.Writer, run *livekit.SimulationRun) {
287-
summary := run.Summary
287+
func writeRunSummary(w io.Writer, run *livekit.SimulationRun, summary *livekit.SimulationRunSummary) {
288288
total, _, passed, failed := simulationJobCounts(run)
289289

290290
fmt.Fprintln(w)

cmd/lk/simulate_tui.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func runSimulateTUI(config *simulateConfig) error {
4040
_, runErr := p.Run()
4141

4242
if m.launcher != nil {
43-
// A second ctrl+c during cleanup would kill the CLI and leak the worker
44-
// (own process group, port stays bound); escalate to SIGKILL instead.
43+
// A second ctrl+c during cleanup would kill the CLI and leak the worker
44+
// (own process group, port stays bound); escalate to SIGKILL instead.
4545
sigCh := make(chan os.Signal, 1)
4646
signal.Notify(sigCh, os.Interrupt)
4747
defer signal.Stop(sigCh)
@@ -157,6 +157,7 @@ type simulateModel struct {
157157

158158
// Run phase
159159
run *livekit.SimulationRun
160+
summary *livekit.SimulationRunSummary
160161
runFinished bool
161162
brokenAgent bool
162163
numSimulations int32
@@ -362,6 +363,7 @@ func (m *simulateModel) runSetup() tea.Cmd {
362363
m.err = err
363364
}
364365
m.run = run
366+
m.summary = decodeRunSummary(run)
365367
m.setupDone = true
366368
return nil
367369
}
@@ -575,6 +577,7 @@ func (m *simulateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
575577
case simulationRunMsg:
576578
if msg.err == nil && msg.run != nil {
577579
m.run = msg.run
580+
m.summary = decodeRunSummary(msg.run)
578581
m.reporter.RunUpdate(msg.run, m.config.numSimulations)
579582
if m.startTime.IsZero() && msg.run.Status == livekit.SimulationRun_STATUS_RUNNING {
580583
m.startTime = time.Now()
@@ -1101,7 +1104,7 @@ func (m *simulateModel) viewRunning() string {
11011104

11021105
if m.run.Status == livekit.SimulationRun_STATUS_SUMMARIZING {
11031106
fmt.Fprintf(&b, "\n %s %s %s\n", yellowStyle().Render("⏺"), yellowStyle().Render("Generating summary..."), m.spinner())
1104-
} else if m.run.Summary != nil {
1107+
} else if m.summary != nil {
11051108
b.WriteString(m.renderSummary())
11061109
} else if isTerminalRunStatus(m.run.Status) {
11071110
msg := "The summary for this run is not available"
@@ -1553,7 +1556,7 @@ func (m *simulateModel) scrolledDetail() string {
15531556
}
15541557

15551558
func (m *simulateModel) renderSummary() string {
1556-
summary := m.run.Summary
1559+
summary := m.summary
15571560
if summary == nil {
15581561
return ""
15591562
}
@@ -1622,10 +1625,10 @@ func (m *simulateModel) renderSummary() string {
16221625
}
16231626

16241627
func (m *simulateModel) renderChatTranscript(jobID string) string {
1625-
if m.run.Summary == nil || m.run.Summary.ChatHistory == nil {
1628+
if m.summary == nil || m.summary.ChatHistory == nil {
16261629
return ""
16271630
}
1628-
chatCtx, ok := m.run.Summary.ChatHistory[jobID]
1631+
chatCtx, ok := m.summary.ChatHistory[jobID]
16291632
if !ok || chatCtx == nil || len(chatCtx.Items) == 0 {
16301633
return ""
16311634
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ require (
1919
github.com/google/go-containerregistry v0.20.7
2020
github.com/google/go-querystring v1.2.0
2121
github.com/joho/godotenv v1.5.1
22-
github.com/livekit/protocol v1.49.1-0.20260707153508-a36bd7e4afe5
22+
github.com/klauspost/compress v1.18.6
23+
github.com/livekit/protocol v1.49.1-0.20260712215709-8847d7456816
2324
github.com/livekit/server-sdk-go/v2 v2.17.0
2425
github.com/mattn/go-isatty v0.0.22
2526
github.com/moby/patternmatcher v0.6.1
@@ -155,7 +156,6 @@ require (
155156
github.com/in-toto/attestation v1.1.2 // indirect
156157
github.com/in-toto/in-toto-golang v0.11.0 // indirect
157158
github.com/jxskiss/base62 v1.1.0 // indirect
158-
github.com/klauspost/compress v1.18.6 // indirect
159159
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
160160
github.com/klauspost/pgzip v1.2.6 // indirect
161161
github.com/lithammer/shortuuid/v4 v4.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
357357
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
358358
github.com/livekit/mediatransportutil v0.0.0-20260605212259-862d4a7bcb1e h1:SkgQRcG2VYEhh80Qb/zYZo8rWKJzNfJcfUQnXe6su2M=
359359
github.com/livekit/mediatransportutil v0.0.0-20260605212259-862d4a7bcb1e/go.mod h1:o8CFmAdrVwzJNOCsQCLUzXRjokkufNshnQHOe4fRaqU=
360-
github.com/livekit/protocol v1.49.1-0.20260707153508-a36bd7e4afe5 h1:6ItjuVJkxz/fpxz9eo4pt8FNtEoRSWUUSIZqGl4wOcE=
361-
github.com/livekit/protocol v1.49.1-0.20260707153508-a36bd7e4afe5/go.mod h1:jO+y05AU9Ec4JswDyuzKCZ4bhziOS0CzMqgnbj60Dzs=
360+
github.com/livekit/protocol v1.49.1-0.20260712215709-8847d7456816 h1:MDWDlH5dmcZY4OSljwE4e6B39libPQJIEmBRYaeGAn0=
361+
github.com/livekit/protocol v1.49.1-0.20260712215709-8847d7456816/go.mod h1:jO+y05AU9Ec4JswDyuzKCZ4bhziOS0CzMqgnbj60Dzs=
362362
github.com/livekit/psrpc v0.7.2 h1:6oZ+NODJ2pLyaT6VqDq1F4Qc/3TpDUSpyphj/P9MhQc=
363363
github.com/livekit/psrpc v0.7.2/go.mod h1:rAI+m2+/cb4x9RXhLRtUx5ZwdfjjXOl4zi46IjEetaw=
364364
github.com/livekit/server-sdk-go/v2 v2.17.0 h1:FzVQMoxHv0WIg164yGqSxLeV+h3aJomjAv1lFeR9MMw=

0 commit comments

Comments
 (0)