GitLabgitlab-org

cli

main
ply9 git calls253 ms104 KiB6 cachedprotocol v2
686 lines21 KiBRaw
1// Package fallbacksync manages the scheduled job that runs
2// `glab minder audit sync --all` when agent hooks fail to sync a session.
3package fallbacksync
5import (
6 "bytes"
7 "context"
8 "encoding/json"
9 "encoding/xml"
10 "errors"
11 "fmt"
12 "io"
13 "io/fs"
14 "os"
15 "os/exec"
16 "path/filepath"
17 "strconv"
18 "strings"
19 "time"
21 "gitlab.com/gitlab-org/cli/internal/api"
22 "gitlab.com/gitlab-org/cli/internal/cmdutils"
23 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/claudehooks"
24 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/gaig"
25 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/opencodeplugin"
26 "gitlab.com/gitlab-org/cli/internal/commands/version"
29const (
30 launchdLabel = "com.gitlab.glab-govern-audit-sync"
31 systemdServiceName = "glab-govern-audit-sync.service"
32 systemdTimerName = "glab-govern-audit-sync.timer"
34 // Interval is how often the scheduled job runs.
35 Interval = 30 * time.Minute
38// ErrUnsupportedOS is returned on platforms without launchd or systemd.
39var ErrUnsupportedOS = errors.New("fallback periodic sync is supported only on macOS and Linux")
41// Unit is a file that makes up the scheduled job.
42type Unit struct {
43 Path string
44 Content string
47// Job is what the scheduled job runs.
48type Job struct {
49 GlabPath string
50 // ConfigDir is passed to the job as GLAB_CONFIG_DIR. launchd and systemd
51 // start jobs without the user's shell environment, so without it a
52 // custom GLAB_CONFIG_DIR or XDG_CONFIG_HOME would point the job at a
53 // different directory from the hooks.
54 ConfigDir string
57// Supported reports whether the scheduled job can be installed on goos.
58func Supported(goos string) bool {
59 return goos == "darwin" || goos == "linux"
62// Units returns the files that define the scheduled job on goos.
63func Units(goos, home string, job Job) ([]Unit, error) {
64 switch goos {
65 case "darwin":
66 return []Unit{{Path: launchdPlistPath(home), Content: launchdPlist(job)}}, nil
67 case "linux":
68 dir := systemdDir(home)
69 return []Unit{
70 {Path: filepath.Join(dir, systemdServiceName), Content: systemdService(job)},
71 {Path: filepath.Join(dir, systemdTimerName), Content: systemdTimer()},
72 }, nil
73 default:
74 return nil, ErrUnsupportedOS
75 }
78// Description names the scheduled job for prompts and help text.
79func Description(goos string) string {
80 switch goos {
81 case "darwin":
82 return fmt.Sprintf("a launchd agent (%s)", launchdPlistPath("~"))
83 case "linux":
84 return fmt.Sprintf("a systemd user timer (%s)", filepath.Join(systemdDir("~"), systemdTimerName))
85 default:
86 return "a scheduled job"
87 }
90func launchdPlistPath(home string) string {
91 return filepath.Join(home, "Library", "LaunchAgents", launchdLabel+".plist")
94func systemdDir(home string) string {
95 return filepath.Join(home, ".config", "systemd", "user")
98func xmlEscape(s string) string {
99 var b strings.Builder
100 _ = xml.EscapeText(&b, []byte(s))
101 return b.String()
104func launchdPlist(job Job) string {
105 return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
106<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
107<plist version="1.0">
108<dict>
109 <key>Label</key>
110 <string>%s</string>
111 <key>ProgramArguments</key>
112 <array>
113 <string>%s</string>
114 <string>minder</string>
115 <string>audit</string>
116 <string>sync</string>
117 <string>--all</string>
118 <string>--silent</string>
119 </array>
120 <key>EnvironmentVariables</key>
121 <dict>
122 <key>GLAB_CONFIG_DIR</key>
123 <string>%s</string>
124 </dict>
125 <key>StartInterval</key>
126 <integer>%d</integer>
127 <key>RunAtLoad</key>
128 <false/>
129</dict>
130</plist>
131`, launchdLabel, xmlEscape(job.GlabPath), xmlEscape(job.ConfigDir), int(Interval.Seconds()))
134// systemdQuoter escapes a value for a double-quoted systemd unit setting.
135// systemd expands % specifiers even within quotes.
136var systemdQuoter = strings.NewReplacer(`\`, `\\`, `"`, `\"`, "%", "%%")
138var systemdUnquoter = strings.NewReplacer(`\\`, `\`, `\"`, `"`, "%%", "%")
140func systemdService(job Job) string {
141 return fmt.Sprintf(`[Unit]
142Description=GitLab AI agent governance fallback sync
144[Service]
145Type=oneshot
146Environment="GLAB_CONFIG_DIR=%s"
147ExecStart="%s" minder audit sync --all --silent
148`, systemdQuoter.Replace(job.ConfigDir), systemdQuoter.Replace(job.GlabPath))
151func systemdTimer() string {
152 return fmt.Sprintf(`[Unit]
153Description=GitLab AI agent governance fallback sync timer
155[Timer]
156OnBootSec=5min
157OnUnitActiveSec=%dmin
159[Install]
160WantedBy=timers.target
161`, int(Interval.Minutes()))
164// Install writes the job's files and loads the job, replacing any existing one.
165func Install(ctx context.Context, executor cmdutils.Executor, goos, home string, job Job, uid int) error {
166 units, err := Units(goos, home, job)
167 if err != nil {
168 return err
169 }
170 for _, u := range units {
171 if err := os.MkdirAll(filepath.Dir(u.Path), 0o755); err != nil {
172 return fmt.Errorf("could not create %s: %w", filepath.Dir(u.Path), err)
173 }
174 if err := os.WriteFile(u.Path, []byte(u.Content), 0o644); err != nil {
175 return fmt.Errorf("could not write %s: %w", u.Path, err)
176 }
177 }
179 if err := load(ctx, executor, goos, units, uid); err != nil {
180 // Leaving the files would make doctor report a half-installed job,
181 // for example where there is no user launchd domain or systemd bus.
182 for _, u := range units {
183 if rmErr := os.Remove(u.Path); rmErr != nil && !errors.Is(rmErr, fs.ErrNotExist) {
184 err = errors.Join(err, rmErr)
185 }
186 }
187 return err
188 }
189 return nil
192func load(ctx context.Context, executor cmdutils.Executor, goos string, units []Unit, uid int) error {
193 switch goos {
194 case "darwin":
195 // bootstrap fails if the label is already loaded, and bootout fails if it is not.
196 _, _ = executor.ExecWithCombinedOutput(ctx, "launchctl", []string{"bootout", launchdTarget(uid)}, nil)
197 return run(ctx, executor, "launchctl", "bootstrap", fmt.Sprintf("gui/%d", uid), units[0].Path)
198 default:
199 if err := run(ctx, executor, "systemctl", "--user", "daemon-reload"); err != nil {
200 return err
201 }
202 return run(ctx, executor, "systemctl", "--user", "enable", "--now", systemdTimerName)
203 }
206// Uninstall unloads the job and removes its files. It reports whether any
207// files were removed.
208func Uninstall(ctx context.Context, executor cmdutils.Executor, goos, home string, uid int) (bool, error) {
209 units, err := Units(goos, home, Job{})
210 if err != nil {
211 return false, err
212 }
214 // Unloading fails when the job is not loaded, which is the state we want.
215 switch goos {
216 case "darwin":
217 _, _ = executor.ExecWithCombinedOutput(ctx, "launchctl", []string{"bootout", launchdTarget(uid)}, nil)
218 default:
219 _, _ = executor.ExecWithCombinedOutput(ctx, "systemctl", []string{"--user", "disable", "--now", systemdTimerName}, nil)
220 }
222 removed := false
223 for _, u := range units {
224 err := os.Remove(u.Path)
225 switch {
226 case err == nil:
227 removed = true
228 case errors.Is(err, fs.ErrNotExist):
229 default:
230 return removed, fmt.Errorf("could not remove %s: %w", u.Path, err)
231 }
232 }
234 if removed && goos == "linux" {
235 if err := run(ctx, executor, "systemctl", "--user", "daemon-reload"); err != nil {
236 return removed, err
237 }
238 }
239 return removed, nil
242func launchdTarget(uid int) string {
243 return fmt.Sprintf("gui/%d/%s", uid, launchdLabel)
246func run(ctx context.Context, executor cmdutils.Executor, name string, args ...string) error {
247 if out, err := executor.ExecWithCombinedOutput(ctx, name, args, nil); err != nil {
248 return fmt.Errorf("%s %s: %w\n%s", name, strings.Join(args, " "), err, out)
249 }
250 return nil
253// ErrNotInstalled is returned by ReadInstalled and InstalledBinary when the
254// job's files are absent.
255var ErrNotInstalled = errors.New("fallback periodic sync is not installed")
257// InstalledBinary returns the glab path that the installed job runs.
258func InstalledBinary(goos, home string) (string, error) {
259 job, err := ReadInstalled(goos, home)
260 return job.GlabPath, err
263// Installed describes the installed job.
264type Installed struct {
265 // GlabPath is the glab that the job runs.
266 GlabPath string
267 // Legacy reports whether the job runs glab govern, as jobs that glab
268 // versions before the rename to glab minder installed do.
269 Legacy bool
272// ReadInstalled reads the installed job.
273func ReadInstalled(goos, home string) (Installed, error) {
274 units, err := Units(goos, home, Job{})
275 if err != nil {
276 return Installed{}, err
277 }
278 data, err := os.ReadFile(units[0].Path)
279 if errors.Is(err, fs.ErrNotExist) {
280 return Installed{}, ErrNotInstalled
281 }
282 if err != nil {
283 return Installed{}, err
284 }
286 if goos == "darwin" {
287 path, err := plistProgram(data)
288 return Installed{GlabPath: path, Legacy: strings.Contains(string(data), "<string>govern</string>")}, err
289 }
290 for line := range strings.Lines(string(data)) {
291 rest, ok := strings.CutPrefix(line, `ExecStart="`)
292 if !ok {
293 continue
294 }
295 if path, ok := cutQuoted(rest); ok {
296 legacy := strings.HasPrefix(rest[len(path)+1:], " govern audit sync ")
297 return Installed{GlabPath: systemdUnquoter.Replace(path), Legacy: legacy}, nil
298 }
299 break
300 }
301 return Installed{}, fmt.Errorf("could not find ExecStart in %s", units[0].Path)
304// cutQuoted returns s up to its first unescaped double quote.
305func cutQuoted(s string) (string, bool) {
306 for i := 0; i < len(s); i++ {
307 switch s[i] {
308 case '\\':
309 i++
310 case '"':
311 return s[:i], true
312 }
313 }
314 return "", false
317func plistProgram(data []byte) (string, error) {
318 var doc struct {
319 Dict struct {
320 Keys []string `xml:"key"`
321 Arrays []struct {
322 Strings []string `xml:"string"`
323 } `xml:"array"`
324 } `xml:"dict"`
325 }
326 if err := xml.Unmarshal(data, &doc); err != nil {
327 return "", fmt.Errorf("could not parse plist: %w", err)
328 }
329 if len(doc.Dict.Arrays) == 0 || len(doc.Dict.Arrays[0].Strings) == 0 {
330 return "", errors.New("plist has no ProgramArguments")
331 }
332 return doc.Dict.Arrays[0].Strings[0], nil
335// JobState is what the system reports about the installed job.
336type JobState struct {
337 Loaded bool
338 // Ran reports whether the job has finished at least once since it was loaded.
339 Ran bool
340 ExitCode int
343// State asks launchd or systemd whether the job is loaded and how its last
344// run exited. It catches runs that fail before they can write a Status, such
345// as a glab binary that does not support --all.
346func State(ctx context.Context, executor cmdutils.Executor, goos string, uid int) (JobState, error) {
347 switch goos {
348 case "darwin":
349 out, err := executor.ExecWithCombinedOutput(ctx, "launchctl", []string{"print", launchdTarget(uid)}, nil)
350 if exited(err) {
351 // launchctl print exits non-zero when the label is not loaded.
352 return JobState{}, nil
353 }
354 if err != nil {
355 return JobState{}, fmt.Errorf("launchctl print: %w", err)
356 }
357 return launchdState(string(out)), nil
358 case "linux":
359 _, err := executor.ExecWithCombinedOutput(ctx, "systemctl", []string{"--user", "is-active", "--quiet", systemdTimerName}, nil)
360 if exited(err) {
361 return JobState{}, nil
362 }
363 if err != nil {
364 return JobState{}, fmt.Errorf("systemctl --user is-active: %w", err)
365 }
366 out, err := executor.ExecWithCombinedOutput(ctx, "systemctl", []string{"--user", "show", systemdServiceName, "--property=ExecMainStartTimestampMonotonic,ExecMainStatus"}, nil)
367 if err != nil {
368 return JobState{}, fmt.Errorf("systemctl --user show %s: %w\n%s", systemdServiceName, err, out)
369 }
370 return systemdState(string(out)), nil
371 default:
372 return JobState{}, ErrUnsupportedOS
373 }
376// exited reports whether err is a command exiting with a non-zero status, as
377// opposed to the command failing to start.
378func exited(err error) bool {
379 var exitErr *exec.ExitError
380 return errors.As(err, &exitErr)
383func launchdState(out string) JobState {
384 state := JobState{Loaded: true}
385 for line := range strings.Lines(out) {
386 value, ok := strings.CutPrefix(strings.TrimSpace(line), "last exit code = ")
387 if !ok {
388 continue
389 }
390 // The value is "(never exited)" before the first run.
391 first, _, _ := strings.Cut(value, " ")
392 if code, err := strconv.Atoi(first); err == nil {
393 state.Ran = true
394 state.ExitCode = code
395 }
396 break
397 }
398 return state
401func systemdState(out string) JobState {
402 state := JobState{Loaded: true}
403 for line := range strings.Lines(out) {
404 key, value, _ := strings.Cut(strings.TrimSpace(line), "=")
405 switch key {
406 case "ExecMainStartTimestampMonotonic":
407 state.Ran = value != "" && value != "0"
408 case "ExecMainStatus":
409 state.ExitCode, _ = strconv.Atoi(value)
410 }
411 }
412 return state
415// Status records the outcome of the most recent `glab minder audit sync --all` run.
416type Status struct {
417 StartedAt time.Time `json:"started_at"`
418 FinishedAt time.Time `json:"finished_at"`
419 Paused []string `json:"paused,omitempty"`
420 // GovernanceNotEnabled lists the projects, as host/path, whose sessions
421 // were not synced because GitLab has AI agent governance turned off for
422 // them. These are expected for a user who works in many projects, so they
423 // are not errors.
424 GovernanceNotEnabled []string `json:"governance_not_enabled,omitempty"`
425 // ProjectNotFound lists the projects, as host/path, that GitLab answered
426 // 404 for: deleted, renamed, or not visible to the user. Like
427 // GovernanceNotEnabled, these are expected and are not errors.
428 ProjectNotFound []string `json:"project_not_found,omitempty"`
429 // NoToken lists the GitLab hosts the run found no token for and could not
430 // sync a session on. It looked up their projects anonymously, so their
431 // private projects are in ProjectNotFound too.
432 NoToken []string `json:"no_token,omitempty"`
433 // AgentTypeNotSupported lists agent types a GitLab host does not accept
434 // yet, as "<agent> on <host>". Their sessions are not uploaded, then or
435 // after an upgrade.
436 AgentTypeNotSupported []string `json:"agent_type_not_supported,omitempty"`
437 // Skipped explains why discovered sessions were not synced, for example
438 // a Cursor workspace that matches several directories.
439 Skipped []string `json:"skipped,omitempty"`
440 SessionsSynced int `json:"sessions_synced"`
441 SessionsCompleted int `json:"sessions_completed"`
442 EventsPosted int `json:"events_posted"`
443 // EventsTooLarge counts events skipped because GitLab cannot accept them.
444 EventsTooLarge int `json:"events_too_large,omitempty"`
445 Errors []string `json:"errors,omitempty"`
448// ErrNoStatus is returned by ReadStatus when no run has been recorded.
449var ErrNoStatus = errors.New("no fallback sync run recorded")
451func statusPath() string {
452 return filepath.Join(gaig.StateDir(), "fallback-sync-status.json")
455// WriteStatus replaces the recorded status of the last run.
456func WriteStatus(s Status) error {
457 path := statusPath()
458 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
459 return err
460 }
461 data, err := json.Marshal(s) //nolint:forbidigo // writing to disk, not stdout
462 if err != nil {
463 return err
464 }
465 return os.WriteFile(path, data, 0o600)
468// ReadStatus returns the recorded status of the last run.
469func ReadStatus() (*Status, error) {
470 data, err := os.ReadFile(statusPath())
471 if errors.Is(err, fs.ErrNotExist) {
472 return nil, ErrNoStatus
473 }
474 if err != nil {
475 return nil, err
476 }
477 var s Status
478 if err := json.Unmarshal(data, &s); err != nil {
479 return nil, fmt.Errorf("could not parse fallback sync status: %w", err)
480 }
481 return &s, nil
484// DiscoverableAgents are the agents whose sessions the scheduled job can find
485// by scanning their transcripts, without hooks.
486var DiscoverableAgents = []string{"codex", "cursor"}
488// HookAgents are the agents that glab installs a hook or plugin for, which
489// syncs their sessions as they run.
490var HookAgents = []string{"claude-code", "opencode"}
492func discoveredAgentsPath() string {
493 return filepath.Join(gaig.StateDir(), "discovered-agents.json")
496func hookAgentsPath() string {
497 return filepath.Join(gaig.StateDir(), "hook-agents.json")
500// SetDiscoveredAgents replaces the agents whose sessions the scheduled job
501// discovers.
502func SetDiscoveredAgents(agents []string) error {
503 return writeJSON(discoveredAgentsPath(), agents)
506// agentsListError is an error reading a file in which setup lists the agents
507// it set up. Uninstalling removes those files.
508type agentsListError struct{ err error }
510func (e *agentsListError) Error() string { return e.err.Error() }
512func (e *agentsListError) Unwrap() error { return e.err }
514// AgentsReadFix says how to fix err, an error working out which agents are set
515// up. Uninstalling only helps when setup's own lists are unreadable, because
516// it doesn't change the Claude Code settings or the OpenCode plugin.
517func AgentsReadFix(err error) string {
518 if errors.As(err, new(*agentsListError)) {
519 return "fix it, or run 'glab minder setup --uninstall' to start again"
520 }
521 return "fix it, then run 'glab minder setup' again"
524// DiscoveredAgents returns the agents whose sessions the scheduled job
525// discovers. None are discovered until setup enables them.
526func DiscoveredAgents() ([]string, error) {
527 agents, _, err := readAgents(discoveredAgentsPath())
528 return agents, err
531// SetHookAgents records the agents setup installed a hook or plugin for.
532func SetHookAgents(agents []string) error {
533 return writeJSON(hookAgentsPath(), agents)
536// ForgetHookAgents forgets the agents recorded by SetHookAgents.
537func ForgetHookAgents() error {
538 return ignoreNotExist(os.Remove(hookAgentsPath()))
541// RecordedHookAgents returns the agents setup recorded with SetHookAgents, and
542// false if setup has recorded nothing. ResolvedHookAgents also covers glab
543// versions that did not record them.
544func RecordedHookAgents() ([]string, bool, error) {
545 return readAgents(hookAgentsPath())
548// ResolvedHookAgents returns the agents that setup has set up a hook or plugin
549// for. glab versions that did not record them are judged by what is installed:
550// the Claude Code hooks in the settings file at claudeSettings, and the
551// OpenCode plugin.
552func ResolvedHookAgents(claudeSettings string) ([]string, error) {
553 agents, recorded, err := RecordedHookAgents()
554 if err != nil || recorded {
555 return agents, err
556 }
558 agents = []string{}
559 claude, err := claudehooks.SyncHookInstalled(claudeSettings)
560 if err != nil {
561 return nil, err
562 }
563 if claude {
564 agents = append(agents, "claude-code")
565 }
566 plugin, err := opencodeplugin.Path()
567 if err != nil {
568 return nil, err
569 }
570 switch state, err := opencodeplugin.Check(plugin); {
571 case err != nil:
572 return nil, err
573 case state == opencodeplugin.Current, state == opencodeplugin.Outdated:
574 agents = append(agents, "opencode")
575 }
576 return agents, nil
579// DefaultHookAgents returns the agents a setup without --agents sets up: those
580// set up earlier, or Claude Code when no agent is set up at all.
581func DefaultHookAgents(setUp, discovered []string) []string {
582 if len(setUp) == 0 && len(discovered) == 0 {
583 return []string{"claude-code"}
584 }
585 return setUp
588// AgentSetup records when setup first set up an agent.
589type AgentSetup struct {
590 SetUpAt time.Time `json:"set_up_at"`
591 // History reports that the user agreed to upload the agent's activity
592 // from before SetUpAt too.
593 History bool `json:"history,omitempty"`
596// AgentSetups are the recorded setups, by agent. Agents set up by glab
597// versions that did not record them are missing.
598type AgentSetups map[string]AgentSetup
600// UploadsFrom returns the time from which agent's activity is uploaded, or the
601// zero time when there is no such limit: the user opted in to its history, or
602// setup did not record it. Uploading history for an agent set up before glab
603// recorded setups keeps what that user agreed to, until they run setup again.
604func (s AgentSetups) UploadsFrom(agent string) time.Time {
605 setup, ok := s[agent]
606 if !ok || setup.History {
607 return time.Time{}
608 }
609 return setup.SetUpAt
612func agentSetupsPath() string {
613 return filepath.Join(gaig.StateDir(), "agent-setups.json")
616// ReadAgentSetups returns the recorded agent setups.
617func ReadAgentSetups() (AgentSetups, error) {
618 setups := AgentSetups{}
619 if _, err := readJSON(agentSetupsPath(), &setups); err != nil {
620 return nil, err
621 }
622 return setups, nil
625// SetAgentSetups replaces the recorded agent setups.
626func SetAgentSetups(setups AgentSetups) error {
627 return writeJSON(agentSetupsPath(), setups)
630func readAgents(path string) ([]string, bool, error) {
631 var agents []string
632 recorded, err := readJSON(path, &agents)
633 if err != nil {
634 return nil, false, err
635 }
636 return agents, recorded, nil
639func writeJSON(path string, v any) error {
640 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
641 return err
642 }
643 data, err := json.Marshal(v) //nolint:forbidigo // writing to disk, not stdout
644 if err != nil {
645 return err
646 }
647 return gaig.WriteFileAtomic(path, data)
650func ignoreNotExist(err error) error {
651 if errors.Is(err, fs.ErrNotExist) {
652 return nil
653 }
654 return err
657// readJSON decodes the file at path into v, and reports false if there is no
658// such file.
659func readJSON(path string, v any) (bool, error) {
660 data, err := os.ReadFile(path)
661 if errors.Is(err, fs.ErrNotExist) {
662 return false, nil
663 }
664 if err != nil {
665 return false, &agentsListError{err}
666 }
667 if err := json.Unmarshal(data, v); err != nil {
668 return false, &agentsListError{fmt.Errorf("could not parse %s: %w", path, err)}
669 }
670 return true, nil
673// BuildVersion returns what `glab version` prints for the build described by
674// info.
675func BuildVersion(info api.BuildInfo) string {
676 return strings.TrimSpace(version.Scheme(info.Version, info.Commit))
679// BinaryVersion runs `glab version` with the glab binary at path.
680func BinaryVersion(ctx context.Context, executor cmdutils.Executor, path string) (string, error) {
681 var stdout bytes.Buffer
682 if err := executor.ExecWithIO(ctx, path, []string{"version"}, nil, nil, &stdout, io.Discard); err != nil {
683 return "", err
684 }
685 return strings.TrimSpace(stdout.String()), nil
Diagnostics9 git calls · 253 ms
CallStatusSizeTime0253 ms
discover200185 B3 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 KiB3 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=UPDATING
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 · 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=4273
git.response.cache=HIT
git.response.duration_ms=3
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 · hit3 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=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
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=3
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 · 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:0200273 B · hit3 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=273
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=5fa160737ad30857ff606d64de1d596bb211ac3d
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=273
git.pkt.payload.max=246
git.sideband.band1.bytes=246
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=246
git.pack.trailer=06dd39b7545811625e04a7645a0a64c9a62c99c6
Open pack map
fetchtree:0200174 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=238
git.response.bytes=174
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=c923ad47aec29523ab261d078f56fb7bf05eff40
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=174
git.pkt.payload.max=147
git.sideband.band1.bytes=147
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=147
git.pack.trailer=b1dcafdbc0347263de9030f8edc56e6165089115
Open pack map
fetch2006.5 KiB238 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=6698
git.response.cache=MISS
git.response.duration_ms=238
git.fetch.wants=7cba757fb3046cf404b3f5d8a195b6583632952e
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=6698
git.pkt.payload.max=6671
git.sideband.band1.bytes=6671
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
a5e290e69b5f24d3
Request
febdfebb…
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