Skip to content

fix(deliveries): date a merge by the pull request's merged_at (#1290) - #1301

Merged
HugoXK merged 2 commits into
mainfrom
dev3/1290-merged-at
Nov 24, 2026
Merged

HugoXK merged 2 commits into
mainfrom
dev3/1290-merged-at

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Written-by: Fledge Platform Dev-3

Fixes #1290

The delivery ledger and the board item were dated by nowIso() at receipt, with the webhook payload already in hand. So a redelivered event, or an operator replay from the admin webhook page, moved a merge to today: delivery_outcomes.merged_at and the work item's merged_at shifted with the receipt, and the 90-day window plus any "merged this week" reading shifted with them.

What changed: the app's recordMergedDelivery closure takes one mergedAt parameter, and both call sites pass pull_request.merged_at from the payload they already hold; the work-item frame at both branches reads the same value. The receipt instant remains only as the fallback for a payload that carries no usable merged_at, and the (repo_id, pr_url) unique key still makes a replayed delivery a no-op. No new column, no backfill, nothing changed in the revert scan or the merge-commit column.

One guard beyond the card's wording: the payload value is accepted only when it parses as a date (Date.parse finite), otherwise the receipt fallback applies. Storing an unparsable string would sort wrongly in the ledger's merged_at DESC order and render an invalid instant on the page.

Alternatives considered: a second column holding GitHub's instant beside the receipt time — rejected, the card forbids a new column and two instants that disagree are worse than one that is right. Accepting any string the payload carries — rejected for the reason above.

Red first: commit 7118d28b is the tests alone. At the base 6ebb0902, npx tsx --test test/deliveryOutcome.test.ts printed # tests 16 / # pass 15 / # fail 1, and the failure was the half-1 assertion assert.equal(rows[0]?.merged_at, '2026-11-20T10:00:00Z', ...) with actual: '2026-11-24T11:25:12.889Z' (the receipt instant). The half-2 guard, a merge with no merged_at in the payload is still dated at receipt, passed at the base and still passes at the tip.

Note on the card's acceptance bullet 4: as written it is causally inverted. "A fix that passes half 1 by skipping rows whose merged_at is older than the receipt fails half 2" — such a fix fails half 1, because it never writes the late row that half 1 reads; half 2 is the guard that a fix cannot pass by refusing to record late deliveries. Recorded here rather than by editing the issue body, which is bound to the review hash 7ca4f3cea1ea.

Ran:

  • npx tsx --test test/deliveryOutcome.test.ts — 16 pass / 0 fail at the tip, 15 pass / 1 fail at the base
  • npm run check — exit 0: lint, typecheck, 3423 tests / 3423 pass / 0 fail, build
  • node scripts/risk-gate.mjs --base 6ebb0902c488267237b61a3e400cdb921d2d17d9 — risk-tier: T2; basis: src/app.ts
  • node scripts/changelog.mjs check — 15 fragment(s) ok

Not run: Docker image, a live webhook redelivery against a real repository, and the OpenAPI/meta-schema checks that belong to no part of this change.

Docs: docs/architecture.md's delivery paragraph now says which instant the row holds and where the fallback applies, so no Docs-not-needed: line.

Fledge Platform Dev-3 added 2 commits November 24, 2026 11:26
…ceipt (#1290)

Red at this tip: the ledger row and the work item are stamped with nowIso() at
receipt. The first case fails here; the second (no merged_at in the payload, one
row at receipt) already passes and is kept as the regression guard.
The recorder and both work-item frames stamped nowIso() with the payload in
hand, so a redelivered merge landed on the day of receipt. The app closure now
takes one mergedAt parameter, threaded from pull_request.merged_at at both call
sites, and keeps the receipt instant only when the payload carries no usable
value. docs/architecture.md says which instant the ledger holds.

@HugoXK-bot HugoXK-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: PASS at 67ade55
Written-by: HugoXK-bot
Author: Fledge Platform Verdict

Grounds:

  1. The defect is closed at both writers: src/app.ts:7247 reads pull.merged_at once (parsed, else null) and the ledger (:7171 via :7253/:7262) and the board item (:7252 create, :7260 update) all consume it; :7171's mergedAt ?? nowIso() is the only receipt fallback.
  2. Red first is the assertion, not a compile or fixture failure: at 7118d28b34ab (base 6ebb0902 + the test commit only) test/deliveryOutcome.test.ts is 15/16, not ok 14 failing actual '2026-11-24T11:58:41.985Z' vs '2026-11-20T10:00:00Z' at test/deliveryOutcome.test.ts:414; at the tip it is 16/16.
  3. Replay stays a no-op and nothing else moved: src/db.ts:4033-4036 inserts ON CONFLICT (repo_id, pr_url) DO NOTHING, test test/deliveryOutcome.test.ts:447 replays a second delivery id and still sees one row at the receipt instant (:449); the diff has no schema change and no backfill.
  4. Acceptance 4 is inverted in wording, not in substance: I read it as "the fix must not pass half 1 by refusing or skipping a late delivery". Half 1 (:414) requires the 2026-11-20 row to exist at the payload instant, and half 2 (:447-449) requires a payload without merged_at to still write one receipt-dated row; both hold at the tip, so no behaviour is missing from the card.
  5. Docs and changelog match: docs/architecture.md:1653-1656 names the stored instant and where the fallback applies; node scripts/changelog.mjs check reports 15 fragments ok; ci-ok, pr-lint, test (24), risk and coverage are success at this sha, and review-gate is red only for the missing verdict. No UI face.

Ran:

  • npx tsx --test test/deliveryOutcome.test.ts in the tip tree — 16/16 pass, exit 0.
  • npx tsx --test test/deliveryOutcome.test.ts at 7118d28b34ab — 15/16, not ok 14 with actual '2026-11-24T11:58:41.985Z', exit 1.
  • node scripts/changelog.mjs check — 15 fragment(s) ok, exit 0.
  • curl https://api.github.com/repos/HugoXK/fledge/pulls/1301/reviews — 0 reviews at this head; curl .../commits/67ade554.../check-runs?filter=latest — 31 runs, 0 pending.

Not run: npm run check locally, Docker, and a live webhook redelivery — the full suite is green in CI at this sha (ci-ok, test (24)), and the acceptance is covered by the two tests above.

@HugoXK-bot HugoXK-bot added the review:approved Issue reviewed and approved by the Fledge Platform Reviewer label Nov 24, 2026
@HugoXK
HugoXK merged commit 7a451f9 into main Nov 24, 2026
36 of 38 checks passed
@HugoXK
HugoXK deleted the dev3/1290-merged-at branch November 24, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Issue reviewed and approved by the Fledge Platform Reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(deliveries): a merge is dated by when Fledge received the webhook, not by GitHub merged_at

2 participants