main
ply4 git calls272 ms43 KiB2 cachedprotocol v2
146 lines6.0 KiBRaw
1// Open-loop probe schedule. Issue at the policy period even while requests are
2// outstanding. At `maxInFlight`, record a shed and keep the clock. Issuing stops at
3// the wall deadline; probes still in flight then get `graceMs` (the probe's own
4// timeout) to answer, and the dwell does not wait out a hung fetch past that.
5import type { StallSource } from './client-health.ts'
6import type { ProbeOutcome } from './probe.ts'
7import { mapGet } from '../../src/absent.ts'
9export type ProbeClock = {
10 now(): number
11 sleep(ms: number): Promise<void>
14/** One probe the scheduler has started. The promise resolves with its outcome. */
15export type ProbeStart = {
16 readonly id: string
17 readonly promise: Promise<ProbeOutcome>
20export type ProbeSchedule = {
21 readonly clock: ProbeClock
22 readonly dwellMs: number
23 readonly periodMs: number
24 readonly maxInFlight: number
25 readonly batch: number
26 /**
27 * How long probes in flight at the deadline may still answer. Without it the last tick's probes (issued a few ms
28 * before the deadline, ~100 ms healthy latency) were always counted timed_out: 2-6 per 2,000-probe window against a
29 * 0.13% cap, which failed or held 4 of 6 ramps on 2026-11-06 with 0 server errors (ids 1995-2000, 1996-2000, …).
30 */
31 readonly graceMs: number
32 /**
33 * The client's own stalls (client-health.ts). Time the client spent stalled is added back to the dwell, missed ticks
34 * are skipped rather than burst, a probe in flight across a stall is `stalled` (not lost), and each stall in the
35 * window adds one `stalled` marker so the judge knows the client was unhealthy. NO_STALLS outside a run.
36 */
37 readonly health: StallSource
38 /**
39 * After a stall, keep issuing past the dwell until `minReal` real samples (responded + lost) exist, but never more than
40 * `maxMs` past the dwell (CLIENT_MAX_EXTENSION_MS). Without a stall the dwell is exactly `dwellMs`.
41 */
42 readonly extension: { readonly maxMs: number; readonly minReal: number }
43 issue(seq: number): ProbeStart
44 shed(seq: number): ProbeOutcome
45 stop(): void
48/**
49 * Tick until the wall deadline. A full in-flight set sheds this tick instead of
50 * awaiting it. Outstanding probes at the deadline are `timed_out` here; `stop`
51 * aborts them so the process does not keep the sockets.
52 */
53export async function runProbeSchedule(input: ProbeSchedule): Promise<readonly ProbeOutcome[]> {
54 if (input.periodMs <= 0) throw new Error('probe period must be > 0')
55 if (input.batch <= 0) throw new Error('probe batch must be > 0')
56 const start = input.clock.now()
57 const outcomes: ProbeOutcome[] = []
58 const inflight = new Map<number, string>()
59 const issuedAt = new Map<number, number>()
60 const pending = new Map<number, Promise<ProbeOutcome>>()
61 let nextAt = start
62 let seq = 0
63 let real = 0
64 let stalls = 0
65 const crossedStall = (id: number, at: number): boolean => {
66 // A resumed process may settle a probe before any timer runs: look at the clocks first.
67 input.health.check()
68 const from = issuedAt.get(id)
69 return typeof from === 'number' && input.health.during(from, at).length > 0
70 }
71 const finish = (id: number, outcome: ProbeOutcome): void => {
72 const held = mapGet(inflight, id)
73 if (held.tag === 'none') return
74 const probeId = held.value
75 inflight.delete(id)
76 pending.delete(id)
77 if (outcome.kind === 'lost' && crossedStall(id, input.clock.now())) {
78 outcomes.push({ kind: 'stalled', id: probeId })
79 } else {
80 if (outcome.kind === 'responded' || outcome.kind === 'lost') real += 1
81 outcomes.push(outcome)
82 }
83 issuedAt.delete(id)
84 }
85 const deadline = (): number => {
86 const stalled = input.health.stalledMs(start, input.clock.now())
87 if (stalled <= 0) return start + input.dwellMs
88 const cap = start + input.dwellMs + input.extension.maxMs
89 const stretched = start + input.dwellMs + stalled
90 // Past the stretched dwell, keep going until enough real samples exist, up to the cap.
91 if (input.clock.now() >= stretched && real + inflight.size < input.extension.minReal) return cap
92 return Math.min(stretched, cap)
93 }
94 while (input.clock.now() < deadline()) {
95 input.health.check()
96 const seen = input.health.during(start, input.clock.now())
97 if (seen.length > stalls) {
98 for (const stall of seen.slice(stalls)) outcomes.push({ kind: 'stalled', id: `client-stall ${stall.from}-${stall.to} ${stall.ms}ms` })
99 stalls = seen.length
100 // Skip the ticks the stall swallowed instead of bursting them into sheds.
101 nextAt = input.clock.now()
102 }
103 const now = input.clock.now()
104 if (now < nextAt) {
105 const wait = Math.min(nextAt, deadline()) - now
106 if (wait > 0) await input.clock.sleep(wait)
107 continue
108 }
109 if (inflight.size + input.batch > input.maxInFlight) {
110 for (let index = 0; index < input.batch; index += 1) {
111 seq += 1
112 outcomes.push(input.shed(seq))
113 }
114 } else {
115 for (let index = 0; index < input.batch; index += 1) {
116 seq += 1
117 const id = seq
118 const started = input.issue(id)
119 inflight.set(id, started.id)
120 issuedAt.set(id, input.clock.now())
121 pending.set(id, started.promise)
122 void started.promise.then(outcome => {
123 finish(id, outcome)
124 })
125 }
126 }
127 nextAt += input.periodMs
128 }
129 if (inflight.size > 0 && input.graceMs > 0) {
130 await Promise.race([Promise.allSettled([...pending.values()]), input.clock.sleep(input.graceMs)])
131 // Let the settled probes' `finish` callbacks run before the rest are counted.
132 await Promise.resolve()
133 }
134 input.stop()
135 input.health.check()
136 const end = input.clock.now()
137 // A stall the loop did not see (it ended while stalled) still marks the window.
138 for (const stall of input.health.during(start, end).slice(stalls)) {
139 outcomes.push({ kind: 'stalled', id: `client-stall ${stall.from}-${stall.to} ${stall.ms}ms` })
140 }
141 for (const [id, probeId] of [...inflight]) {
142 inflight.delete(id)
143 outcomes.push(crossedStall(id, end) ? { kind: 'stalled', id: probeId } : { kind: 'lost', id: probeId, reason: 'timed_out' })
144 }
145 return outcomes
Diagnostics4 git calls · 272 ms
CallStatusSizeTime0272 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=4
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 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=41349
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2002.3 KiB266 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=266
git.response.bytes=2327
git.response.cache=MISS
git.response.duration_ms=266
git.fetch.wants=10cf33df2b5ffaf425ac1d7086e6a23b48c0f0c8
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2327
git.pkt.payload.max=2306
git.sideband.band1.bytes=2305
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2f0df1fa7fda9
Request
e7b6b34d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format