main
ply4 git calls389 ms42 KiB2 cachedprotocol v2
73 lines3.5 KiBRaw
1// Worker-level codes. ply's plyError() rejects anything outside its RETRY table, and Artifacts answers every lost
2// compare-and-swap — create onto an existing ref, and delete with a stale old oid — with the same "stale ref".
3// The distinction is made here, before the push, where the current oid is known.
4import { err, ok, type Result } from '../http/machine.ts';
5import { assertNever } from '../never.ts';
7export const CODE_REF_EXISTS = 'ref_exists';
8export const CODE_STALE_EXPECTED = 'stale_expected';
10/** The Worker's own codes, beside ply's. status.ts maps each to an HTTP status. */
11export type WorkerCode = typeof CODE_REF_EXISTS | typeof CODE_STALE_EXPECTED;
13export const WORKER_RETRY: Readonly<Record<WorkerCode, string>> = Object.freeze({
14 [CODE_REF_EXISTS]: 'no',
15 [CODE_STALE_EXPECTED]: 'fresh',
16});
18export function isWorkerCode(code: unknown): code is WorkerCode {
19 return typeof code === 'string' && Object.prototype.hasOwnProperty.call(WORKER_RETRY, code);
22export { assertNever };
24type RefExists = { oid: string };
25type StaleExpected = { expected: string; actual: string };
27export function refExists(ref: string, oid: string): WorkerError {
28 return Object.assign(new Error(`ref ${ref} already exists`), { code: CODE_REF_EXISTS, oid } as const satisfies RefExists & { code: WorkerCode });
31export function staleExpected(ref: string, expected: string, actual: string): WorkerError {
32 return Object.assign(new Error(`ref ${ref} is at ${actual}, not ${expected}`), {
33 code: CODE_STALE_EXPECTED,
34 expected,
35 actual,
36 oid: actual,
37 } as const satisfies StaleExpected & { code: WorkerCode; oid: string });
40/** A thrown-shape Worker error: what index.js's errorBody and status.ts answer (409, with the documented body). */
41export type WorkerError = Error & { readonly code: WorkerCode; readonly oid: string };
43/**
44 * A ref compare-and-swap the Worker lost, as a value. An operation() body returns it (ply turns a throw from the
45 * body into bad_request 'callback', or 'ambiguous' once a push was handed to the transport — ply #277), and the
46 * caller turns it into the Worker error after operation() has returned. A conflict learnt from a definite
47 * cas_conflict rejection is therefore still a definite 409.
48 */
49export type RefConflict =
50 | { readonly kind: typeof CODE_REF_EXISTS; readonly ref: string; readonly oid: string }
51 | { readonly kind: typeof CODE_STALE_EXPECTED; readonly ref: string; readonly expected: string; readonly actual: string };
53/** An operation() body's answer: the write landed (or was a noop), or a ref conflict to report as 409. */
54export type Written<T> = { readonly kind: 'done'; readonly value: T } | RefConflict;
56export const done = <T>(value: T): Written<T> => ({ kind: 'done', value });
57export const refExistsAt = (ref: string, oid: string): RefConflict => ({ kind: CODE_REF_EXISTS, ref, oid });
58export const staleAt = (ref: string, expected: string, actual: string): RefConflict => ({ kind: CODE_STALE_EXPECTED, ref, expected, actual });
60export function conflictError(c: RefConflict): WorkerError {
61 switch (c.kind) {
62 case CODE_REF_EXISTS: return refExists(c.ref, c.oid);
63 case CODE_STALE_EXPECTED: return staleExpected(c.ref, c.expected, c.actual);
64 default: return assertNever(c);
65 }
68/** operation()'s Result over a Written body, as the write's Result: a conflict becomes its Worker error. */
69export function settle<T, E>(r: Result<Written<T>, E>): Result<T, E | WorkerError> {
70 if (!r.ok) return r;
71 const w = r.value;
72 return w.kind === 'done' ? ok(w.value) : err(conflictError(w));
Diagnostics4 git calls · 389 ms
CallStatusSizeTime0389 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 · hit6 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 · 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
fetch2001.4 KiB381 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=381
git.response.bytes=1455
git.response.cache=MISS
git.response.duration_ms=381
git.fetch.wants=4c683bab2209dd109cf0c5db61bb5a0852648414
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=1455
git.pkt.payload.max=1434
git.sideband.band1.bytes=1433
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
a5e2bfac684589da
Request
63d0d9b9…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format