main
ply4 git calls25 ms43 KiB3 cachedprotocol v2
176 lines6.9 KiBRaw
1import assert from 'node:assert/strict'
2import { readFileSync } from 'node:fs'
3import { mkdtemp, readFile } from 'node:fs/promises'
4import { tmpdir } from 'node:os'
5import { join } from 'node:path'
6import { test } from 'node:test'
7import { none } from '../src/option.ts'
8import { asRecord } from '../scripts/cd/json.ts'
9import { parseEvent, RunLog } from '../scripts/cd/log.ts'
10import { parsePolicy, type RolloutPolicy } from '../scripts/cd/policy.ts'
11import { accountProbeLoss, type ProbeOutcome } from '../scripts/cd/probe.ts'
12import {
13 classifyQuery,
14 recordQueryAttempt,
15 retryQuery,
16 type QueryCommand,
17} from '../scripts/cd/query-retry.ts'
18import { decideWithoutTelemetry, runRamp } from '../scripts/cd/ramp.ts'
20const TIMEOUT = 'APIError: timeout Envelope Error'
22function command(code: number, stderr: string, latencyMs: number, stdout = ''): QueryCommand {
23 return { code, stdout, stderr, latencyMs }
26function scripted(commands: readonly QueryCommand[]): () => Promise<QueryCommand> {
27 const pending = [...commands]
28 return async () => {
29 const next = pending.shift()
30 if (!next) throw new Error('no more query commands')
31 return next
32 }
35function policy(): RolloutPolicy {
36 const raw = JSON.parse(readFileSync(new URL('../scripts/cd/cd.policy.json', import.meta.url), 'utf8')) as Record<string, unknown>
37 raw.ingestPollMs = 0
38 const parsed = parsePolicy(JSON.stringify(raw)).policy
39 // A lone 100 step is not a loadable policy (ramp-only, 2026-11-08); the engine runs one here to isolate a single window.
40 // Frozen test clocks need the fixed ingest sleep, and these windows were written against onHarnessFault rollback.
41 return { ...parsed, steps: [{ percent: 100, dwellMs: 1 }], probe: { ...parsed.probe, onHarnessFault: 'rollback' } }
44function probes(count: number, status: number): ProbeOutcome[] {
45 const outcomes: ProbeOutcome[] = []
46 for (let index = 0; index < count; index += 1) {
47 outcomes.push({ kind: 'responded', id: `probe-${index}`, status, ray: none(), latencyMs: 50, version: none() })
48 }
49 return outcomes
52test('a timeout then a page is a sample, and the timeout latency is kept', async () => {
53 const bound = policy().telemetry.query
54 const waits: number[] = []
55 const result = await retryQuery(
56 { attempts: bound.attempts, backoffMs: bound.backoffMs },
57 {
58 once: scripted([
59 command(1, TIMEOUT, 80_000),
60 command(0, '', 400, '{"events":[]}'),
61 ]),
62 sleep: async ms => {
63 waits.push(ms)
64 },
65 },
66 )
67 assert.equal(result.kind, 'ok')
68 if (result.kind !== 'ok') return
69 assert.equal(result.stdout, '{"events":[]}')
70 assert.equal(result.attempts.length, 2)
71 const first = result.attempts[0]
72 const second = result.attempts[1]
73 if (!first || !second) throw new Error('missing attempt')
74 assert.equal(first.kind, 'transient')
75 assert.equal(first.latencyMs, 80_000)
76 assert.match(first.kind === 'transient' ? first.detail : '', /timeout Envelope Error/)
77 assert.equal(second.kind, 'ok')
78 assert.equal(second.latencyMs, 400)
79 assert.deepEqual(waits, [bound.backoffMs])
80 const lost = classifyQuery(command(1, 'APIError "timeout" Envelope Error', 80_000))
81 assert.equal(lost.kind, 'transient')
82})
84test('a persistent timeout records each attempt and does not fault a clean probe window', async () => {
85 const rollout = policy()
86 const bound = rollout.telemetry.query
87 const waits: number[] = []
88 const result = await retryQuery(
89 { attempts: bound.attempts, backoffMs: bound.backoffMs },
90 {
91 once: scripted([
92 command(1, TIMEOUT, 80_000),
93 command(1, TIMEOUT, 80_000),
94 command(1, TIMEOUT, 80_000),
95 command(0, '', 10, '{}'),
96 ]),
97 sleep: async ms => {
98 waits.push(ms)
99 },
100 },
101 )
102 assert.equal(result.kind, 'lost')
103 if (result.kind !== 'lost') return
104 assert.equal(result.attempts.length, bound.attempts)
105 assert.deepEqual(waits, [bound.backoffMs, bound.backoffMs * 2])
106 const dir = await mkdtemp(join(tmpdir(), 'ply-cd-query-'))
107 const ledger = join(dir, 'ledger.jsonl')
108 const log = await RunLog.open(join(dir, 'run'), ledger, 'run-query')
109 let ordinal = 0
110 for (const attempt of result.attempts) {
111 ordinal += 1
112 await recordQueryAttempt(log, ordinal, attempt)
113 }
114 const lines = (await readFile(ledger, 'utf8')).trim().split('\n')
115 assert.equal(lines.length, bound.attempts)
116 for (const line of lines) {
117 const event = parseEvent(JSON.parse(line) as unknown)
118 assert.equal(event.kind, 'observation')
119 if (event.kind !== 'observation') continue
120 const measurement = asRecord(event.payload.measurement)
121 if (!measurement) throw new Error('missing measurement')
122 assert.equal(measurement.source, 'telemetry-query')
123 assert.equal(measurement.kind, 'transient')
124 assert.equal(measurement.latencyMs, 80_000)
125 assert.match(String(measurement.detail), /timeout Envelope Error/)
126 }
127 const clean = accountProbeLoss(probes(rollout.burn.minSamples, 200), rollout.probe.maxLossRate)
128 const advance = decideWithoutTelemetry(clean, rollout, 'telemetry unavailable: APIError "timeout" Envelope Error')
129 assert.equal(advance.outcome, 'advance')
130 assert.match(advance.reason, /informational: telemetry query lost/)
131 assert.match(advance.reason, /100 responded probes, 0 server errors/)
132 let rolled = 0
133 const ramp = await runRamp(rollout, {
134 now: () => 0,
135 sleep: async () => {},
136 dwell: async () => ({ outcomes: probes(rollout.burn.minSamples, 200) }),
137 applySplit: async () => null,
138 observe: async () => ({ kind: 'unavailable', reason: 'telemetry unavailable: APIError "timeout" Envelope Error' }),
139 rollback: async () => {
140 rolled += 1
141 return null
142 },
143 })
144 assert.equal(ramp.state.kind, 'complete')
145 assert.equal(rolled, 0)
146 const line = ramp.lines[0]
147 if (!line) throw new Error('missing ramp line')
148 assert.match(line, /decision=advance/)
149 assert.match(line, /telemetry query lost/)
150})
152test('a persistent timeout still rolls back when a responded probe was a 5xx', async () => {
153 const rollout = policy()
154 const sample = probes(rollout.burn.minSamples - 1, 200)
155 sample.push({ kind: 'responded', id: 'probe-500', status: 500, ray: none(), latencyMs: 50, version: none() })
156 const loss = accountProbeLoss(sample, rollout.probe.maxLossRate)
157 const decision = decideWithoutTelemetry(loss, rollout, 'telemetry unavailable: timeout')
158 assert.equal(decision.outcome, 'rollback')
159 assert.match(decision.reason, /1 5xx on responded probes/)
160 let rolled = 0
161 const ramp = await runRamp(rollout, {
162 now: () => 0,
163 sleep: async () => {},
164 dwell: async () => ({ outcomes: sample }),
165 applySplit: async () => null,
166 observe: async () => ({ kind: 'unavailable', reason: 'telemetry unavailable: timeout' }),
167 rollback: async () => {
168 rolled += 1
169 return null
170 },
171 })
172 assert.equal(ramp.state.kind, 'rolled-back')
173 assert.equal(rolled, 1)
174 const bare = decideWithoutTelemetry(null, rollout, 'telemetry unavailable: timeout')
175 assert.equal(bare.outcome, 'harness_fault')
176})
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 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 · 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=145
git.response.cache=HIT
git.response.duration_ms=3
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 · 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=41349
git.response.cache=HIT
git.response.duration_ms=3
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.2 KiB · hit19 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=19
git.response.bytes=2212
git.response.cache=HIT
git.response.duration_ms=19
git.fetch.wants=174a54e837e9d4eed5ece86a413dbfea780f7375
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=2212
git.pkt.payload.max=2191
git.sideband.band1.bytes=2190
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
a5e30c9de9fe8a31
Request
4fbd8b62…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format