Skip to content

feat(delivery): one stored body per content, rows point at it instead of carrying a copy CU-86akkb8f5 - #2886

Merged
semen-flamingo merged 3 commits into
mainfrom
feature/delivery-payload-store
Oct 30, 2026
Merged

semen-flamingo merged 3 commits into
mainfrom
feature/delivery-payload-store

Conversation

@semen-flamingo

@semen-flamingo semen-flamingo commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

The body of a delivery is stored once per distinct content in a new collection, machine_delivery_payload; a row in machine_delivery points at it instead of carrying its own copy. Every type, nothing to switch on.

Why: a rollout to a fleet (flags, an update) wrote the same payload into every row, and a script batch for a fleet will do the same with script bodies inside (Kirill's "payload by reference", Slack 2026-09-22 and 2026-10-30). Storage is one body per content now, and the content of a waiting delivery has one place to live.

How it works

  • DeliveryPayloadJson.body(payload) = the payload JSON without the row's delivery block, plus its SHA-256. Rows of one content share one hash.
  • DeliveryPayloadStore.hold(type, body, expiresAt) keeps the body under tenant:type:hash: read, and saved only when it is new or held shorter than this row needs, through the plain repository save (Kirill's review: no hand-written update, so tenant stamping, events and locks on the collection keep working). The expiry only moves forward. The TTL index is on expiresAt, like the rows.
  • DeliveryRecorder holds the body ten minutes longer than the row it writes (BODY_OUTLIVES_ROW_SECONDS): Mongo reaps expired documents once a minute per collection, and the margin also covers two pods saving the same new body a moment apart. The row carries payloadId; payloadJson is no longer written.
  • DeliverySweepService publishes from the body: the JSON comes from the store, the delivery block (type, targetId, dispatchId, sequence) is stamped from the row at publish time. A re-run therefore needs no payload copy any more (RerunPublication.payloadJson removed).
  • Rows written before this release still carry their body inline: the sweep reads payloadJson when a row has no payloadId, and upsertPending drops the inline body when a newer dispatch replaces such a row. They are gone with their TTL (30 days at most). No migration.
  • A body that is gone while its row is still open (cannot happen by the expiry rule, kept defensive) goes the ordinary error path of the sweep: counted, postponed, FAILED after max-attempts.
  • machine_delivery_rollout keeps its one copy per rollout, as before; the rows it produces all point at the same body.

Cost

Per recorded row: one primary read of the body and, only for a new body or a longer hold, one save, instead of a payload copy per row. One primary read of the body per publish from the sweep; the publish right after the hand-off still uses the payload in hand.

Next

Script batches drop the per-machine machineId field from the message (the agent never reads it), so one fire = one body for the whole fleet (follows in the scripts PR). Replacing the content of a waiting delivery when a script is edited is a re-dispatch of the same key from the domain; the recorder already lets the newer dispatch take the row.

Tests

DeliveryPayloadJsonTest (+ body/hash), DeliveryRecorderTest (+ body held, row points at it), DeliverySweepServiceTest (+ body read and stamped, body gone), DeliveryPayloadStoreTest (new), CustomMachineDeliveryRepositoryImplTest (rerun without a copy, inline body dropped on replace).

🤖 Generated with Claude Code

https://claude.ai/code/session_018qx6NqA97kwRxQ4hnD5jtu

… of carrying a copy CU-86akkb8f5

machine_delivery_payload holds the payload without the row's delivery block under tenant:type:hash,
written on first use with its expiry only moving forward; a row carries payloadId and the sweep stamps
the row's delivery block at publish time. Rows written before this read their inline payloadJson until
they expire; a re-run no longer stores a payload copy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018qx6NqA97kwRxQ4hnD5jtu
@github-actions

Copy link
Copy Markdown
Contributor

🦩 Flamingo Code Review

Not reviewed yet. Reviews start when you ask, so the reviewer reads this pull request when it is ready, not when it is opened.

When it is ready:

  • Review this pull request

Or comment @flamingo-review. Add the flamingo-review-always label to review every push.

Updated 2026-10-29 17:29 UTC · workflow run

kirill-567
kirill-567 previously approved these changes Oct 29, 2026
…ave, and a body outlives its rows by ten minutes CU-86akkb8f5

Kirill's review: no hand-written update on the collection, so tenant stamping, events and locks keep working.
DeliveryPayloadStore reads the body and saves it only when new or held shorter than the row needs; the
recorder holds it BODY_OUTLIVES_ROW_SECONDS longer than the row, past Mongo's once-a-minute TTL reaping and
the moment between two pods saving the same new body.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018qx6NqA97kwRxQ4hnD5jtu
@semen-flamingo
semen-flamingo added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit cb73624 Oct 30, 2026
2 of 3 checks passed
@semen-flamingo
semen-flamingo deleted the feature/delivery-payload-store branch October 30, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants