GitLabgitlab-org

cli

main
ply9 git calls196 ms99 KiB6 cachedprotocol v2
129 lines4.3 KiBRaw
1package sync
3import (
4 "context"
5 "fmt"
6 "slices"
7 "time"
9 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/fallbacksync"
10 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/syncstate"
13// uploadsFrom returns the time from which agentType's activity is uploaded,
14// or the zero time when there is no such limit.
15func uploadsFrom(agentType string) (time.Time, error) {
16 setups, err := fallbacksync.ReadAgentSetups()
17 if err != nil {
18 return time.Time{}, fmt.Errorf("could not tell which %s activity to upload: %w", agentType, err)
19 }
20 return setups.UploadsFrom(agentType), nil
23// pending is what a sync reads from a session's transcript.
24type pending struct {
25 data *sessionData
26 // next is the position to save once data is uploaded.
27 next int64
28 // uploaded reports whether glab has uploaded any of the session. A
29 // session without uploads is not completed, which would create it on
30 // GitLab empty.
31 uploaded bool
34// readPending reads what src recorded after the session's sync position,
35// leaving out activity from before since, the time the agent was set up.
36func readPending(ctx context.Context, sessionID string, src transcript, since time.Time) (pending, error) {
37 position, err := syncstate.ReadPosition(sessionID)
38 if err != nil {
39 return pending{}, err
40 }
41 position, err = skipBeforeSetup(ctx, sessionID, src, position, since)
42 if err != nil {
43 return pending{}, err
44 }
45 data, next, err := src.read(ctx, position)
46 if err != nil {
47 return pending{}, err
48 }
49 data.dropBefore(since)
50 uploaded, err := syncstate.HasUploads(sessionID, position)
51 if err != nil {
52 return pending{}, err
53 }
54 if !uploaded {
55 data.dropUnmatchedResults()
56 // The readers take the goal only from the start of a transcript, so a
57 // session whose syncing starts later, such as one resumed from before
58 // setup, takes it from its first prompt synced.
59 if data.Goal == "" && len(data.Prompts) > 0 {
60 data.Goal = goalFromText(data.Prompts[0].Text)
61 }
62 }
63 return pending{data: data, next: next, uploaded: uploaded}, nil
66// skipBeforeSetup moves the sync position of a session glab has not read yet,
67// and whose transcript was last active before since, the time the agent was
68// set up, to the end of the transcript. It returns the position to read from.
69// Reading such a transcript again on every run would find nothing to upload,
70// and a session the user resumes later uploads only its new turns.
71func skipBeforeSetup(ctx context.Context, sessionID string, src transcript, position int64, since time.Time) (int64, error) {
72 if position != 0 || since.IsZero() {
73 return position, nil
74 }
75 last, err := src.lastActivity(ctx)
76 if err != nil || !last.Before(since) {
77 return position, err
78 }
79 if err := skipToEnd(ctx, sessionID, src); err != nil {
80 return position, err
81 }
82 return syncstate.ReadPosition(sessionID)
85// dropBefore leaves out what the agent recorded before since, unless since is
86// zero, including the results of calls made before since. A goal or start
87// time from before since is left out too.
88func (d *sessionData) dropBefore(since time.Time) {
89 if since.IsZero() {
90 return
91 }
92 prompts := len(d.Prompts)
93 d.Prompts = slices.DeleteFunc(d.Prompts, func(p prompt) bool { return p.Timestamp.Before(since) })
94 droppedCalls := map[string]struct{}{}
95 d.ToolCalls = slices.DeleteFunc(d.ToolCalls, func(c toolCall) bool {
96 if c.Timestamp.Before(since) {
97 droppedCalls[c.ID] = struct{}{}
98 return true
99 }
100 return false
101 })
102 d.ToolResults = slices.DeleteFunc(d.ToolResults, func(r toolResult) bool {
103 _, dropped := droppedCalls[r.CallID]
104 return dropped || r.Timestamp.Before(since)
105 })
106 d.Responses = slices.DeleteFunc(d.Responses, func(r llmResponse) bool { return r.Timestamp.Before(since) })
108 startedBefore := !d.StartedAt.IsZero() && d.StartedAt.Before(since)
109 if startedBefore || len(d.Prompts) < prompts {
110 d.Goal = ""
111 }
112 if startedBefore {
113 d.StartedAt = time.Time{}
114 }
117// dropUnmatchedResults leaves out the results of calls that data does not
118// hold. A session with nothing uploaded has synced none of its calls, so
119// such a call was skipped, for example because it started before setup.
120func (d *sessionData) dropUnmatchedResults() {
121 calls := make(map[string]struct{}, len(d.ToolCalls))
122 for _, c := range d.ToolCalls {
123 calls[c.ID] = struct{}{}
124 }
125 d.ToolResults = slices.DeleteFunc(d.ToolResults, func(r toolResult) bool {
126 _, ok := calls[r.CallID]
127 return !ok
128 })
Diagnostics9 git calls · 196 ms
CallStatusSizeTime0196 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200261 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=261
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=3bb9946301aa8c0dc8d202b83bc9f84bf0400f6d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=261
git.pkt.payload.max=234
git.sideband.band1.bytes=234
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=234
git.pack.trailer=e0a52f164f79506da6b0dcc275ed62911f5383bf
Open pack map
fetchtree:0200139 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=139
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=f91da6c620e9fe39086f689d1ae91b87356cda50
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=139
git.pkt.payload.max=112
git.sideband.band1.bytes=112
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=112
git.pack.trailer=a35549813b2a01d473947912b5773e993ce7c2e2
Open pack map
fetchtree:0200638 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=178
git.response.bytes=638
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=02089b627a9895becfd23127f25e46df629ce9b2
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=638
git.pkt.payload.max=611
git.sideband.band1.bytes=611
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=611
git.pack.trailer=f2a6246e346c2fa34e54ecb04cb1dd1c524f65bc
Open pack map
fetch2001.6 KiB178 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1649
git.response.cache=MISS
git.response.duration_ms=178
git.fetch.wants=c0838ebb525f14ddfcfead461f55710951f34dbb
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1649
git.pkt.payload.max=1622
git.sideband.band1.bytes=1622
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2dcadbe9ac125
Request
7e2afc42…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format