Repository navigation
feat(storage): keep webhook bodies out of control.sqlite - #1407
zhaozhaozz wants to merge 1 commit into
Conversation
deliveries.payload holds about 8.4 GB of the production database and grows by about 640 MB a day (252,600 accepted deliveries in the last week, almost all over 2 KiB). An accepted body larger than 2 KiB is now written to its own file, webhook-bodies/<project>/<id[:2]>/<id>, and synced off the event loop before the row is inserted. The row keeps an empty payload, the file in payload_ref, its sha256 and size in the payload_sha256 / payload_bytes columns the retention cleanup already keeps, and in payload_summary the few fields the delivery list shows. Every reader goes through deliveryBody(): the console's event detail (which reports payload_unreadable instead of failing), external executors' event polling and subscription forwarding (an unreadable body counts as an unavailable source). The list reads the summary. Refused requests' digests and bodies of at most 2 KiB stay in the row. One file per delivery keeps the retention cleanup per delivery: a body past webhook_payload_days loses its file after the row is committed, and a delivery an external executor still has to receive keeps its body. Deleting a project removes its body directory. Existing rows move through a new deliveries phase of the background migration, which writes each file, syncs it, reads it back against its hash and only then points the row at it. The storage page counts the new directory. Refs agent-CI-Infra#1403
|
Reviewed head Blocking
Non-blocking suggestions
|
Refs #1403 (phase 2 of 4, see the plan; phase 1 was #1405).
What
deliveries.payload(webhook bodies) is the next largest body incontrol.sqlite: 8.38 GB in 422.5 k rows in production, none removed by retention yet.src/app/webhook.ts): an accepted body larger than 2 KiB is written to its own file,webhook-bodies/<project>/<id[:2]>/<id>beside the database (_for no project), as the received bytes (mode 0600). The write and itsfdatasyncrun with async IO before the transaction that inserts the row; the file is removed again if that transaction fails. The row keeps an emptypayload, the file inpayload_ref, its sha256 and size inpayload_sha256/payload_bytes(the columns the retention cleanup already kept for a removed body), and inpayload_summarythe few fields the delivery list shows, in the body's own shape. A refused request's digest and a body of at most 2 KiB stay in the row as before.deliveryBody(),src/storage/webhook-bodies.ts): returns the received bytes from the file (checked against the row's sha256) or from the row. An unreadable file is aDeliveryBodyError(delivery_body_missing/delivery_body_corrupt, file system error ascause).deliveriesphase ofPayloadMigration(second, aftertask_runs). Each file is written, then synced off the event loop and read back against its hash. Only after that does the row point at it. A slice moves at most 40 rows, because clearing a body frees its overflow pages and 150 rows took 150–190 ms to commit. Refused, small and already removed rows stay. If retention removed a body in the meantime, it stays removed and the new file is deleted.Read paths covered
/api/events,deliveryResult): readspayload_summary, falls back to the inline body for rows without one; never reads files./api/events/:id):deliveryBody(); an unreadable file shows an empty payload withpayload_unreadable: <code>instead of failing the view.src/external/events.ts) and subscription forwarding (src/external/forward.ts):deliveryBody(); a forward whose body cannot be read fails assource_unavailable, before the delivery is claimed.webhook_payload_days): the row is cleared as before (payload_removed_at, sha256 and size kept,payload_refcleared, summary kept so the list still names the repository) and the file is removed after the transaction commits; a delivery an executor still has to receive keeps its file.webhook-bodies/<project>/with the trajectory files.src/app/delivery-audit.ts) only reads refused rows, whose digests stay inline. No query filters on body fields.Webhook 正文 webhook-bodies.Side effect: the
UPDATE deliveries SET response=?that follows every accepted delivery no longer rewrites a ~18 KB row.Bytes per day (production, read-only sample 2026-11-19 → 11-26)
control.sqlitebeforeExisting 8.38 GB move in the background after deploy. As with phase 1, the database file shrinks only after a compaction, which will be planned separately.
Background migration speed (synthetic)
.tmpbenchmark (not committed): 5,000 accepted deliveries of 18.6 KB (93 MB), default options, local disk, machine load ≈2: 37 s (135 rows/s, 2.5 MB/s),failed 0, 0 bytes left in rows. Longest event-loop block 103 ms; p99 49 ms. Before the 40-row cap, one apply of ~150 rows took up to 190 ms. At this rate production's 422.5 k rows take about an hour on an idle disk, longer under IO pressure. Like the other phases, the migration pauses for the disk reserve and for descriptor exhaustion.Retention
Unchanged:
webhook_payload_days(unset in production) still removes bodies one delivery at a time with the same skip rule; files go with their rows and with the project.Tests
New or changed tests:
test/st/src/storage/webhook-bodies.test.mjs(new):payload_unreadable: delivery_body_corruptin the detail view and makes a forward fail assource_unavailable.test/st/src/storage/storage-retention.test.mjs: file-backed bodies pastwebhook_payload_dayslose their file. The row keeps sha256, size and summary and reads as empty. A body an executor still has to receive keeps its file until it has been sent.test/ut/src/storage/trajectory-migration.test.mjs: legacy inline rows read identically before and after the migration (bytes anddeliveryResult). Accepted large bodies move, including one without a project (filed under_). Refused, small and removed rows stay.deliveriesis read by rowid ranges.test/ut/static/storage-page-labels.test.mjs: the new storage row label.test/ut/src/storage/history-lookup-plan.test.mjs: its rawINSERT INTO deliveries VALUES(...)now names its columns, because the body columns exist from store start-up.test/fixtures/external-helpers.mjs:externalFixturetakes control-plane options (here a largermaxBodyBytes; the harness default of 2 KiB never produces a body over the threshold).Local record for head
23e8f953(on8a211c13, currentmain):npm ci/(cd runner && npm ci)npm run checkBOT_TEST_JOBS=8 npm testcodex-harness(wall-clock budgets, machine load 10–14) andrunner-transportnode test/framework/test-sets.mjs --jobs 1 test/st/src/harness/codex-harness.test.mjsTMPDIR=$PWD/.tmp/s node --test test/ut/manager/runner-transport.test.mjsEADDRINUSEfrom a Unix socket path over 108 bytes in this deep worktree)