GitLabgitlab-org

cli

main
ply9 git calls303 ms109 KiB7 cachedprotocol v2
1107 lines39 KiBRaw
1package sync
3import (
4 "cmp"
5 "context"
6 "crypto/sha256"
7 "errors"
8 "fmt"
9 "net/http"
10 "os"
11 "runtime"
12 "slices"
13 "strconv"
14 "strings"
15 "time"
16 "unicode/utf8"
18 "github.com/MakeNowJust/heredoc/v2"
19 "github.com/google/uuid"
20 "github.com/spf13/cobra"
22 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
24 "gitlab.com/gitlab-org/cli/internal/api"
25 "gitlab.com/gitlab-org/cli/internal/cmdutils"
26 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/fallbacksync"
27 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/gaig"
28 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/redact"
29 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/syncstate"
30 "gitlab.com/gitlab-org/cli/internal/config"
31 "gitlab.com/gitlab-org/cli/internal/dbg"
32 "gitlab.com/gitlab-org/cli/internal/glrepo"
33 "gitlab.com/gitlab-org/cli/internal/iostreams"
34 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
35 "gitlab.com/gitlab-org/cli/internal/text"
38type options struct {
39 io *iostreams.IOStreams
40 apiClient func(repoHost string) (*api.Client, error)
41 baseRepo func() (glrepo.Interface, error)
42 executor cmdutils.Executor
43 config func() config.Config
44 silent bool
45 complete bool
46 agentType string
47 all bool
48 // hook is the agent whose hook passes the session on stdin.
49 hook string
50 buildInfo api.BuildInfo
51 // rateLimitWaited is how long this run has waited out GitLab's rate limit.
52 rateLimitWaited time.Duration
53 // waitFor, when set, replaces waiting for a duration, for tests.
54 waitFor func(ctx context.Context, d time.Duration) error
55 // startDetached, when set, replaces starting glab in the background, for tests.
56 startDetached func(dir string, env []string, args ...string) error
59// wait waits for d, or until ctx is done.
60func (o *options) wait(ctx context.Context, d time.Duration) error {
61 if o.waitFor != nil {
62 return o.waitFor(ctx, d)
63 }
64 select {
65 case <-ctx.Done():
66 return ctx.Err()
67 case <-time.After(d):
68 return nil
69 }
72const (
73 // idleCompleteAfter is how long a session must be inactive before
74 // `--all` marks it completed on behalf of a SessionEnd hook that never ran.
75 idleCompleteAfter = 24 * time.Hour
76 // forgetUnfoundAfter is how long --all keeps reporting a session the
77 // agent says it does not have, and keeps a completed session it cannot
78 // check, before forgetting it.
79 forgetUnfoundAfter = 30 * 24 * time.Hour
80 maxStatusErrors = 20
83func NewCmd(f cmdutils.Factory) *cobra.Command {
84 opts := &options{
85 io: f.IO(),
86 apiClient: f.ApiClient,
87 baseRepo: f.BaseRepo,
88 executor: f.Executor(),
89 config: f.Config,
90 buildInfo: f.BuildInfo(),
91 }
93 cmd := &cobra.Command{
94 Use: "sync",
95 Short: "Sync agent session data to GitLab. (EXPERIMENTAL)",
96 Long: heredoc.Docf(`
97 Read new entries from the local agent transcript since the last sync and POST them to GitLab as audit events.
99 The audit events contain the prompts you type, each tool call with its arguments (such as commands, file paths, and edits, replaced with a marker when over 8 KB), each tool call's outcome, duration, and error message, and the model and token usage of each response. Tool output and the text of responses are not sent.
101 Before anything is sent, glab replaces common secret formats with a marker such as %[1]s[REDACTED:gitlab_token]%[1]s: GitLab, GitHub, Slack, npm and PyPI tokens, AWS, Google, Stripe, OpenAI and Anthropic API keys, JWTs, private keys, credentials in Authorization and token headers or under credential-like keys, and passwords in URLs. This is best effort: other secrets in prompts, commands, or file contents are sent as they are.
103 When glab creates a session on GitLab, it also sends the glab version and the agent's version. A session that has never synced and has had no activity in the last 89 days is not uploaded, because GitLab does not accept events that old. Activity from before an agent was set up with %[1]sglab minder setup%[1]s is not uploaded either, unless setup was run with %[1]s--include-history%[1]s.
105 Some agents record less:
107 - OpenCode: prompts and responses are not sent, and a tool call's outcome is sent only if the call had finished when it was first synced.
108 - Codex: a tool call's outcome is "completed", because Codex does not record whether it succeeded.
109 - Cursor: only prompts and tool calls are sent, timed by the transcript's last modification, because Cursor records no results, token usage, timestamps, or version. For a Cursor session that started before Cursor was set up, only what was added after setup is uploaded. A Cursor session is not synced if the files its tool calls read or write are outside the workspace glab finds, or if several directories match the workspace's name and those files don't show which, so that it is not uploaded to the wrong project.
111 If a GitLab instance does not accept an agent's sessions yet, they are not uploaded, then or after the instance is upgraded. Sessions from after the upgrade are.
113 Called by the Claude Code Stop hook after every agent turn. Also used by its SessionEnd hook (with %[1]s--complete%[1]s) to mark the session as complete. The hooks also record the session's project, host, and transcript location so that %[1]s--all%[1]s can sync it later.
115 With %[1]s--hook codex%[1]s or %[1]s--hook cursor%[1]s, reads the session from the JSON that a Codex Stop hook, or a Cursor stop or sessionEnd hook, gets on stdin, and syncs it with a glab started in the background, so the agent does not wait for the upload. It prints nothing, because the agent reads a hook's output as a reason to continue. The project is resolved from the session's directory, or for Cursor from the workspace folder that the transcript belongs to.
117 In a Cursor workspace with several folders, glab uses the folder the workspace is named after, unless the session's tool calls point elsewhere, or otherwise the one folder the tool calls used. Until a turn shows which, the session is not synced. Cursor's sessionEnd hook does not mark a session as complete. A Cursor session is completed once it has been inactive for 24 hours.
119 Project is resolved from the Git remote of the current directory, or overridden with %[1]s-R/--repo%[1]s.
121 With %[1]s--all%[1]s, syncs every session the hooks have recorded, each to the project and host it was recorded with. Sessions inactive for 24 hours are marked completed. Sessions from agents that use hooks are skipped while the glab hooks are missing, so removing the hooks pauses them, including an agent session that was already open and still runs them. The fallback periodic sync installed by %[1]sglab minder setup%[1]s runs this, and %[1]sglab minder doctor%[1]s shows the result of its last run.
123 Supports Claude Code, OpenCode, Codex, and Cursor sessions. OpenCode sessions are read with %[1]sopencode session export%[1]s, or %[1]sopencode export%[1]s before OpenCode 2. With %[1]s--all%[1]s, it also finds and syncs the sessions of Codex and Cursor, when they are enabled with %[1]sglab minder setup --agents%[1]s, by scanning their transcripts, for repositories on GitLab hosts glab is logged in to.
124 `, "`") + text.ExperimentalString,
125 Example: heredoc.Doc(`
126 # Sync the current agent session to GitLab
127 $ glab minder audit sync
129 # Sync and mark the session as completed
130 $ glab minder audit sync --complete
132 # Sync against a specific project
133 $ glab minder audit sync -R my-group/my-project
135 # Sync every recorded session that has unsynced activity
136 $ glab minder audit sync --all
137 `),
138 Args: cobra.NoArgs,
139 ValidArgsFunction: cobra.NoFileCompletions,
140 Annotations: map[string]string{
141 mcpannotations.Destructive: "true",
142 },
143 RunE: func(cmd *cobra.Command, args []string) error {
144 return runSync(cmd.Context(), opts)
145 },
146 }
148 fl := cmd.Flags()
149 fl.BoolVar(&opts.silent, "silent", false, "Suppress all output. Used when invoked from hooks.")
150 fl.BoolVar(&opts.complete, "complete", false, "Mark the session as completed. Used by the SessionEnd hook.")
151 fl.BoolVar(&opts.all, "all", false, "Sync all sessions recorded by the hooks. Used by the fallback periodic sync.")
152 fl.Var(cmdutils.NewEnumValue(hookAgents, "", &opts.hook), "hook", fmt.Sprintf("Read the session from the stdin of this agent's hook, and sync it in the background: %s. Used by the Codex and Cursor hooks.", strings.Join(hookAgents, ", ")))
154 cmdutils.EnableRepoOverride(cmd, f)
155 cmd.MarkFlagsMutuallyExclusive("all", "repo")
156 cmd.MarkFlagsMutuallyExclusive("all", "complete")
157 for _, other := range []string{"all", "complete", "repo"} {
158 cmd.MarkFlagsMutuallyExclusive("hook", other)
159 }
161 return cmd
164func runSync(ctx context.Context, opts *options) error {
165 if opts.hook != "" {
166 return runHook(opts)
167 }
168 if opts.all {
169 return syncAllSessions(ctx, opts)
170 }
172 ag, sessionID := detectAgent(supportedAgents(opts.executor))
174 var src transcript
175 if ag != nil {
176 // A session that started before the hooks were removed still runs
177 // them, so the pause that --all and --hook honour applies here too.
178 reason, err := ag.pausedReason()
179 if err != nil {
180 return fmt.Errorf("not syncing the %s session: could not check whether syncing is paused: %w", ag.name(), err)
181 }
182 if reason != "" {
183 if !opts.silent {
184 opts.io.LogInfof("Not syncing the %s session: %s.\n", ag.name(), reason)
185 }
186 return nil
187 }
188 opts.agentType = ag.name()
189 var locator string
190 src, locator, err = ag.current(sessionID)
191 if err != nil {
192 return err
193 }
194 // Written before ResolveProject so a failed project lookup still
195 // leaves enough context for --all to retry this session later, or to
196 // report it when the folder has no GitLab project.
197 err = recordSessionMeta(ctx, opts, ag, sessionID, locator)
198 if errors.Is(err, errEarlierActivityNotSkipped) {
199 return err
200 }
201 if err != nil && !opts.silent {
202 opts.io.LogErrorf("warning: could not record session metadata: %v\n", err)
203 }
204 }
206 project, client, err := gaig.ResolveProject(opts.baseRepo, opts.apiClient)
207 if err != nil {
208 if !opts.silent {
209 opts.io.LogErrorf("error: could not resolve project: %v\n", err)
210 }
211 return err
212 }
214 if !opts.silent {
215 opts.io.LogInfof("Project: %s (ID: %d)\n", project.PathWithNamespace, project.ID)
216 }
218 t := target{client: client, project: project}
219 if opts.agentType != "" {
220 identity, err := gaig.RegisterIdentity(ctx, client, project.ID, opts.agentType)
221 if errors.Is(err, gitlab.ErrNotFound) {
222 if !opts.silent {
223 opts.io.LogInfo(governanceNotEnabled)
224 }
225 return nil
226 }
227 if err != nil && !opts.silent {
228 opts.io.LogErrorf("warning: %v\n", err)
229 }
230 if identity != nil {
231 t.identityID = identity.ID
232 if !opts.silent {
233 opts.io.LogInfof("Agent identity: %d\n", identity.ID)
234 }
235 }
236 }
238 if sessionID == "" {
239 if !opts.silent {
240 opts.io.LogInfo("No active agent session detected.")
241 }
242 return nil
243 }
245 return syncSession(ctx, t, sessionID, src, opts)
248// withoutRemoteReason is the not-synced reason for an agent's sessions that ran
249// in a folder without a GitLab project.
250func withoutRemoteReason(agentType string) string {
251 return agentType + " sessions in a folder where glab could not identify a GitLab project"
254var errEarlierActivityNotSkipped = errors.New("could not skip activity from before the session had a GitLab project")
256// recordSessionMeta records the session for --all. A session recorded without a
257// project skips its earlier activity before it is recorded with one, so a
258// failed skip leaves it without a project for the next hook call to retry.
259func recordSessionMeta(ctx context.Context, opts *options, ag agent, sessionID, locator string) error {
260 if opts.baseRepo == nil {
261 return nil
262 }
263 meta, readErr := readSessionMeta(sessionID)
264 recordedWithoutProject := readErr == nil && meta.PathWithNamespace == ""
265 repo, err := opts.baseRepo()
266 if err != nil {
267 // ResolveProject reports err. Recording the session lets --all report
268 // it as not synced, and every hook call rewrites the record, which
269 // --all reads as the session's last activity.
270 switch {
271 case errors.Is(readErr, errNoSessionMeta):
272 case readErr != nil:
273 return readErr
274 case meta.PathWithNamespace != "":
275 return nil
276 }
277 return writeSessionMeta(sessionID, sessionMeta{AgentType: opts.agentType, Transcript: locator})
278 }
279 if recordedWithoutProject {
280 // The recorded transcript, not the hook's: the hook's path follows its
281 // working directory, which changes if the agent changed directory.
282 src, _, err := ag.recorded(sessionID, cmp.Or(meta.Transcript, locator))
283 if err == nil {
284 err = skipToEnd(ctx, sessionID, src)
285 }
286 if err != nil {
287 return fmt.Errorf("%w: %w", errEarlierActivityNotSkipped, err)
288 }
289 }
290 return writeSessionMeta(sessionID, sessionMeta{
291 AgentType: opts.agentType,
292 PathWithNamespace: repo.FullName(),
293 Host: repo.RepoHost(),
294 Transcript: locator,
295 })
298// skipToEnd moves the session's sync position past what the transcript holds
299// now. The user agreed to upload sessions in a GitLab repository, so a session
300// that only now has a GitLab remote uploads its activity from this point, not
301// what it did before in another folder or repository.
302func skipToEnd(ctx context.Context, sessionID string, src transcript) error {
303 if src == nil {
304 return nil
305 }
306 position, err := syncstate.ReadPosition(sessionID)
307 if err != nil {
308 return err
309 }
310 _, end, err := src.read(ctx, position)
311 if err != nil {
312 return err
313 }
314 return syncstate.StartAt(sessionID, end)
317// target is the project a session is synced to.
318type target struct {
319 client *api.Client
320 project *gitlab.Project
321 identityID int
324// syncSession syncs a single session transcript to GitLab.
325func syncSession(ctx context.Context, t target, sessionID string, src transcript, opts *options) error {
326 since, err := uploadsFrom(opts.agentType)
327 if err != nil {
328 return err
329 }
330 p, err := readPending(ctx, sessionID, src, since)
331 if errors.Is(err, errTranscriptNotFound) {
332 if !opts.silent {
333 opts.io.LogInfof("No transcript found at %s\n", src)
334 }
335 return nil
336 }
337 if err != nil {
338 return fmt.Errorf("could not read the session: %w", err)
339 }
341 if p.data.empty() && (!opts.complete || !p.uploaded) {
342 if !opts.silent {
343 opts.io.LogInfo("No new entries to sync.")
344 }
345 return nil
346 }
348 if t.client == nil || t.project == nil {
349 return fmt.Errorf("client and project are required")
350 }
352 if opts.agentType == "" {
353 if !opts.silent {
354 opts.io.LogInfo("No agent type detected -- skipping session sync.")
355 }
356 return nil
357 }
359 if _, err := pushSession(ctx, t, sessionID, opts.agentType, src, p.data, p.next, opts.complete, opts); err != nil && !opts.silent {
360 opts.io.LogErrorf("warning: %v\n", err)
361 }
362 return nil
365type pushResult struct {
366 eventsPosted int
367 eventsTooLarge int
368 completed bool
371// pushSession uploads data to GitLab, advances the cursor to newCursor once
372// the events are posted, and marks the session completed if requested.
373func pushSession(ctx context.Context, t target, sessionID, agentType string, src transcript, data *sessionData, newCursor int64, complete bool, opts *options) (pushResult, error) {
374 var res pushResult
375 redactSessionData(data)
377 glSessionID, err := ensureSession(ctx, t.client, t.project.ID, t.identityID, sessionID, agentType, syncTypeFor(opts), opts.buildInfo.Version, data)
378 if err != nil {
379 return res, err
380 }
381 if glSessionID <= 0 {
382 return res, errors.New("could not create session: GitLab returned no session ID")
383 }
384 if !opts.silent {
385 opts.io.LogInfof("Session: %d\n", glSessionID)
386 }
388 if events := auditEvents(agentType, data, time.Now()); len(events) > 0 {
389 poster := auditEventPoster{client: t.client, projectID: t.project.ID, sessionID: glSessionID, opts: opts}
390 tooLarge, err := poster.post(ctx, events)
391 res.eventsTooLarge = tooLarge
392 if err != nil {
393 return res, fmt.Errorf("could not post audit events: %w", err)
394 }
395 res.eventsPosted = len(events) - tooLarge
396 if !opts.silent {
397 opts.io.LogInfof("Posted %d audit events\n", res.eventsPosted)
398 if tooLarge > 0 {
399 opts.io.LogErrorf("warning: skipped %d audit events too large for GitLab to accept\n", tooLarge)
400 }
401 }
402 }
404 if err := syncstate.WritePosition(sessionID, newCursor); err != nil && !opts.silent {
405 opts.io.LogErrorf("warning: could not update the sync position: %v\n", err)
406 }
408 if !complete {
409 return res, nil
410 }
412 sum, err := src.checksum(ctx)
413 if err != nil && !opts.silent {
414 opts.io.LogErrorf("warning: could not compute transcript checksum: %v\n", err)
415 }
416 if err := completeSession(ctx, t.client, t.project.ID, glSessionID, sum); err != nil {
417 return res, fmt.Errorf("could not complete session: %w", err)
418 }
419 res.completed = true
420 if !opts.silent {
421 opts.io.LogInfo("Session marked as completed.")
422 }
423 if err := markSessionCompleted(sessionID, time.Now()); err != nil && !opts.silent {
424 opts.io.LogErrorf("warning: could not record session completion: %v\n", err)
425 }
426 return res, nil
429// redactSessionData replaces the secrets in the prompts and error messages
430// that glab sends from data. The goal is redacted when it is read, because it
431// is shortened then, and tool arguments when their size is checked, because a
432// marker can be longer than the secret it replaces.
433func redactSessionData(data *sessionData) {
434 for i := range data.Prompts {
435 data.Prompts[i].Text = redact.Secrets(data.Prompts[i].Text)
436 }
437 for i := range data.ToolResults {
438 data.ToolResults[i].Error = redact.Secrets(data.ToolResults[i].Error)
439 }
442func syncAllSessions(ctx context.Context, opts *options) error {
443 now := time.Now()
444 status := fallbacksync.Status{StartedAt: now}
445 defer func() {
446 status.FinishedAt = time.Now()
447 if err := fallbacksync.WriteStatus(status); err != nil && !opts.silent {
448 opts.io.LogErrorf("warning: could not record sync status: %v\n", err)
449 }
450 }()
451 recordRunErr := func(err error) {
452 if !opts.silent {
453 opts.io.LogErrorf("warning: %v\n", err)
454 }
455 if len(status.Errors) < maxStatusErrors {
456 status.Errors = append(status.Errors, err.Error())
457 }
458 }
459 recordErr := func(sessionID string, err error) {
460 recordRunErr(fmt.Errorf("session %s: %w", sessionID, err))
461 }
463 sessionIDs, err := listSessionMetas()
464 if err != nil {
465 status.Errors = append(status.Errors, err.Error())
466 return err
467 }
468 setups, err := fallbacksync.ReadAgentSetups()
469 if err != nil {
470 err = fmt.Errorf("could not tell which activity to upload: %w", err)
471 status.Errors = append(status.Errors, err.Error())
472 return err
473 }
475 agents := supportedAgents(opts.executor)
476 known := make(map[string]struct{}, len(sessionIDs))
477 for _, id := range sessionIDs {
478 known[id] = struct{}{}
479 }
480 recordSkip := func(reason string) {
481 if !slices.Contains(status.Skipped, reason) {
482 status.Skipped = append(status.Skipped, reason)
483 }
484 if !opts.silent {
485 opts.io.LogInfof("Not syncing: %s.\n", reason)
486 }
487 }
488 sessionIDs = append(sessionIDs, discoverSessions(ctx, agents, known, opts.config(), recordRunErr, recordSkip)...)
489 // paused caches each agent's pause check for the run. A failed check
490 // pauses the agent, because uploading is not safe when it is unclear
491 // whether the user turned syncing off.
492 paused := map[string]bool{}
493 isPaused := func(a agent) bool {
494 if p, ok := paused[a.name()]; ok {
495 return p
496 }
497 reason, err := a.pausedReason()
498 if err != nil {
499 reason = fmt.Sprintf("could not check whether syncing is paused: %v", err)
500 }
501 paused[a.name()] = reason != ""
502 if reason != "" {
503 status.Paused = append(status.Paused, a.name()+": "+reason)
504 if !opts.silent {
505 opts.io.LogInfof("Skipping %s sessions: %s.\n", a.name(), reason)
506 }
507 }
508 return reason != ""
509 }
511 targets := map[string]targetLookup{}
512 identities := map[string]identityLookup{}
513 reported := map[string]struct{}{}
514 recordOnce := func(key, sessionID string, err error) {
515 if _, ok := reported[key]; ok {
516 return
517 }
518 reported[key] = struct{}{}
519 recordErr(sessionID, err)
520 }
521 // A GitLab version that does not accept an agent type rejects all its
522 // sessions. They are marked completed locally rather than retried, so
523 // they are not uploaded in a burst after an upgrade, long after the user
524 // agreed to syncing.
525 recordUnsupported := func(agentType, host, sessionID string) {
526 entry := agentType + " on " + host
527 if !slices.Contains(status.AgentTypeNotSupported, entry) {
528 status.AgentTypeNotSupported = append(status.AgentTypeNotSupported, entry)
529 }
530 if err := markSessionCompleted(sessionID, now); err != nil {
531 recordErr(sessionID, err)
532 }
533 }
534 // The governance endpoints answer 404 when the feature is off for a
535 // project that was found, which is expected rather than an error.
536 recordNotEnabled := func(projectKey string) {
537 if !slices.Contains(status.GovernanceNotEnabled, projectKey) {
538 status.GovernanceNotEnabled = append(status.GovernanceNotEnabled, projectKey)
539 }
540 }
541 // A project lookup answers 404 for a deleted project, one the user cannot
542 // see, and any private project when no token is found, which the job can
543 // hit when it runs without the user's shell environment. The session is
544 // kept for a later run rather than dropped.
545 recordProjectNotFound := func(projectKey string) {
546 if !slices.Contains(status.ProjectNotFound, projectKey) {
547 status.ProjectNotFound = append(status.ProjectNotFound, projectKey)
548 }
549 }
550 // A host is only reported when something there failed, because a host
551 // without a token still syncs if every lookup and upload succeeds.
552 tokenChecked := map[string]struct{}{}
553 failedWithoutToken := func(host string) {
554 if _, ok := tokenChecked[host]; ok {
555 return
556 }
557 tokenChecked[host] = struct{}{}
558 // A token that cannot be read, such as from a locked keyring, fails
559 // the client and is recorded as an error instead.
560 cfg := opts.config()
561 if token, _, err := cfg.GetWithSource(host, "token", true); err != nil || token != "" {
562 return
563 }
564 if jobToken, err := cfg.Get(host, "job_token"); err == nil && jobToken == "" {
565 status.NoToken = append(status.NoToken, host)
566 }
567 }
568 for _, sessionID := range sessionIDs {
569 meta, err := readSessionMeta(sessionID)
570 if err != nil {
571 recordErr(sessionID, err)
572 continue
573 }
575 ag := agentByName(agents, meta.AgentType)
576 if ag == nil {
577 recordErr(sessionID, fmt.Errorf("unsupported agent %q", meta.AgentType))
578 continue
579 }
581 src, locator, err := ag.recorded(sessionID, meta.Transcript)
582 if err != nil {
583 recordErr(sessionID, err)
584 continue
585 }
586 if locator != meta.Transcript {
587 meta.Transcript = locator
588 if err := writeSessionMeta(sessionID, *meta); err != nil {
589 recordErr(sessionID, err)
590 }
591 }
593 if meta.CompletedAt != nil {
594 // Local state is kept while the agent can still resume the session.
595 forget, err := ag.canForget(src, *meta.CompletedAt)
596 if err != nil {
597 recordErr(sessionID, err)
598 } else if forget {
599 if err := forgetSession(sessionID); err != nil {
600 recordErr(sessionID, err)
601 }
602 }
603 continue
604 }
606 if isPaused(ag) {
607 continue
608 }
609 if meta.PathWithNamespace == "" {
610 recordSkip(withoutRemoteReason(meta.AgentType))
611 last, err := sessionMetaModTime(sessionID)
612 if err != nil {
613 recordErr(sessionID, err)
614 } else if now.Sub(last) > idleCompleteAfter {
615 // Completed rather than forgotten: if the session resumes in a
616 // GitLab project, the record is what makes it skip its earlier
617 // activity. canForget deletes it once the agent cannot resume it.
618 if err := markSessionCompleted(sessionID, now); err != nil {
619 recordErr(sessionID, err)
620 }
621 }
622 continue
623 }
624 p, err := readPending(ctx, sessionID, src, setups.UploadsFrom(meta.AgentType))
625 if errors.Is(err, errTranscriptNotFound) {
626 // The agent has deleted the transcript, so there is nothing left
627 // to sync. Forgetting the session stops later runs searching for it.
628 if err := forgetSession(sessionID); err != nil {
629 recordErr(sessionID, err)
630 }
631 continue
632 }
633 if errors.Is(err, errAgentSessionNotFound) {
634 if recorded, statErr := sessionMetaModTime(sessionID); statErr == nil && now.Sub(recorded) > forgetUnfoundAfter {
635 if err := forgetSession(sessionID); err != nil {
636 recordErr(sessionID, err)
637 }
638 continue
639 }
640 }
641 if err != nil {
642 recordErr(sessionID, err)
643 continue
644 }
646 last, err := src.lastActivity(ctx)
647 if err != nil {
648 recordErr(sessionID, err)
649 continue
650 }
651 if !p.uploaded && now.Sub(last) > gaig.MaxEventAge {
652 // GitLab accepts no events this old, so a session with nothing
653 // uploaded would arrive empty. It is marked completed locally so it
654 // is not checked again. A session that has synced still goes
655 // through idle completion, so it is completed on GitLab.
656 if err := markSessionCompleted(sessionID, now); err != nil {
657 recordErr(sessionID, err)
658 }
659 continue
660 }
661 idle := now.Sub(last) > idleCompleteAfter
662 if p.data.empty() && (!idle || !p.uploaded) {
663 continue
664 }
666 // Lookups are cached per project for the run, and a failure is
667 // recorded once, so one unreachable project cannot fill the error
668 // list with a copy for each of its sessions.
669 projectKey := meta.Host + "/" + meta.PathWithNamespace
670 t, err := lookupTarget(targets, meta, opts)
671 switch {
672 case errors.Is(err, gitlab.ErrNotFound):
673 failedWithoutToken(meta.Host)
674 recordProjectNotFound(projectKey)
675 continue
676 case err != nil:
677 failedWithoutToken(meta.Host)
678 recordOnce("project "+projectKey, sessionID, err)
679 continue
680 }
681 identityKey := projectKey + " " + meta.AgentType
682 identity, ok := identities[identityKey]
683 if !ok {
684 registered, err := gaig.RegisterIdentity(ctx, t.client, t.project.ID, meta.AgentType)
685 switch {
686 case errors.Is(err, gitlab.ErrNotFound):
687 recordNotEnabled(projectKey)
688 case unsupportedAgentType(err):
689 identity.unsupported = true
690 case err != nil:
691 failedWithoutToken(meta.Host)
692 recordOnce("identity "+identityKey, sessionID, err)
693 }
694 if registered != nil {
695 identity = identityLookup{id: registered.ID, ok: true}
696 }
697 identities[identityKey] = identity
698 }
699 if identity.unsupported {
700 recordUnsupported(meta.AgentType, meta.Host, sessionID)
701 continue
702 }
703 if !identity.ok {
704 // GitLab requires an agent identity to create a session.
705 continue
706 }
707 t.identityID = identity.id
709 res, err := pushSession(ctx, t, sessionID, meta.AgentType, src, p.data, p.next, idle, opts)
710 status.EventsPosted += res.eventsPosted
711 status.EventsTooLarge += res.eventsTooLarge
712 if res.eventsPosted > 0 {
713 status.SessionsSynced++
714 }
715 if res.completed {
716 status.SessionsCompleted++
717 }
718 switch {
719 case errors.Is(err, gitlab.ErrNotFound) && res.eventsPosted == 0 && !res.completed:
720 recordNotEnabled(projectKey)
721 case unsupportedAgentType(err):
722 recordUnsupported(meta.AgentType, meta.Host, sessionID)
723 case err != nil:
724 failedWithoutToken(meta.Host)
725 recordErr(sessionID, err)
726 }
727 }
728 return nil
731type targetLookup struct {
732 target target
733 err error
736type identityLookup struct {
737 id int
738 ok bool
739 // unsupported reports that GitLab does not accept the agent type.
740 unsupported bool
743// unsupportedAgentType reports whether GitLab rejected a request because it
744// does not accept the session's agent type, as GitLab versions from before
745// an agent was added do.
746func unsupportedAgentType(err error) bool {
747 var resp *gitlab.ErrorResponse
748 return errors.As(err, &resp) && resp.StatusCode == http.StatusBadRequest && strings.Contains(resp.Message, "agent_type")
751// lookupTarget resolves the project a session was recorded with, caching the
752// result per host and project so each is looked up once per run.
753func lookupTarget(cache map[string]targetLookup, meta *sessionMeta, opts *options) (target, error) {
754 if meta.Host == "" || meta.PathWithNamespace == "" {
755 return target{}, errors.New("session metadata has no project")
756 }
758 key := meta.Host + "/" + meta.PathWithNamespace
759 lookup, ok := cache[key]
760 if !ok {
761 lookup = resolveTarget(meta, opts)
762 cache[key] = lookup
763 }
764 if lookup.err != nil {
765 return target{}, lookup.err
766 }
768 return lookup.target, nil
771func resolveTarget(meta *sessionMeta, opts *options) targetLookup {
772 client, err := opts.apiClient(meta.Host)
773 if err != nil {
774 return targetLookup{err: fmt.Errorf("could not create client for %s: %w", meta.Host, err)}
775 }
776 project, err := api.GetProject(client.Lab(), meta.PathWithNamespace)
777 if err != nil {
778 return targetLookup{err: fmt.Errorf("could not resolve project %s on %s: %w", meta.PathWithNamespace, meta.Host, err)}
779 }
780 return targetLookup{target: target{client: client, project: project}}
783// sessionRequest is the body for POST /ai_agent/sessions.
784type sessionRequest struct {
785 AgentType string `json:"agent_type"`
786 AgentIdentityID int `json:"agent_identity_id,omitempty"`
787 SyncType string `json:"sync_type"`
788 Goal string `json:"goal,omitempty"`
789 IdempotencyKey string `json:"idempotency_key"`
790 StartedAt string `json:"started_at,omitempty"`
791 GlabVersion string `json:"glab_version,omitempty"`
792 AgentVersion string `json:"agent_version,omitempty"`
795// sessionResponse is the response from POST /ai_agent/sessions.
796type sessionResponse struct {
797 ID int `json:"id"`
800const governanceNotEnabled = "AI Governance is not turned on for this project. " +
801 "Ask a group Owner or administrator to turn it on. It is not available for personal projects on GitLab.com."
803// syncTypeFor reports which path is syncing the session. GitLab keeps the value
804// sent when it creates the session. The hooks are the only callers that pass
805// --silent without --all.
806func syncTypeFor(opts *options) string {
807 switch {
808 case opts.all:
809 return "fallback"
810 case opts.silent:
811 return "hook"
812 default:
813 return "manual"
814 }
817// ensureSession creates a session on GitLab or returns the existing one via idempotency key.
818func ensureSession(ctx context.Context, client *api.Client, projectID int64, identityID int, sessionID, agentType, syncType, glabVersion string, data *sessionData) (int, error) {
819 if agentType == "" {
820 agentType = "unknown"
821 }
822 reqBody := sessionRequest{
823 AgentType: agentType,
824 SyncType: syncType,
825 IdempotencyKey: sessionID,
826 GlabVersion: sessionVersion(strings.TrimPrefix(glabVersion, "v")),
827 AgentVersion: sessionVersion(data.AgentVersion),
828 }
830 if identityID > 0 {
831 reqBody.AgentIdentityID = identityID
832 }
834 if data.Goal != "" {
835 reqBody.Goal = data.Goal
836 }
838 if !data.StartedAt.IsZero() && time.Since(data.StartedAt) < 30*24*time.Hour {
839 reqBody.StartedAt = data.StartedAt.UTC().Format(time.RFC3339)
840 }
842 req, err := client.Lab().NewRequest(
843 http.MethodPost,
844 fmt.Sprintf("projects/%d/ai_agent/sessions", projectID),
845 reqBody,
846 []gitlab.RequestOptionFunc{gitlab.WithContext(ctx), api.WithSafeRetries()},
847 )
848 if err != nil {
849 return 0, fmt.Errorf("could not create session request: %w", err)
850 }
852 var resp sessionResponse
853 if _, err := client.Lab().Do(req, &resp); err != nil {
854 return 0, fmt.Errorf("could not create session: %w", err)
855 }
857 return resp.ID, nil
860// maxVersionLength is the longest version GitLab accepts.
861const maxVersionLength = 255
863// sessionVersion returns v as GitLab accepts it, or "" to leave it out. GitLab
864// rejects the whole session over a version it does not accept, and the
865// versions are only informational.
866func sessionVersion(v string) string {
867 v = strings.TrimSpace(v)
868 if utf8.RuneCountInString(v) > maxVersionLength {
869 return ""
870 }
871 return v
874// auditEventRequest is a single audit event.
875type auditEventRequest struct {
876 EventName string `json:"event_name"`
877 CloudEventID string `json:"cloud_event_id"`
878 OccurredAt string `json:"occurred_at"`
879 Details map[string]any `json:"details"`
882// auditEventsRequest is the body for POST /ai_agent/audit_events.
883type auditEventsRequest struct {
884 SessionID int `json:"session_id"`
885 Events []auditEventRequest `json:"events"`
888const (
889 // maxEventsPerRequest is the most events GitLab accepts in one request.
890 maxEventsPerRequest = 500
891 // maxElementsPerRequest keeps a request under the 5,000 JSON elements that
892 // older GitLab versions accept for audit events, with some margin.
893 maxElementsPerRequest = 4500
894 // maxBytesPerRequest keeps a request under the 5 MB body that GitLab
895 // accepts for audit events, with some margin.
896 maxBytesPerRequest = 4 * 1024 * 1024
899// jsonLimitErrors are the errors GitLab's JSON validation returns for a
900// request over one of its limits.
901var jsonLimitErrors = []string{
902 "Too many total parameters",
903 "JSON body too large",
904 "Array parameter too large",
905 "Hash parameter too large",
906 "Parameters nested too deeply",
909// auditEventPoster posts a session's audit events to GitLab.
910type auditEventPoster struct {
911 client *api.Client
912 projectID int64
913 sessionID int
914 opts *options
917// post posts events in batches GitLab accepts, and returns how many events
918// were too large for GitLab to accept. If a batch fails, earlier batches stay
919// posted; GitLab deduplicates them by cloud_event_id when they are retried.
920func (p auditEventPoster) post(ctx context.Context, events []auditEventRequest) (int, error) {
921 tooLarge := 0
922 for _, batch := range auditEventBatches(events) {
923 n, err := p.postSplitting(ctx, batch)
924 tooLarge += n
925 if err != nil {
926 return tooLarge, err
927 }
928 }
929 return tooLarge, nil
932// auditEventBatches splits events into batches of at most maxEventsPerRequest
933// events, maxElementsPerRequest JSON elements and maxBytesPerRequest bytes.
934func auditEventBatches(events []auditEventRequest) [][]auditEventRequest {
935 var batches [][]auditEventRequest
936 var batch []auditEventRequest
937 elements, size := auditEventsRequestElements, auditEventsRequestBytes
938 for _, event := range events {
939 n := auditEventElements(event)
940 // Counts a comma for every event, one more than the request has.
941 b := encodedLen(event) + 1
942 full := elements+n > maxElementsPerRequest || size+b > maxBytesPerRequest
943 if len(batch) == maxEventsPerRequest || (len(batch) > 0 && full) {
944 batches = append(batches, batch)
945 batch, elements, size = nil, auditEventsRequestElements, auditEventsRequestBytes
946 }
947 batch = append(batch, event)
948 elements += n
949 size += b
950 }
951 if len(batch) > 0 {
952 batches = append(batches, batch)
953 }
954 return batches
957// postSplitting posts events, and posts each half separately if GitLab finds
958// the request over one of its JSON limits. An event over a limit on its own
959// can never be posted, so it is skipped and counted rather than blocking the
960// rest of the session.
961//
962// A hook returns the error instead when the fallback sync is installed. It
963// leaves the cursor where it is, so the fallback sync splits the batch and
964// records any skipped events in the status file that glab minder doctor reads,
965// without the hook using up the rate limit.
966func (p auditEventPoster) postSplitting(ctx context.Context, events []auditEventRequest) (int, error) {
967 err := p.postBatch(ctx, events)
968 if !requestTooLarge(err) || (syncTypeFor(p.opts) == "hook" && fallbackSyncInstalled()) {
969 return 0, err
970 }
971 if len(events) == 1 {
972 dbg.Debugf("skipping audit event %s that is too large for GitLab: %v", events[0].CloudEventID, err)
973 return 1, nil
974 }
975 half := len(events) / 2
976 tooLarge, err := p.postSplitting(ctx, events[:half])
977 if err != nil {
978 return tooLarge, err
979 }
980 n, err := p.postSplitting(ctx, events[half:])
981 return tooLarge + n, err
984// fallbackSyncInstalled reports whether the fallback sync job is installed for
985// this user. A job whose files exist but cannot be read counts as installed.
986func fallbackSyncInstalled() bool {
987 home, err := os.UserHomeDir()
988 if err != nil {
989 return false
990 }
991 _, err = fallbacksync.InstalledBinary(runtime.GOOS, home)
992 return !errors.Is(err, fallbacksync.ErrNotInstalled) && !errors.Is(err, fallbacksync.ErrUnsupportedOS)
995func requestTooLarge(err error) bool {
996 var resp *gitlab.ErrorResponse
997 if !errors.As(err, &resp) || resp.StatusCode != http.StatusBadRequest {
998 return false
999 }
1000 return slices.ContainsFunc(jsonLimitErrors, func(msg string) bool {
1001 return strings.Contains(resp.Message, msg)
1002 })
1005const (
1006 // maxRateLimitWaits is how many times one request waits out GitLab's rate
1007 // limit before the sync gives up until its next run.
1008 maxRateLimitWaits = 5
1009 // maxRateLimitWait caps a single wait. GitLab asks for 60 seconds.
1010 maxRateLimitWait = 90 * time.Second
1011 // maxRateLimitWaitPerRun keeps one large session from holding up a run,
1012 // and the other sessions in it, for long.
1013 maxRateLimitWaitPerRun = 20 * time.Minute
1016// postBatch posts events in one request. The API client gives up on GitLab's
1017// rate limit after a few seconds because it ignores Retry-After, so a sync
1018// other than a hook, which must finish quickly, waits as GitLab asks.
1019func (p auditEventPoster) postBatch(ctx context.Context, events []auditEventRequest) error {
1020 for waits := 0; ; waits++ {
1021 err := p.postBatchOnce(ctx, events)
1022 wait, limited := rateLimitWait(err)
1023 if !limited || waits == maxRateLimitWaits || syncTypeFor(p.opts) == "hook" ||
1024 p.opts.rateLimitWaited+wait > maxRateLimitWaitPerRun {
1025 return err
1027 p.opts.rateLimitWaited += wait
1028 if !p.opts.silent {
1029 p.opts.io.LogInfof("GitLab rate limit reached, retrying in %s\n", wait)
1031 if err := p.opts.wait(ctx, wait); err != nil {
1032 return err
1037// rateLimitWait reports whether err is GitLab's rate limit, and how long it
1038// asks the client to wait.
1039func rateLimitWait(err error) (time.Duration, bool) {
1040 var resp *gitlab.ErrorResponse
1041 if !errors.As(err, &resp) || resp.StatusCode != http.StatusTooManyRequests {
1042 return 0, false
1044 wait := time.Minute
1045 if resp.Response != nil {
1046 if seconds, err := strconv.Atoi(resp.Response.Header.Get("Retry-After")); err == nil && seconds >= 0 {
1047 wait = min(time.Duration(seconds)*time.Second, maxRateLimitWait)
1050 return wait, true
1053func (p auditEventPoster) postBatchOnce(ctx context.Context, events []auditEventRequest) error {
1054 reqBody := auditEventsRequest{
1055 SessionID: p.sessionID,
1056 Events: events,
1059 req, err := p.client.Lab().NewRequest(
1060 http.MethodPost,
1061 fmt.Sprintf("projects/%d/ai_agent/audit_events", p.projectID),
1062 reqBody,
1063 []gitlab.RequestOptionFunc{gitlab.WithContext(ctx), api.WithSafeRetries()},
1065 if err != nil {
1066 return fmt.Errorf("could not create audit events request: %w", err)
1069 _, err = p.client.Lab().Do(req, nil)
1070 return err
1073// completeRequest is the body for PATCH /ai_agent/sessions/:id.
1074type completeRequest struct {
1075 Status string `json:"status"`
1076 Jsonlsha256 string `json:"jsonl_sha256,omitempty"`
1079// completeSession marks a session as completed on GitLab.
1080func completeSession(ctx context.Context, client *api.Client, projectID int64, sessionID int, sha256 string) error {
1081 reqBody := completeRequest{
1082 Status: "completed",
1083 Jsonlsha256: sha256,
1086 req, err := client.Lab().NewRequest(
1087 http.MethodPatch,
1088 fmt.Sprintf("projects/%d/ai_agent/sessions/%d", projectID, sessionID),
1089 reqBody,
1090 []gitlab.RequestOptionFunc{gitlab.WithContext(ctx), api.WithSafeRetries()},
1092 if err != nil {
1093 return fmt.Errorf("could not create complete request: %w", err)
1096 if _, err := client.Lab().Do(req, nil); err != nil {
1097 return fmt.Errorf("could not complete session: %w", err)
1100 return nil
1103// deterministicUUID derives a name-based UUIDv8 from SHA-256, the RFC 9562
1104// replacement for SHA-1 UUIDv5, which FIPS 140-3 mode rejects.
1105func deterministicUUID(toolCallID string) string {
1106 return uuid.NewHash(sha256.New(), uuid.NameSpaceDNS, []byte("gaig.gitlab.com/"+toolCallID), 8).String()
Diagnostics9 git calls · 303 ms
CallStatusSizeTime0303 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
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 KiB · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
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:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
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
fetchtree:02001.8 KiB · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=1
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=261
git.response.cache=HIT
git.response.duration_ms=2
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=139
git.response.cache=HIT
git.response.duration_ms=2
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=638
git.response.cache=HIT
git.response.duration_ms=2
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
fetch20012 KiB291 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=291
git.response.bytes=11887
git.response.cache=MISS
git.response.duration_ms=291
git.fetch.wants=b41b8cadd45262a48e89421d6b3c03127b2d00a1
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=11887
git.pkt.payload.max=11860
git.sideband.band1.bytes=11860
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
a5e2d1375dffcf3a
Request
931e4b39…
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