Artifactspublic-v0

ply

main
ply4 git calls29 ms40 KiB3 cachedprotocol v2
68 lines5.7 KiBRaw
1// The merge-base server behaviours (issue #18, #42): a server answering the commit-only `tree:0` + `deepen` walks of
2// mergeBase with a cut history. Shared by test/fuzz/liar.mjs (`--op mergebase`, random DAGs) and
3// test/mergebase-space.test.js (the enumerated outcome space).
4import { buildPack } from '../../src/pack.js';
5import { TYPE } from '../../src/objects.js';
6import { concat, te } from '../../src/bytes.js';
7import { Rng } from './prng.js';
8import { reachableCommits } from './dag.js';
10export const pktLine = s => { const b = typeof s === 'string' ? te.encode(s) : s; return concat([te.encode((b.length + 4).toString(16).padStart(4, '0')), b]); };
11export const FLUSH = te.encode('0000');
12// a v2 fetch response carrying exactly these objects (full, no deltas) as a sideband pack
13export async function fetchResponse(objs, { shallow = [] } = {}) {
14 const { pack } = await buildPack(objs);
15 const parts = [];
16 if (shallow.length) { parts.push(pktLine('shallow-info\n')); for (const s of shallow) parts.push(pktLine(`shallow ${s}\n`)); parts.push(te.encode('0001')); }
17 parts.push(pktLine('packfile\n'));
18 for (let i = 0; i < pack.length; i += 65000) parts.push(pktLine(concat([Uint8Array.of(1), pack.subarray(i, Math.min(i + 65000, pack.length))])));
19 parts.push(FLUSH);
20 return concat(parts);
23// ---- merge-base lies (issue #18) ----
24// The request names one commit want, `filter tree:0` and `deepen N`; the honest answer is every commit within N of the
25// want, with the commits at the cut as `shallow` lines (dag.js reachableCommits, calibrated against upload-pack). Each
26// lie is a function of the request alone (a sub-Rng seeded from the want and the case, so concurrent fetches of `ours`
27// and `theirs` cannot reorder the randomness) and answers without forwarding; `M.lied` counts the answers that were lies.
28const fetchRequest = body => { const s = Buffer.from(body).toString('latin1'); return { want: /want ([0-9a-f]{40})\n/.exec(s)?.[1] ?? null, deepen: +(/deepen (\d+)\n/.exec(s)?.[1] ?? 0), filter: /filter ([^\n]+)\n/.exec(s)?.[1] ?? null }; };
29const window = (M, want, deepen) => { const { commits, boundary } = reachableCommits(M.model, [want], { depth: deepen }); return { all: [...commits.keys()], boundary: [...boundary] }; };
30const drop = (rng, list, k) => { const out = new Set(); const pool = [...list]; while (out.size < Math.min(k, pool.length)) out.add(pool[rng.int(0, pool.length - 1)]); return out; };
31export const MERGE_LIES = {
32 // control: forwarded untouched → the bases must be git's
33 'mb:honest': () => null,
34 // the issue: ancestors inside the window are omitted and no shallow line admits it. The pack still hash-verifies.
35 'mb:omit-no-shallow': (M, rng, w) => { const gone = drop(rng, w.all.filter(c => c !== w.want), rng.int(1, 3)); return { keep: w.all.filter(c => !gone.has(c)), shallow: [], omitted: gone.size }; },
36 // the honest shallow lines are sent, but commits elsewhere in the window are missing too
37 'mb:omit-keep-shallow': (M, rng, w) => { const gone = drop(rng, w.all.filter(c => c !== w.want && !w.boundary.includes(c)), rng.int(1, 3)); return { keep: w.all.filter(c => !gone.has(c)), shallow: w.boundary, omitted: gone.size }; },
38 // a consistent cut shallower than asked: one commit c declared shallow, everything only reachable through it dropped.
39 // Not a contradiction of the protocol — a server may answer with less depth — so the client must deepen or give up typed.
40 'mb:cut-shallower': (M, rng, w) => {
41 const c = rng.pick(w.all.filter(x => x !== w.want)); if (!c) return null;
42 const seen = new Set([w.want]); const st = [w.want];
43 while (st.length) { const x = st.pop(); if (x === c) continue; for (const p of M.model.commits.get(x).parents) if (!seen.has(p) && w.all.includes(p)) { seen.add(p); st.push(p); } }
44 return { keep: [...seen], shallow: [...new Set([...w.boundary.filter(b => seen.has(b) && b !== c), c])], omitted: w.all.length - seen.size };
45 },
46 // the want itself is missing from an otherwise honest pack
47 'mb:omit-want': (M, rng, w) => ({ keep: w.all.filter(c => c !== w.want), shallow: w.boundary, omitted: 1 }),
48 // an unrequested commit (from an unrelated repo) rides along in an otherwise honest pack
49 'mb:extra-foreign': (M, rng, w) => ({ keep: w.all, shallow: w.boundary, extra: [M.decoy], omitted: 0 }),
50 // a tree object in a tree:0 pack (the want's root tree). Main admits a well-formed, hash-verified tree in a commit-walk
51 // pack (the blob:none fallback carries every tree for the same request; fetch.js checkWide, #47) and the walk reads
52 // commits only, so this is not a contradiction: the answer must still be git's (or a typed error)
53 'mb:tree-in-tree0': (M, rng, w) => ({ keep: w.all, shallow: w.boundary, extra: [{ type: TYPE.TREE, data: M.treeOf(w.want) }], omitted: 0 }),
54};
55export const mergeLie = (M, kind, seed) => ctx => {
56 if (ctx.stage !== 'fetch' || ctx.phase !== 'request') return null;
57 const { want, deepen, filter } = fetchRequest(ctx.reqBody);
58 if (!want || !deepen || filter !== 'tree:0' || !M.model.commits.has(want)) return null;
59 const rng = new Rng((seed ^ parseInt(want.slice(0, 8), 16) ^ (deepen * 2654435761)) >>> 0);
60 if (kind !== 'mb:honest' && deepen === 1 && rng.bool(0.5)) return null; // let some of the three-commit fetches through
61 const w = { ...window(M, want, deepen), want };
62 const plan = MERGE_LIES[kind](M, rng, w);
63 if (!plan || (plan.omitted === 0 && !plan.extra)) return null; // nothing to omit in a one-commit window: the honest answer
64 M.lied++; M.omitted += plan.omitted;
65 const objs = [...plan.keep.map(c => ({ type: TYPE.COMMIT, data: M.commitData.get(c) })), ...(plan.extra ?? [])];
66 return { type: 'bytes', noForward: true, name: kind, bytes: fetchResponse(objs, { shallow: plan.shallow }) };
67};
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 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 1020038 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=38434
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=19912563f540228593df0c489082e5e2508e21e4
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=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2002.5 KiB · hit23 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=23
git.response.bytes=2548
git.response.cache=HIT
git.response.duration_ms=23
git.fetch.wants=c61a8cb433ec93f6a6176d94efcb3eff1ccad14f
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=2548
git.pkt.payload.max=2527
git.sideband.band1.bytes=2526
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.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e33af51a2af162
Request
2ea0cafe…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format