@zabaca/zbc 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zabaca/zbc",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Zabaca stack CLI — scaffold and deploy infrastructure",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -109,6 +109,10 @@ _Avoid_: identity, attribution log, audit trail
109
109
  `GET /_walgit/provenance?repo=<id>` — the whole of reading Provenance back: one repository, the Index's map as it stands, `{}` when nothing has been signed. Behind exactly the credential a clone of that repository needs, so a public deployment answers anyone and a token-gated one answers nobody else; there is no second authorization model. Deliberately not a Ref Event — that wire is latest-state and says only that a ref moved and to what (ADR-0009), while Provenance has a different lifetime and a different reader.
110
110
  _Avoid_: the provenance API, the audit endpoint
111
111
 
112
+ **Source** / **Per-source limit**:
113
+ The client one push is attributed to — the IP the edge saw (`cf-connecting-ip`, falling back to `x-forwarded-for`), which is all a Worker in front of a container can know — and the counts a deployment bounds it by in a window: new repositories, pushes, and pushed bytes (`src/rate-limit.ts`). Off unless configured, like every capability here. A request walgit cannot attribute to a Source is not limited, because pooling the unattributable into one bucket would let the first such request throttle every other. The verdict is reached at the smart-HTTP handler, the only layer that sees both the Source and the repository; it is **spoken** by `pre-receive`, because a status code on that route reaches git as `RPC failed; HTTP …` — a transport fault, which a client retries — while stderr from the hook reaches it as the same `remote:` reject line a size cap produces. The window is in memory and a container restart forgives it: over-forgiving is the safe direction, and a durable write per push would cost more than the spike it is there to make cheap.
114
+ _Avoid_: rate limiting the repository (nothing here is per repository), throttling (nothing is slowed — a push is served or refused), the client's identity (a Source is an address, not a who)
115
+
112
116
  **Advertised capability**:
113
117
  What the three agent-facing documents say a deployment can do, rendered from the thing that enforces it and never written as prose. The derivation has one owner — `shared/capabilities.ts`, whose `capabilitiesFrom(env)` returns the `Capabilities` that the plain-text `GET /`, the landing page and `/llms.txt` all render from, that `pre-receive` takes its size caps from (`limitsOf`), and that the Worker claims the event socket on. A capability with no field there is not advertised; a field added there fails to compile at every construction site until it is answered. Signing joins the size caps, the retention window and the stream under this rule: with no `WALGIT_PUSH_CERT_SEED`, none of the three mentions signing, keys or Provenance at all. Sharper here than for a cap, because a client asking to sign a host that does not advertise `push-cert` is refused by its OWN git — the agent finds out only after it has written the push. The stream is the same rule read across two variables: `events` is true only when `WALGIT_EVENTS_URL` and `WALGIT_EVENTS_TOKEN` are both set, because the token alone claims a socket the container's `post-receive` has nowhere to announce to — an advertised stream that never delivers.
114
118
 
@@ -454,13 +454,27 @@ cloudflare instance's `workerSecrets`):
454
454
  local directory for the bucket, which is for development and tests only.
455
455
 
456
456
  Optional instance configuration (plain env, not secrets): `WALGIT_APPEND_ONLY`,
457
- `WALGIT_MAX_PUSH_BYTES`, `WALGIT_MAX_REPO_BYTES`, `WALGIT_RETENTION_HOURS`,
457
+ `WALGIT_MAX_PUSH_BYTES`, `WALGIT_MAX_REPO_BYTES`,
458
+ `WALGIT_MAX_NEW_REPOS_PER_SOURCE`, `WALGIT_MAX_PUSHES_PER_SOURCE`,
459
+ `WALGIT_MAX_PUSH_BYTES_PER_SOURCE`, `WALGIT_RATE_WINDOW_SECONDS`,
460
+ `WALGIT_RETENTION_HOURS`,
458
461
  `WALGIT_PUBLIC`, `WALGIT_SIGNER_LISTS` — each unset means the behaviour is off
459
462
  and `GET /` does not claim it. `WALGIT_EVENTS_URL` and `WALGIT_EVENTS_TOKEN` (a
460
463
  secret) turn on the ref-event stream below, `WALGIT_PUSH_CERT_SEED` (a secret)
461
464
  turns on signed pushes, and `WALGIT_PRIVATE_REPOS` (a secret) turns on read
462
465
  gating.
463
466
 
467
+ `WALGIT_OPERATOR` and `WALGIT_CONTACT` name **who runs this deployment** and
468
+ where to write about it — a takedown, an abuse report, anything else. They are
469
+ the one pair here that is not a capability: nothing enforces them and the push
470
+ path never sees them, so unlike everything else above they are **edge-only** and
471
+ deliberately absent from `CONTAINER_ENV` — editing one costs no container
472
+ restart. Set either, both or neither; with neither set the landing page and
473
+ `/llms.txt` carry no operator block at all, rather than a placeholder address
474
+ nobody reads (`operatorFrom`, `shared/operator.ts`). A contact that is an email
475
+ address or an `https://` URL is rendered as a link on the page; anything else is
476
+ rendered as text.
477
+
464
478
  For the three boolean flags — `WALGIT_APPEND_ONLY`, `WALGIT_PUBLIC` and
465
479
  `WALGIT_SIGNER_LISTS` — **on means `1` or `true`, and nothing else**
466
480
  (`flagEnabled`, `shared/policy.ts`). An unrecognised value (`yes`, `on`, `TRUE`)
@@ -567,6 +581,39 @@ rule, and offers a free name (`<repo>-<8 hex>`) to push to instead — a wave of
567
581
  agents on near-identical prompts all reach for `test`, and this message is the
568
582
  first thing walgit ever says to most of them.
569
583
 
584
+ ## Per-source limits
585
+
586
+ `WALGIT_MAX_NEW_REPOS_PER_SOURCE`, `WALGIT_MAX_PUSHES_PER_SOURCE` and
587
+ `WALGIT_MAX_PUSH_BYTES_PER_SOURCE` bound what **one client** may spend in a
588
+ window; `WALGIT_RATE_WINDOW_SECONDS` is the window and defaults to an hour when
589
+ a count is set without one. All three are **unset by default**, and with them
590
+ unset nothing about a push changes.
591
+
592
+ They answer a different question from the size caps above: those bound how big
593
+ one thing may be, these bound how much of the host is yours. A hundred 1 MiB
594
+ pushes are each individually fine and a hundred new names are each individually
595
+ free, and one container serves every repository — so a single visitor filling
596
+ the bucket is the queue everybody else is behind.
597
+
598
+ The verdict is reached in the smart-HTTP handler (`src/http.ts`), which is the
599
+ only layer that sees both the **source** — the client IP, from
600
+ `cf-connecting-ip`, falling back to `x-forwarded-for`; a request walgit cannot
601
+ attribute is not limited — and the repository the push names. It is **spoken**
602
+ by `pre-receive` (`src/rate-limit.ts`), which is where a refusal has to come
603
+ from to reach the client as a `remote:` reject line: a 4xx on that route is
604
+ reported by git as `RPC failed; HTTP …`, which reads as a transport fault and
605
+ gets retried. Nothing is written to the object store.
606
+
607
+ The window lives in the container's memory, so a restart forgives it. That is
608
+ the trade: the alternative is a durable write per push to enforce a limit whose
609
+ whole purpose is to make a spike cheap, and over-forgiving is the safe
610
+ direction. Whether a name is *new* is read from the Index (a repository holding
611
+ no ref is one being created); an Index that cannot be read never invents a
612
+ creation refusal.
613
+
614
+ `GET /` and `/llms.txt` state each limit that is on, from the same
615
+ `Capabilities` the handler enforces.
616
+
570
617
  ## Size limits
571
618
 
572
619
  `WALGIT_MAX_PUSH_BYTES` caps a single push; `WALGIT_MAX_REPO_BYTES` caps what
@@ -139,6 +139,50 @@ entry count wrong: a **signed** ref-only push sends an empty pack (a 32-byte
139
139
  header and trailer) where an unsigned one sends none at all. The scenario reads
140
140
  the object count out of the pack header instead.
141
141
 
142
+ # `load.ts` — how many at once, against a deployment
143
+
144
+ Neither of the other two answers the question an operator has before handing the
145
+ URL to a crowd: how many at once, and what gives way first. `suite.ts` measures
146
+ one stream against a node it starts itself — no edge, no Durable Object, no R2,
147
+ no contention — and `live.ts` asks a deployment a yes/no question about its
148
+ configuration.
149
+
150
+ ```bash
151
+ bun run e2e:load -- --origin https://agentgit.zabaca.com
152
+ bun run e2e:load -- --origin https://… --repos 8 --clones 8 --pushes 8 --watchers 8 --json run.json
153
+ ```
154
+
155
+ It drives the three things a visitor does — clone, push, subscribe to the ref
156
+ event stream — reports nearest-rank percentiles over the SUCCESSES of each,
157
+ counts a rate-limit refusal apart from a transport failure, and names the
158
+ workload that degraded first. Nothing is stood in for: a deployment is the thing
159
+ being measured.
160
+
161
+ Two rules it enforces on the plan before it starts, both of which exist because
162
+ breaking them produces a number that looks like a finding and is not:
163
+
164
+ - **It refuses to spend more than half the deployment's hourly per-source
165
+ budget** (`WALGIT_MAX_*_PER_SOURCE`). A run that spends it measures
166
+ `src/rate-limit.ts` rather than the service, and leaves the rest of the hour
167
+ unmeasurable for whoever runs next from the same address.
168
+ - **One repository per concurrent push.** Two pushes racing for the same ref
169
+ means one loses the compare-and-swap and is refused as a non-fast-forward —
170
+ git being right, recorded as the host giving way.
171
+
172
+ The arithmetic and the verdict live in `load-report.ts`, which is unit-tested;
173
+ the driver is not, deliberately, because doubling the network would measure the
174
+ double.
175
+
176
+ Under `--origin` the run leaves `load-<run id>-*` repositories behind, named on
177
+ the way out, collected by the deployment's retention window if it has one and
178
+ permanent if it has none. Exit 0 means the run completed — the verdict is in the
179
+ report, not in the exit code; 1 means the origin could not be measured at all,
180
+ 64 that the arguments were wrong.
181
+
182
+ The first run of it against agentgit production, with what it found and what the
183
+ rate limits were set to as a result, is
184
+ `docs/research/agentgit-load-2026-09-16.md`.
185
+
142
186
  # `live.ts` — a separate check, against a deployment
143
187
 
144
188
  Everything above is `suite.ts`, which starts its own node. `live.ts` is not part
@@ -0,0 +1,240 @@
1
+ /**
2
+ * The load run's arithmetic and its verdict — everything `load.ts` decides
3
+ * that does not need the network.
4
+ *
5
+ * It lives apart from the driver because the driver is the part that must not
6
+ * be doubled: pointing it at a stub would measure the stub. What CAN be
7
+ * checked without a deployment is whether the numbers coming back are read
8
+ * correctly — a percentile that counts a 9-second failure as a 9-second
9
+ * latency, or a verdict that names the slowest workload rather than the one
10
+ * that broke, is a wrong answer written down with a date on it.
11
+ */
12
+
13
+ /** What one operation did. `ms` is wall time; only an `ok` one is a latency. */
14
+ export interface Sample {
15
+ ms: number
16
+ outcome: 'ok' | 'error' | 'limited'
17
+ /** The remote's own words, for a refusal or a failure. */
18
+ detail?: string
19
+ }
20
+
21
+ export interface OpSummary {
22
+ /** Every attempt, whatever it did. */
23
+ n: number
24
+ ok: number
25
+ errors: number
26
+ /** Refused by the deployment's per-source rate limit (`src/rate-limit.ts`). */
27
+ limited: number
28
+ /** Milliseconds, over the successful attempts alone. Null when there were none. */
29
+ min: number | null
30
+ p50: number | null
31
+ p95: number | null
32
+ p99: number | null
33
+ max: number | null
34
+ }
35
+
36
+ /**
37
+ * Nearest rank: the pth percentile is the ceil(p/100 × n)-th smallest sample.
38
+ *
39
+ * Chosen over interpolation because every number this produces is a latency
40
+ * something actually experienced, which is what a report gets read for.
41
+ */
42
+ function percentile(sorted: readonly number[], p: number): number | null {
43
+ if (sorted.length === 0) return null
44
+ const rank = Math.ceil((p / 100) * sorted.length)
45
+ return sorted[Math.min(Math.max(rank, 1), sorted.length) - 1] ?? null
46
+ }
47
+
48
+ /**
49
+ * The percentiles are over SUCCESSES only.
50
+ *
51
+ * A connection that died after nine seconds did not serve anything in nine
52
+ * seconds, and a rate-limit refusal answered in 40 ms is not the service being
53
+ * fast. Blending either into the latency distribution makes a degrading run
54
+ * look better the more it fails, so both are counted instead.
55
+ */
56
+ export function summarize(samples: readonly Sample[]): OpSummary {
57
+ const durations = samples
58
+ .filter((sample) => sample.outcome === 'ok')
59
+ .map((sample) => sample.ms)
60
+ .toSorted((a, b) => a - b)
61
+
62
+ return {
63
+ n: samples.length,
64
+ ok: durations.length,
65
+ errors: samples.filter((sample) => sample.outcome === 'error').length,
66
+ limited: samples.filter((sample) => sample.outcome === 'limited').length,
67
+ min: durations[0] ?? null,
68
+ p50: percentile(durations, 50),
69
+ p95: percentile(durations, 95),
70
+ p99: percentile(durations, 99),
71
+ max: durations[durations.length - 1] ?? null,
72
+ }
73
+ }
74
+
75
+ export interface Bottleneck {
76
+ /** The workload that degraded first, or null when none of them ran. */
77
+ op: string | null
78
+ /** p99 ÷ p50 for that workload, when it is a slowness verdict. */
79
+ ratio: number | null
80
+ reason: string
81
+ }
82
+
83
+ /**
84
+ * Which workload degraded first.
85
+ *
86
+ * Two rules, in order. A workload that FAILED or was REFUSED outranks every
87
+ * merely slow one however fast it was — a broken thing is not a fast thing.
88
+ * Among the rest the verdict is p99 ÷ p50 rather than absolute p99, because a
89
+ * clone is honestly slower than a websocket handshake and comparing them
90
+ * absolutely would name the heaviest workload every time. A tail that is a
91
+ * multiple of its own median is the shape of a queue, which is what one
92
+ * container serving every repository produces when it saturates.
93
+ */
94
+ export function nameBottleneck(summaries: Readonly<Record<string, OpSummary>>): Bottleneck {
95
+ const ran = Object.entries(summaries).filter(([, summary]) => summary.n > 0)
96
+ if (ran.length === 0) return { op: null, ratio: null, reason: 'nothing ran' }
97
+
98
+ const broken = ran
99
+ .filter(([, summary]) => summary.errors > 0 || summary.limited > 0)
100
+ .toSorted((a, b) => b[1].errors + b[1].limited - (a[1].errors + a[1].limited))
101
+ if (broken.length > 0) {
102
+ const [op, summary] = broken[0] as [string, OpSummary]
103
+ const parts = [
104
+ summary.errors > 0 ? `${summary.errors}/${summary.n} failed` : '',
105
+ summary.limited > 0 ? `${summary.limited}/${summary.n} rate-limited` : '',
106
+ ].filter(Boolean)
107
+ return { op, ratio: null, reason: parts.join(', ') }
108
+ }
109
+
110
+ const ratios = ran
111
+ .filter(([, summary]) => summary.p50 !== null && summary.p50 > 0 && summary.p99 !== null)
112
+ .map(([op, summary]) => ({ op, ratio: (summary.p99 as number) / (summary.p50 as number) }))
113
+ .toSorted((a, b) => b.ratio - a.ratio)
114
+ const worst = ratios[0]
115
+ if (!worst) return { op: null, ratio: null, reason: 'nothing completed' }
116
+
117
+ return {
118
+ op: worst.op,
119
+ ratio: worst.ratio,
120
+ reason: `p99 is ${worst.ratio.toFixed(1)}x its own p50`,
121
+ }
122
+ }
123
+
124
+ export interface LoadOptions {
125
+ origin: string
126
+ /** Concurrent clones of the seeded repositories. */
127
+ clones: number
128
+ /** Concurrent pushes, one per seeded repository at a time. */
129
+ pushes: number
130
+ /** Concurrent websocket subscribers on the ref-event stream. */
131
+ watchers: number
132
+ /** How many scratch repositories to seed — each one is a NEW NAME. */
133
+ repos: number
134
+ /** Where to write the machine-readable record, if anywhere. */
135
+ json: string | null
136
+ }
137
+
138
+ export type Parsed<T> = { ok: true; value: T } | { ok: false; error: string }
139
+
140
+ /**
141
+ * What one source may spend against agentgit production in an hour
142
+ * (`packages/infra/environments/production/walgit-public.ts`).
143
+ *
144
+ * The run refuses to plan past a fraction of it. Not politeness: a run that
145
+ * spends the budget measures `src/rate-limit.ts` rather than the service, and
146
+ * it burns the rest of the hour for whoever measures next — from the same IP,
147
+ * which on a NAT is more people than the operator.
148
+ */
149
+ const BUDGET = {
150
+ newRepos: 20,
151
+ pushes: 300,
152
+ /** Of each, what one run may take. */
153
+ share: 0.5,
154
+ } as const
155
+
156
+ export function parseLoadArgs(argv: readonly string[]): Parsed<LoadOptions> {
157
+ const value: LoadOptions = {
158
+ origin: '',
159
+ clones: 8,
160
+ pushes: 8,
161
+ watchers: 8,
162
+ // One per concurrent push, per the rule below: the default plan has to be
163
+ // a legal one, or the bare `--origin` invocation is refused.
164
+ repos: 8,
165
+ json: null,
166
+ }
167
+
168
+ for (let index = 0; index < argv.length; index += 1) {
169
+ const flag = argv[index] as string
170
+ const next = argv[index + 1]
171
+ const takes = (): string | null => {
172
+ if (next === undefined || next.startsWith('--')) return null
173
+ index += 1
174
+ return next
175
+ }
176
+
177
+ switch (flag) {
178
+ case '--origin': {
179
+ const origin = takes()
180
+ if (origin === null) return { ok: false, error: '--origin needs a URL' }
181
+ value.origin = origin.replace(/\/+$/, '')
182
+ break
183
+ }
184
+ case '--json': {
185
+ const path = takes()
186
+ if (path === null) return { ok: false, error: '--json needs a path' }
187
+ value.json = path
188
+ break
189
+ }
190
+ case '--clones':
191
+ case '--pushes':
192
+ case '--watchers':
193
+ case '--repos': {
194
+ const raw = takes()
195
+ const count = Number(raw)
196
+ if (raw === null || !Number.isInteger(count) || count < 0) {
197
+ return { ok: false, error: `${flag} needs a non-negative integer` }
198
+ }
199
+ value[flag.slice(2) as 'clones' | 'pushes' | 'watchers' | 'repos'] = count
200
+ break
201
+ }
202
+ default:
203
+ return { ok: false, error: `unknown argument: ${flag}` }
204
+ }
205
+ }
206
+
207
+ if (value.origin === '') return { ok: false, error: '--origin is required' }
208
+
209
+ const repoCap = Math.floor(BUDGET.newRepos * BUDGET.share)
210
+ if (value.repos > repoCap) {
211
+ return {
212
+ ok: false,
213
+ error: `--repos ${value.repos} would spend more than half the deployment's per-source budget of ${BUDGET.newRepos} new names an hour; at most ${repoCap}`,
214
+ }
215
+ }
216
+ const pushCap = Math.floor(BUDGET.pushes * BUDGET.share)
217
+ // Seeding is a push too, and so is the one that wakes the watchers.
218
+ const plannedPushes = value.repos + value.pushes + (value.watchers > 0 ? 1 : 0)
219
+ if (plannedPushes > pushCap) {
220
+ return {
221
+ ok: false,
222
+ error: `${plannedPushes} pushes would spend more than half the deployment's per-source budget of ${BUDGET.pushes} an hour; at most ${pushCap}`,
223
+ }
224
+ }
225
+ // One repository per concurrent pusher. Two pushes racing for the same ref
226
+ // means one of them loses the compare-and-swap and is refused as a
227
+ // non-fast-forward — git being right, recorded as the host giving way, which
228
+ // would make a report understate capacity and name the wrong bottleneck.
229
+ if (value.pushes > value.repos) {
230
+ return {
231
+ ok: false,
232
+ error: `--pushes ${value.pushes} with --repos ${value.repos} would race two pushes for the same ref; give at least one repository per concurrent push`,
233
+ }
234
+ }
235
+ if (value.repos === 0 && (value.clones > 0 || value.pushes > 0)) {
236
+ return { ok: false, error: 'nothing to clone or push: --repos is 0' }
237
+ }
238
+
239
+ return { ok: true, value }
240
+ }