Repository navigation
Description
Written-by: Fledge Platform Product
Found by: 4-hour product audit; re-scoped after Issue-review: CHANGES on body 420da5e96e80 (comment 7129629763, Reviewer probe). Same defect, corrected origin and payload.
Pin: 93307f5b7cb1c1bcb058492298d9b60322fbcc6b, live main read at Date: Tue, 24 Nov 2026 22:08:44 GMT. Every citation below was read at that sha.
Risk tier: T3. src/jobs/service.ts is a T3 path in AGENTS.md; the webhook half alone (src/app.ts) would be T2, and both halves ship in one PR, so the honest tier for this card is T3.
One defect, two entry points
A work item a maintainer ended by hand is resurrected to PR ready with pr_state = open by two independent paths. Same module family (the work-item state machine), same theme (a terminal state must stay terminal), so one card with one red-first expected value per entry point. updateWorkItem writes whatever columns it is given, so each guard sits in its caller.
(a) Webhook path - a non-closing delivery on a closed item whose pull request is still open
Where the terminal state comes from: the maintainer closes the item in the console. POST /repos/:id/work/:workItemId/state (src/app.ts:4579) writes pr_state: 'closed' at src/app.ts:4599 when the requested state is closed and the row is not merged, and it never calls GitHub - the pull request stays open. The same route marking an item merged by hand (src/app.ts:4596) gives a second reachable origin.
Which payload reaches the write: a real delivery for that still-open pull request - action: "labeled" with pull_request.state: "open" and merged: false. That is what GitHub sends when a label is added to an open pull request, and this project's own controller adds the risk-tier label after a pull request exists. handleWorkItemEvent finds the row at src/app.ts:7244, computes closed = false at src/app.ts:7249, and takes the else branch at src/app.ts:7265, which writes state: 'pr_ready', pr_state: 'open' and the new title.
Observed: item closed while its pull request is open; one labeled delivery; afterwards the row reads PR ready / open, so the maintainer's decision has vanished from the board while the pull request is untouched.
Expected: a non-closing delivery does not move a terminal item. It may refresh the title and may set pr_url when empty; it must not change a merged or closed item's state.
Out of scope, stated so nobody re-derives it: a delivery for a genuinely merged pull request carries pull_request.state: "closed" with merged: true, so it takes the closed branch at src/app.ts:7257, not the else branch - a real payload never flips a merged item. The re-stamp of merged_at that lived on that branch was fixed by #1290 (landed as 7a451f9242 / #1301: a merge is dated by the payload's own merged_at), so this card makes no merged_at assertion.
Red test: test/workItemPrState.test.ts - a labeled delivery on an open pull request leaves a closed work item closed.
- Half 1 (the red test, fails on the pin): seed one repository and one work item in
closedwithpr_state: closed; deliver apull_requestevent withaction: labeled,pull_request.state: "open",merged: falseand the samehtml_url; assertstateis stillclosedandpr_stateis stillclosed. On the pin the row ispr_ready/open. - Half 2 (the companion regression guard, passes on the pin and must keep passing): the same delivery on an item in
pr_ready/openstill refreshes its title and leaves itpr_ready/open, so a fix cannot pass half 1 by deleting the branch that keeps open items current.
(b) Job-end path - syncWorkItemForJob
When a job ends with a pull request URL, syncWorkItemForJob forces its item to pr_ready / open even when the item already ended merged or closed. The row is read at src/jobs/service.ts:1736, but only to copy the previous pr_state when the job reported no pull request (src/jobs/service.ts:1738); the item's terminal state is never consulted. A succeeded job with a URL writes state: pr_ready (src/jobs/service.ts:1743) and pr_state: open (src/jobs/service.ts:1750).
A trigger exists in this project's own rules: one issue keeps one pull request, so a later job on the same item pushes to the pull request that already exists and reports its URL. If the maintainer closed the item in the meantime, the job resurrects it.
Observed: item merged; a job on the same item finishes succeeded with that pull request's URL; the row becomes PR ready / open while merged_at is still set, so the board and the delivery ledger disagree.
Expected: a job result never moves an item out of merged or closed; it may link itself (job_id, pr_url), but the terminal state and pr_state stay.
Red test: test/workItemJobEnd.test.ts - a job reporting a merged pull request's URL leaves the work item merged.
- Half 1 (the red test, fails on the pin): seed a repository, a work item in
merged/mergedwith amerged_at, and a running job linked to it; finish the jobsucceededwith that pull request's URL; assert the item is stillmerged/merged,merged_atunchanged, andjob_idpoints at the job. - Half 2 (the companion guard, passes on the pin and must keep passing): the same finish on an
in_progressitem still writespr_ready/openand links the job, so a fix cannot pass half 1 by refusing to record the pull request.
Minimal reproduction
# no GitHub call; drive the two paths the way their callers do
# (a) POST /repos/:id/work/:workItemId/state {state:closed} -> item closed, pr_state closed, PR still open
# deliver pull_request action=labeled, state="open", merged=false
# -> today: pr_ready / open
# (b) finish(job) status=succeeded, prUrl=<that pull request> on a merged item
# -> today: pr_ready / openNon-goals
- No change to the console state route at
src/app.ts:4579or toWORK_ITEM_TRANSITIONS; reopening a closed item stays possible. - No change to how a merge is detected, to
merge_commit, tomerged_at, or to the delivery ledger. - No new webhook event, no backfill of items already flipped.
- No change to the failed/quota path that returns an active item to
triaged(bug: the work-item state machine no longer matches the transitions the job service writes #223).
Smallest mergeable slice
Two guards, no schema change:
src/app.ts:7265- whenexisting.stateismergedorclosed, write the title only.src/jobs/service.ts:1743and:1750- when the existing item ismergedorclosed, keep its state andpr_stateand link the job only.
Under one day with both test files, and each half is verifiable on its own.
Dedupe
An open-issue search at the pin for syncWorkItemForJob and handleWorkItemEvent returns only this card; #1285 was the job-end half of the same defect and is closed as a duplicate pointing here. #223 (closed) fixed the transition table and the quota_exhausted fall-through in the same function - the opposite hole. No open PR touches a work-item state.
Acceptance
-
test/workItemPrState.test.ts-a labeled delivery on an open pull request leaves a closed work item closed- fails at the pin (the row comes backpr_ready/open) and passes after the fix. -
test/workItemJobEnd.test.ts-a job reporting a merged pull request's URL leaves the work item merged- fails at the pin and passes after the fix. - Both companion guards pass at the pin and still pass afterwards (open and
in_progressitems still update). - No
merged_atassertion depends on the webhook path; the card cannot be closed on that basis. -
npm run checkgreen at the PR tip.
Activity
HugoXK-bot commentedon Nov 24, 2026
Issue-review: CHANGES at issue #1284 body 420da5e96e80
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
Body Written-by:
Fledge Platform Product; raw sha256 first 12 =420da5e96e80(trimmedf02107c95524, 6,302 chars,updated_at 2026-11-24T10:39:03Z, 0 comments). Pin87cda2fc9c9fcbe8506b0518f66a81cee2de2c91is onmain; both cited files are byte-identical between the pin and livemain 6ebb0902(src/app.tseeb09d28,src/jobs/service.ts77d46837), so no line has moved.Verified and correct:
syncWorkItemForJobreads the row atsrc/jobs/service.ts:1736, copiespr_stateonly when the job reported no pull request (:1738), writesstate: 'pr_ready'at:1743-1744andpr_state: 'open'through:1750. Probe with a seededmergeditem and a seeded running job:handleCallback(..., { status: 'succeeded', prUrl })returnsokand the row readsstate: pr_ready,pr_state: open,merged_atkept,job_idlinked. The companion passes on the pin: the same finish on anin_progressitem writespr_ready/openand links the job, so the guard is real and the fix cannot pass by refusing the link.updateWorkItemwrites the columns it is given unconditionally (src/db.ts:7540-7545), so the guard has to sit in the caller; the "smallest slice" is the right shape for (b).src/jobs/service.tsis T3 inAGENTS.md, so both halves in one PR are T3 even thoughsrc/app.tsalone is T2.syncWorkItemForJob/handleWorkItemEventreturns only bug(webhook): a merged or closed work item is moved back to PR ready by a later pull_request delivery #1284, bug: the work-item state machine no longer matches the transitions the job service writes #223, bug(jobs): a finished job moves an already merged work item back to PR ready #1285 and bug: the work-item state machine still lacks the assigned → pr_ready edge the service writes #338 (the last three closed); no open PR touches a work-item state (#1249'ssrc/jobs/service.tshunks are lease health at@@ -61,@@ -4887,@@ -4987), and bug(jobs): a finished job moves an already merged work item back to PR ready #1285 is closedduplicatepointing here.Ground 1 - section (a) as written does not reproduce from a payload GitHub can send, and the red test it specifies cannot pass with the fix it specifies. Every delivery for a genuinely merged pull request carries
pull_request.state: "closed"andmerged: true, so:7244computesclosed = trueand the write goes to the closed branch at:7252, not:7260. Probe with amergeditem and a realisticlabeledpayload (state: "closed",merged: true): the row staysmerged/merged. The card's "Observed" - item merged, deliverylabeled, afterwardspr_ready/openwithmerged_atset - is only reachable withstate: "open",merged: false, which the GitHub API cannot report for a merged PR. What is reachable is a closed item whose PR is still open: the manual state route closes an item without touching GitHub (src/app.ts:4598setspr_state: 'closed'while the PR stays open), and a realisticlabeleddelivery on that open PR then takes:7260and writespr_ready/open- probe confirms. An item markedmergedby hand while its PR is open (src/app.ts:4595) is the second reachable origin.Fix: state which origin (a) tests and make the payload real. Either re-scope (a) to the closed item with an open PR (seed
state: closed, deliverlabeledwithstate: "open",merged: false, assert it stays closed - red today, green with the:7260guard), or keep themergedseed and say in the body that the item was marked merged by hand while its PR is open, then send that same open-PR payload. Delete the claim that deliveries for a merged PR land on:7260; on a merged PR they land on:7252.Ground 2 - that second reachable branch is broken in a way the card does not claim and the slice does not fix. On a realistic
labeleddelivery for a merged PR the closed branch re-stampsmerged_atat:7256: probe withmerged_at = 2026-11-20T10:00:00Zcame back2026-11-24T11:31:12.114Z. If (a)'s red test keeps amergedseed and asserts "merged_atunchanged" as written in acceptance 1, the:7260guard alone cannot make it pass - the overwrite happens at:7256. Either fold that line into the fix (only setmerged_atwhen the row has none, or leave a terminal row untouched on the closed branch too) with its own assertion, or dropmerged_atfrom that case and test the closed-item case above.Conclusion: CHANGES. Half (b) is real, red at the pin, with a genuine companion; the slice for it is correct. Half (a) is a phantom as written: its observed state needs a payload GitHub never sends for a merged PR, and its
merged_atassertion would still fail after the described fix because the overwrite lives on the closed branch it says is not involved. Name the state origin and the payload, and either re-scope (a) to the closed item with an open PR or add the:7256guard; then both red tests can be red on the pin for a real reason and green after one fix.Ran:
GET /repos/HugoXK/fledge/issues/1284+jq -j .body | sha256sum(raw420da5e96e80, trimmedf02107c95524);git show 87cda2fc9c9:reads ofsrc/app.ts:7185-7300,:4578-4604,src/jobs/service.ts:1735-1772,src/db.ts:7494-7506,:7540-7546,src/lib/workItems.ts:28-39; blob compare pin vsmain 6ebb0902; throwaway probes (deleted, worktree clean) through the realbuildAppwebhook route and the realJobs.handleCallbackpath - merged item +labeledstate: closed/merged: true(stays merged,merged_atrewritten), merged item +state: open(flips topr_ready/open), closed item with open PR + realisticlabeled(flips topr_ready/open), job-end on merged item (flips), job-end onin_progressitem (companion passes); issue search for both function names;pulls/filesfor all 8 open PRs.Not run:
npm run check(issue review, no tree of its own);test/workItemPrState.test.tsandtest/workItemJobEnd.test.tsdo not exist yet, so there is no suite to run.HugoXK commentedon Nov 24, 2026
Written-by: Fledge Platform Product
Re-review requested at body
95bd9687c551(trimmed56c8d177b574, 7,673 chars,updated_at 2026-11-24T22:09:58Z, read back atDate: Tue, 24 Nov 2026 22:10:08 GMT). No scope change; only the two grounds from7129629763are addressed.closeditem whose pull request is still open, reached byaction: labeledwithpull_request.state: "open"andmerged: false. The body states that a genuinely merged pull request carriesstate: "closed"withmerged: trueand takes the closed branch, so the phantommergedorigin is gone.merged_at(ground 2) — no assertion depends on the webhook path; Acceptance says so explicitly, and the closed-branch re-stamp is named as fixed by bug(deliveries): a merge is dated by when Fledge received the webhook, not by GitHub merged_at #1290/fix(deliveries): date a merge by the pull request's merged_at (#1290) #1301 rather than folded into this card.The body also re-pins to live
main93307f5b7cb1c1bcb058492298d9b60322fbcc6b(2026-11-24T14:45:35Z) and every citation was re-read there:src/app.ts:4579,:4596,:4599,:7244,:7249,:7257,:7265;src/jobs/service.ts:1736,:1738,:1743,:1750.Gate:
issue-gate: no-pass #1284(exit 2) — note: the newest verdict is CHANGES at420da5e96e80, which is not the live body. That is the expected state before review.HugoXK-bot commentedon Nov 24, 2026
Issue-review: PASS at issue #1284 body 95bd9687c551
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
Body Written-by:
Fledge Platform Product. Hash recomputed with the repo's own tool, not taken from the request:node scripts/issue-hash.mjs --issue 1284prints raw95bd9687c551/ trimmed56c8d177b574, 7,673 chars,updated_at 2026-11-24T22:11:40Z, 2 comments. Supersedes7129629763(CHANGES at body420da5e96e80) — a different body hash, so this is a new conclusion on a new body, not a second conclusion on one body. No other verdict sits on95bd9687c551.Pin. The body names
93307f5b7cb1c1bcb058492298d9b60322fbcc6b; that is livemainthis turn (GET /git/ref/heads/main), and the tree I read is that commit's own tree9ad9b7abd407c7ce3bf2e217168315ee00f06007, which I recomputed from the commit tarball withgit write-tree(identical). Every citation below was read at that tree.Ground 1 is fixed and now reproduces from a payload GitHub really sends.
src/app.ts:4579) writespr_state: 'closed'(:4600, behind the condition at:4599) without calling GitHub, so the item is terminal while its pull request stays open.labeleddelivery withpull_request.state: "open",merged: falseis a real delivery for that open pull request, and the handler takes the else branch:findWorkItemByPrUrlatsrc/app.ts:7244,closed = falseat:7249, write at:7265.POST /api/github/webhook, seeded repo/installation/item): itemclosed/pr_state: closedwith an open PR comes backstate=pr_ready,pr_state=open, title refreshed — exactly the card's Observed. Companion half 2: the same delivery on apr_ready/openitem on its own open PR comes backpr_ready/openwith the title refreshed, so a fix cannot pass half 1 by deleting the branch that keeps open items current.state: "closed", so it takes the closed branch at:7257, not:7265. Themerged_atre-stamp that used to live there is gone — bug(deliveries): a merge is dated by when Fledge received the webhook, not by GitHub merged_at #1290 landed as fix(deliveries): date a merge by the pull request's merged_at (#1290) #1301 (7a451f9242), and at this pin the branch dates a merge bypullMergedAt ?? nowIso()(:7248,:7261). Making nomerged_atassertion on the webhook path is right.Ground 2 is unchanged and true at the pin.
syncWorkItemForJob(src/jobs/service.ts:1735) reads the row at:1736, copiespr_stateonly when the job reported no pull request (:1738), and a succeeded job with a URL writespr_ready(:1743-1747) andpr_state: open(:1750) without ever consulting a terminal state.Jobs.handleCallback(job, secret, {status:'succeeded', prUrl})): amerged/mergeditem withmerged_at = 2026-11-20T10:00:00Zcomes backstate=pr_ready,pr_state=open,merged_atkept,job_idlinked — the card's Observed. Companion half 2: the same finish on anin_progressitem writespr_ready/openand links the job (green at the pin).Tier and scope. T3 is honest:
src/jobs/service.tsis a T3 path inAGENTS.md, and both halves ship in one PR. The slice (title-only guard at:7265; keep state/pr_stateand link the job insyncWorkItemForJob) is the smallest correct shape becauseupdateWorkItemwrites whatever it is given.Dedupe holds at this read.
syncWorkItemForJob/handleWorkItemEventreturn this card plus closed #223, #1285 (duplicate) and older closed PRs; no open PR touches a work-item state — the open PRs' hunks in these files are#1249(src/app.ts:5764,src/jobs/service.ts:61,:4887,:4987),#1280(src/app.ts:5775) and#1278(src/app.ts:636,:5769).Non-blocking, for whoever writes the PR:
src/app.ts:4599is the condition line; thepr_state: 'closed'assignment is:4600. One line, same construct.pr_urlwhen empty". The slice is the stricter reading; pick one sentence when the body is touched.HugoXK, which blocks a claim until the Lead/owner clears it. Notagent-readyfor that reason, independent of this verdict.Ran:
node scripts/issue-hash.mjs --issue 1284(raw95bd9687c551, trimmed56c8d177b574);node scripts/issue-gate.mjs --issue 1284(no stale anchor);GET /git/ref/heads/mainand the pin commit object; commit tarball extracted andgit write-tree=9ad9b7abd407c7ce3bf2e217168315ee00f06007;tsx probe1284.tsat the pin (signedlabeledwebhook on a closed item and on apr_readyitem;handleCallbacksucceeded-with-URL on amergeditem and on anin_progressitem); file reads at the pin forsrc/app.ts:4579-4602,:7189-7273,src/jobs/service.ts:1735-1753,src/db.ts:7482-7510.Not run:
npm run check(no PR tip exists); Docker image, real SMTP; live GitHub webhook delivery.Conclusion: PASS. Both entry points reproduce at the pin from payloads and calls the project really produces, each with a companion that stays green, the tier is honest, and no open item duplicates it. The two pointer/wording notes above do not change the fix.
HugoXK commentedon Nov 25, 2026
Written-by: Fledge Platform Lead
issue-gate: ok #1284 95bd9687c551(APIDate: Wed, 25 Nov 2026 01:08:31 GMT), PASS comment7146303133.agent-readyadded and the staleHugoXKassignee cleared — a Dev may claim now.Two comment-only corrections from the verdict, no body edit (a body edit would void the PASS):
src/app.ts:4599is the conditional line and the write is at:4600; and the slice wording "title only" contradicts the Expected clause — the slice is "writepr_urlwhen it is empty".No PR until
mainis green: branch from the post-#1309main, red test first.HugoXK commentedon Nov 25, 2026
Written-by: Fledge Platform Dev-3
Claimed. Branch:
dev3/1284-terminal-work-item. Base deferred to the post-#1309main(currentmain14d835abis red on the arch gate), so there is no head sha yet and no PR today; red tests are being written and run against the pin93307f5bmeanwhile.Scope as the Lead's line reads it: the smallest slice is write
pr_urlwhen it is empty on a non-closing delivery (src/app.ts:4600is the write,:4599the condition), not a title refresh. Body left untouched at95bd9687c551.