Repository navigation
fix(hub): stream large artifacts to R2 so the whole-package zip publishes; cut email 0.2.2 - #1849
Conversation
TDD red state: 11 new tests for the streaming POST /publish path (application/octet-stream + X-Gaia-* headers). All 11 fail with 415 because the handler has not been updated yet. Existing 65 multipart tests remain green.
…artifacts The existing multipart path buffers the entire artifact in memory, hitting Cloudflare's ~128 MB per-Worker limit for the 177 MB whole-package zip. New second path: when Content-Type is application/octet-stream, the raw body is passed directly to R2.put() without buffering. Metadata travels in X-Gaia-* headers (Manifest, Filename, Sha256, Package-Files). R2-side sha256 integrity enforces upload correctness. The multipart path (per-platform binaries, README, CHANGELOG) is unchanged. Shared tail extracted (finishPublish) so both paths write ancillary objects and rebuild the index identically. validatePackageFilesJson() refactored into a shared helper used by both paths.
publish_to_r2.py: add publish_streaming() for platform_key=="package" (the whole-package zip). Sends application/octet-stream with X-Gaia-* headers and data=<file-handle> — requests streams chunk-by-chunk, never loading the full ~177 MB into memory. Per-platform binaries keep using the existing multipart publish_one() unchanged. _sha256_file() now hashes in 1 MiB chunks instead of read_bytes(). tests/unit/test_publish_to_r2_stream.py: 11 new tests asserting call validity (octet-stream + X-Gaia-* for zip; multipart for binary), 201/409 idempotency, integrity mismatch → SystemExit, and main() routing. workers/agent-hub/README.md: document the new streaming protocol alongside the existing multipart contract (required/optional headers, curl examples, shared 201 body shape).
R2.put() can return null on success in some binding implementations. Guard against it with an explicit null check + 500, rather than silently falling back to the client-supplied Content-Length (unverified, could corrupt the catalog's size_bytes field).
|
Verdict: Approve with suggestions — no blocking issues. This fixes the release-killing 502 by streaming the ~177 MB whole-package zip straight to R2 instead of buffering it in the Worker (which blew past Cloudflare's 128 MB isolate cap). The proven multipart path for the smaller per-platform binaries is left untouched, routing is purely by One thing worth tightening before/after merge: the PR introduces a shared "finish publish" helper but only wires the new streaming path through it — the existing multipart path still carries its own byte-for-byte copy of that same tail logic, and the helper's docstring claims both paths use it. That's a drift risk (two copies of the per-version-record + index-rebuild logic must now stay in sync) plus an inaccurate comment. Non-blocking, but cheap to fix now. 🔍 Technical details🟡 Important
🟢 Minor
(add
Strengths
|
- drop unused unittest.mock.call import (flake8 F401 — the CI Code Quality blocker) - move base64 import to module top-level in publish_to_r2.py - send X-Gaia-Content-Type: application/zip so the stored package object has the right content-type and the documented header is actually exercised - correct finishPublish docstring (the multipart path still inlines its own tail) and note the Content-Length size guard is advisory — R2 is the real ceiling and the body is never buffered
|
Thanks for the review — addressed the suggestions in b0c08c2, and CI Code Quality is green again.
The Code Quality failure itself was a flake8 |
…ature set) (amd#1851) Bumps the email agent to **0.2.2** so the release can be re-cut now that the Hub publish 502 is fixed on main ([amd#1849](amd#1849), the streaming fix). 0.2.1 published its per-platform binaries to the Hub but its npm publish never completed (the worker OOM'd on the ~177 MB whole-package zip), so 0.2.2 is the first *complete* publish of the same feature set. No agent wire-contract change — `SCHEMA_VERSION` stays 2.0. Keeps all four version sources in sync (the release workflow's version-resolve step asserts this): `gaia-agent.yaml`, `pyproject.toml`, `version.py`, npm `package.json` → 0.2.2, plus the CHANGELOG entry. >⚠️ **Prerequisite before tagging `agent-pkg-email-v0.2.2`:** the live Agent Hub **worker must be redeployed** with the streaming fix. Merging amd#1849 updated the worker *source* on main but no CI deploys the worker — it's a manual `wrangler deploy` (Cloudflare account that owns `agent-hub`). Tagging before that redeploy would 502 again. ## Test plan - [x] All four version sources read 0.2.2 (sync gate) - [x] `cd hub/agents/npm/agent-email && npm run build && npm test` — 46 pass; `npm pack` ships README/CHANGELOG/SKILL/SPEC --------- Co-authored-by: Tomasz Iniewicz <[email protected]>
…loy) (amd#1854) Re-cuts the email agent at **0.2.3** now that the Agent Hub worker has been redeployed with the streaming fix ([amd#1849](amd#1849)). 0.2.2 published its per-platform binaries but its whole-package zip + npm publish never completed because the live worker hadn't yet picked up the fix — so 0.2.3 is the first fully-published release of this feature set. No agent wire-contract change (`SCHEMA_VERSION` stays 2.0). All seven version targets synced via `stamp_version.py` (the sync gate): `version.py` (source), `gaia-agent.yaml`, `pyproject.toml`, npm `package.json`, `binaries.lock.json` (agentVersion + baseUrl), and the `architecture.html` badge → 0.2.3, plus the CHANGELOG entry. ## Test plan - [x] `stamp_version.py --check` passes on all targets - [x] `cd hub/agents/npm/agent-email && npm run build && npm test` - [ ] Tag `agent-pkg-email-v0.2.3` → release run publishes binaries + zip + npm @0.2.3 (the real test that the worker redeploy resolved the 502) Co-authored-by: Tomasz Iniewicz <[email protected]>
…ail 0.2.4 (amd#1855) Gets the email-agent release unblocked. The ~177 MB all-platforms whole-package zip (amd#1843) exceeds **Cloudflare's edge upload limit** — `POST /publish` returns `413 Payload Too Large` before the request even reaches the worker, which blocked the release on 0.2.1–0.2.3 (each published its binaries but never the zip/npm). That edge limit is plan-based and not fixable in worker code, so the worker-side streaming attempt ([amd#1849](amd#1849)) couldn't have solved it. This reverts that streaming change and disables the whole-package zip publish (`if: false`, with a note to revive it via presigned-to-R2 or per-platform zips). **0.2.4 ships the per-platform binaries + npm client + website with no combined zip** — the binaries stay individually downloadable from the Hub. No agent wire-contract change (`SCHEMA_VERSION` stays 2.0). <details> <summary>What's in here</summary> - **Revert amd#1849** — restores the worker + `publish_to_r2.py` to the multipart-only path; worker suite back to 64 tests passing. - **Disable the zip steps** — "Assemble + publish the whole-package zip" and its edge-verify step are `if: false`; the binary fetch-verify, npm publish, and website redeploy are untouched. - **0.2.4 bump** — all six version targets synced via `stamp_version.py` + CHANGELOG. </details> ## Test plan - [x] `stamp_version.py --check` passes (all targets 0.2.4) - [x] worker `npm run typecheck && npm test` — 64 pass (revert clean) - [x] `cd hub/agents/npm/agent-email && npm run build && npm test` — 46 pass - [ ] Tag `agent-pkg-email-v0.2.4` → release publishes binaries + npm @0.2.4 + website (no zip step) --------- Co-authored-by: Tomasz Iniewicz <[email protected]>
Closes #1848
The email-agent release currently dies at the "publish the whole-package zip" step with a Cloudflare 502, which also skips the npm publish and website redeploy that run after it — so every release is stuck half-done (binaries on the Hub, no npm package, no catalog update). The cause isn't auth: the Hub worker buffers the entire upload in memory (
request.formData()→arrayBuffer()), and the new 177 MB whole-package zip needs ~350 MB+, far over Cloudflare's hard 128 MB per-Worker memory limit → the isolate is OOM-killed → 502. The ~40 MB per-platform binaries stay under the ceiling, which is why they publish fine with the same token.This streams large artifacts straight to R2 instead of buffering them: the whole-package zip is sent as a raw
application/octet-streambody with metadata inX-Gaia-*headers, and stored viaenv.BUCKET.put(key, request.body, { sha256 })— the body is never materialized, so worker memory is independent of artifact size, and R2 verifies the client-supplied SHA-256 as it streams (mismatch →400, fail-loud). The proven multipart path for the smaller per-platform binaries (which carry README/CHANGELOG) is left byte-for-byte unchanged; routing is purely byContent-Type.Test plan
cd workers/agent-hub && npm run typecheck && npm test— 76 pass (12 new streaming tests, incl. integrity-mismatch rejection)python -m pytest tests/unit/test_publish_to_r2_stream.py— 11 pass (asserts the zip goes octet-stream withX-Gaia-*headers, binaries stay multipart)Evidence
Worker suite (independently re-run on this branch):
The decisive worker tests: a wrong
X-Gaia-Sha256makes R2 reject the streamed bytes → worker returns400 integrity_check_failed(proves server-side integrity with no worker-side checksum over the body); an oversizedContent-Length→413without buffering.Python client (independently re-run):
Honest scope note: local
wrangler devruns workerd without the production 128 MB isolate cap, so it can't reproduce the OOM — the unit tests prove the streaming protocol + integrity, the diff proves the no-buffering behavior (request.bodypassed straight to R2), and the CI release re-run is the definitive proof the 502 is gone.Follow-ups (out of scope here)
_download_sha256(the 409 idempotency re-check) still buffers the response; switch to chunkediter_content(rare path).