main
1// One traffic writer for the process. A deployment create outside the run log,
2// or a percent that this step's decision has not armed, is a harness fault.
3// Run 2026-11-01T20-01-08-225Z wrote `ramp … 100%` during the 75% observe window
4// with no command event and no state_change.
5import { AsyncLocalStorage } from 'node:async_hooks'
6import { assertNever } from '../../src/never.ts'
7import { activeLog } from './log.ts'
8import { commandSinkActive } from './trace.ts'
10export class HarnessFault extends Error {
11 constructor(reason: string) {
12 super(reason)
13 this.name = 'harness_fault'
14 }
15}
17export type WriteIntent =
18 | { readonly kind: 'canary' }
19 | { readonly kind: 'step'; readonly percent: number }
20 | { readonly kind: 'restore'; readonly percent: number }
21 | { readonly kind: 'rollback' }
23type Arm =
24 | { readonly kind: 'idle' }
25 | { readonly kind: 'step'; readonly percent: number }
26 | { readonly kind: 'observe' }
28const intents = new AsyncLocalStorage<WriteIntent>()
29const depth = new AsyncLocalStorage<number>()
31let arm: Arm = { kind: 'idle' }
32let tail: Promise<void> = Promise.resolve()
34export function withWriteIntent<T>(intent: WriteIntent, fn: () => Promise<T>): Promise<T> {
35 return intents.run(intent, fn)
36}
38export function activeIntent(): WriteIntent | null {
39 const intent = intents.getStore()
40 if (intent) return intent
41 return null
42}
44/** The first ramp percent may be written. A second begin without `endRamp` is a fault. */
45export function beginRamp(percent: number): void {
46 if (arm.kind !== 'idle') throw new HarnessFault(`ramp began while the traffic gate is ${armLabel(arm)}`)
47 arm = { kind: 'step', percent }
48}
50/** The decision for the current step is on the log, so this percent may be written. */
51export function armStep(percent: number): void {
52 if (arm.kind === 'idle') throw new HarnessFault(`cannot arm ${percent}% outside a ramp`)
53 arm = { kind: 'step', percent }
54}
56/** This percent was applied, or it was already live. Forward writes wait for the next decision. */
57export function noteStepApplied(percent: number): void {
58 if (arm.kind === 'observe') return
59 if (arm.kind === 'step' && arm.percent === percent) {
60 arm = { kind: 'observe' }
61 return
62 }
63 throw new HarnessFault(`step ${percent}% was not armed (${armLabel(arm)})`)
64}
66export function endRamp(): void {
67 arm = { kind: 'idle' }
68}
70/**
71 * Process-wide single flight. A create that is already inside the lock
72 * (the compare-and-swap calling `cf`) re-enters instead of waiting on itself.
73 */
74export async function withTrafficLock<T>(body: () => Promise<T>): Promise<T> {
75 if (depth.getStore()) return body()
76 let release: () => void = () => {}
77 const gate = new Promise<void>(resolve => {
78 release = resolve
79 })
80 const previous = tail
81 tail = previous.then(() => gate, () => gate)
82 await previous
83 try {
84 return await depth.run(1, body)
85 } finally {
86 release()
87 }
88}
90function armLabel(current: Arm): string {
91 switch (current.kind) {
92 case 'idle':
93 return 'idle'
94 case 'observe':
95 return 'observe'
96 case 'step':
97 return `step ${current.percent}%`
98 default:
99 return assertNever(current)
100 }
101}
103function intentLabel(intent: WriteIntent): string {
104 switch (intent.kind) {
105 case 'canary':
106 return 'canary'
107 case 'rollback':
108 return 'rollback'
109 case 'step':
110 return `step ${intent.percent}%`
111 case 'restore':
112 return `restore ${intent.percent}%`
113 default:
114 return assertNever(intent)
115 }
116}
118function refusal(intent: WriteIntent): string | null {
119 switch (arm.kind) {
120 case 'idle':
121 if (intent.kind === 'canary' || intent.kind === 'rollback') return null
122 return `deployment write ${intentLabel(intent)} is outside the ramp`
123 case 'step':
124 if (intent.kind === 'rollback') return null
125 if ((intent.kind === 'step' || intent.kind === 'restore') && intent.percent === arm.percent) return null
126 return `deployment write ${intentLabel(intent)} is not the armed ${arm.percent}% step`
127 case 'observe':
128 if (intent.kind === 'rollback') return null
129 return `deployment write ${intentLabel(intent)} during observe`
130 default:
131 return assertNever(arm)
132 }
133}
135/** Call under the traffic lock, immediately before `cf workers deployments create`. */
136export function assertDeploymentCreate(): void {
137 if (!activeLog()) throw new HarnessFault('cf deployments create with no active log')
138 if (!commandSinkActive()) throw new HarnessFault('cf deployments create with no command sink')
139 const intent = activeIntent()
140 if (!intent) throw new HarnessFault('cf deployments create with no write intent')
141 const refused = refusal(intent)
142 if (refused) throw new HarnessFault(refused)
143 if (intent.kind === 'step' || intent.kind === 'restore') arm = { kind: 'observe' }
144}
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 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=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 · hit7 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=7 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=61Open pack map
fetch2001.6 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1618 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=6e5692812893bc82900b901ee58be4fa88d87c3a 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=1618 git.pkt.payload.max=1597 git.sideband.band1.bytes=1596 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
- a5e2f50ceb387089
- Request
- e1407488…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format