Skip to content

Commit 0bbf4a3

Browse files
committed
pm: the dequeue reads the pull open and unmerged twice, one poll apart
The queue's removal and the pull's merge arrive seconds apart in either order, so one pull read the moment the queue stops listing it can miss a merge. The read-back now lands only when two pull reads one poll interval apart both read it open with merged false. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nn2c5rose69uoEzmE
1 parent febb3a9 commit 0bbf4a3

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎scripts/pm/fleet-write/execute.mjs‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
* read answered (no second read between the comment and the mutation); then
212212
* the queue re-read every `DEQUEUE_POLL_MS` for up to `DEQUEUE_WINDOW_MS`
213213
* until it no longer lists the pull, and the pull's own GET read open with
214-
* `merged` false (`dequeuePullAfter`). GraphQL errors are FAILED naming the
214+
* `merged` false (`dequeuePullAfter`) twice, one `DEQUEUE_POLL_MS` apart. GraphQL errors are FAILED naming the
215215
* grant when the platform says "not accessible by integration"; a pull that
216216
* merged, or closed, inside the window is FAILED naming it; a read-back that
217217
* still lists the pull after the window is FAILED, UNCONFIRMED. Every failure after the comment names the
@@ -1452,10 +1452,17 @@ export async function dequeueAction(req, { payload, api, t, sleep, now, windowMs
14521452
const v = dequeueReadBack({ pull, queue: q.queue });
14531453
if (!v.ok) last = v.why;
14541454
else {
1455-
// Out of the queue is half the landing: the pull's own GET must read it still open and unmerged (header).
1456-
const after = dequeuePullAfter(await rest(api, `/repos/${payload.repo}/pulls/${pull}`, {}, t));
1457-
if (after.ok) return { ok: true, call: mutation, status: r.status, result: dequeueLandedText({ pull, total: q.queue.entries.length, auditId }) };
1458-
if (!after.pending) return { ok: false, call: mutation, status: r.status, why: `HTTP 200 accepted and the queue no longer lists #${pull}, but ${after.why}; audit comment ${auditId} stands — ⛔ do not re-send, read the pull and report to the maintainer` };
1455+
// Out of the queue is half the landing: the pull's own GET must read it still open and unmerged, TWICE, one
1456+
// poll apart — the queue's removal and `merged` arrive seconds apart in either order (header).
1457+
const readPull = async () => dequeuePullAfter(await rest(api, `/repos/${payload.repo}/pulls/${pull}`, {}, t));
1458+
const merged = (after) => ({ ok: false, call: mutation, status: r.status, why: `HTTP 200 accepted and the queue no longer lists #${pull}, but ${after.why}; audit comment ${auditId} stands — ⛔ do not re-send, read the pull and report to the maintainer` });
1459+
let after = await readPull();
1460+
if (after.ok) {
1461+
await sleep(pollMs);
1462+
after = await readPull();
1463+
if (after.ok) return { ok: true, call: mutation, status: r.status, result: dequeueLandedText({ pull, total: q.queue.entries.length, auditId }) };
1464+
}
1465+
if (!after.pending) return merged(after);
14591466
last = after.why;
14601467
}
14611468
}
@@ -2551,8 +2558,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
25512558
// 9 → 12 with a carrying comment that opens with a seat signature refused, its other way, and no reader carrying nothing.
25522559
"the pr_enqueue_front SIZE lift: a pull over the human-merge line is jumped only on an authorised APPROVED review on its current head, or an earlier one carried to the head by an authorised comment on the pull naming it — the reviews read only over the line, a full page or an unread list lifting nothing, a non-approver, an approval elsewhere, a comment naming another head or pull or opening with a seat signature refused with the mutation not sent": 12,
25532560
// 16 → 27 with seat-asks bound to the landing seat (another seat, the relay's own audit, no trailer, the pure match),
2554-
// the pull read back open and unmerged (merged, closed, a late read, the pure reading) and the node id from the first read.
2555-
"the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged, a merge or close inside the window FAILED, UNCONFIRMED after the window": 27,
2561+
// the pull read back open and unmerged (merged, closed, a late read, the pure reading) and the node id from the first read;
2562+
// 27 → 28 with the second pull read one interval later, a merge that shows only there refused.
2563+
"the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged on two reads one interval apart, a merge or close inside the window FAILED, UNCONFIRMED after the window": 28,
25562564
"the hierarchy link: sub_issue_add and sub_issue_remove read the parent's and the child's own answers, then the child's parent (add) or the parent's whole list (remove), immediately before ONE write whose body is the child's REST id from its own answer — never its number, never replace_parent; a pull, a transferred or unread card, a child under another parent, one the parent does not list, or a read that is neither answer is zero writes; a child already under this parent is a no-op landed on the list; the answer confirmed only when the parent's list reads the child back (or no longer does) inside the window; a refused write, a list that never settles or never reads whole is FAILED; no annotation, and the rows ride a stroke beside other ops": 20,
25572565
"the advisory rows: advisory_report and advisory_create are ONE POST of their body each, landed on a 2xx carrying an id — a draft's reading state draft — that the row and a notice annotation name; advisory_collaborators_add, advisory_versions and advisory_state read the advisory first and send ONE PATCH — every existing login kept with the missing ones added, an all-present list a no-op, the versions entries alone, or the one state a legal transition reaches, the reopen and the publish among them — or nothing at all on a fence: an unread, other or wrong-state advisory, an illegal move, a list the versions may not replace or a publish whose versions are not set; each lands only when its answer shows the result, a publish only read back as published with the versions it was sent, and a landed publish alone is annotated with its id; ⛔ the marker in a report's or a draft's summary, description and packages and in every advisory answer's summary, description and vulnerabilities reaches no log line, row, step summary or annotation": 41,
25582566
"the mailbox branch delete: the pull's own answer, the open pulls on its head and the ref read immediately before ONE DELETE of the ref under the App token — an open, unlabelled, other-headed or forked pull, an open pull on that head, a ref moved off the pull's head, or a read that does not answer is zero writes with every failing fence named; the DELETE lands only when the ref reads back absent, a ref already gone an idempotent landing and one still there FAILED; and mailbox-open's close stroke — comment, close, delete — leaves no branch, while a head outside claude/mailbox-* sends no DELETE": 7,
@@ -3426,7 +3434,7 @@ export async function selfTest() {
34263434
}
34273435

34283436
// ── the dequeue ─────────────────────────────────────────────────────────
3429-
battery("the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged, a merge or close inside the window FAILED, UNCONFIRMED after the window");
3437+
battery("the pr_dequeue: the pull's own GET, its base's queue with each entry's merge-group rollup and, for seat-asks alone, its comments read before ONE audit comment and ONE dequeuePullRequest mutation — open, its head, not Version Packages, a queue read whole that lists it, and the cause holding on those reads (conflict: dirty; own-failure: UNMERGEABLE or a failing rollup, never an unread one; seat-asks: a relay comment signed by the landing seat its body's trailer names, under the dispatching session — another seat's comment refused); each fence refused with nothing written; no audit comment, no mutation; GraphQL errors FAILED naming the grant; the 200 confirmed only by reading the queue back without the pull and the pull still open and unmerged on two reads one interval apart, a merge or close inside the window FAILED, UNCONFIRMED after the window");
34303438
{
34313439
const PULL = 3591;
34323440
const HEAD = '5c1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c';
@@ -3452,7 +3460,7 @@ export async function selfTest() {
34523460
const mutations = (seen) => seen.filter((x) => x.call === GQL && x.body?.query?.startsWith('mutation'));
34533461
const audits = (seen) => seen.filter((x) => x.call === AUDIT);
34543462
const ok = await run(stroke(), happy, timing);
3455-
t('⭐ conflict: the sender gate, the pull, its queue — then ONE audit comment, ONE mutation on the node id the first pull read answered (no second read between the comment and the mutation), the queue read back, the pull read back; exit 0', [ok.exit, ok.seen.map((x) => x.call)], [EXIT_OK, [PERM, PULL_GET, GQL, AUDIT, GQL, GQL, PULL_GET]], ok.logs.join(' | '));
3463+
t('⭐ conflict: the sender gate, the pull, its queue — then ONE audit comment, ONE mutation on the node id the first pull read answered (no second read between the comment and the mutation), the queue read back, the pull read back twice; exit 0', [ok.exit, ok.seen.map((x) => x.call)], [EXIT_OK, [PERM, PULL_GET, GQL, AUDIT, GQL, GQL, PULL_GET, PULL_GET]], ok.logs.join(' | '));
34563464
t('…the queue read selects each entry\'s merge-group rollup, the mutation sends the pull\'s node id to dequeuePullRequest', [ok.seen[2].body.query.includes('statusCheckRollup { state }'), mutations(ok.seen).map((m) => [m.body.query.includes('dequeuePullRequest(input: { id: $id })'), m.body.variables])], [true, [[true, { id: 'PR_kwDOout' }]]]);
34573465
const body = audits(ok.seen)[0]?.body?.body ?? '';
34583466
t('…the ONE audit comment names the session, the request, the cause, what the relay read and the seat\'s reason', [SESSION, 'fw-test-1', 'cause `conflict`', 'mergeable_state dirty', 'conflicts with main at the shared changeset'].map((w) => body.includes(w)), [true, true, true, true, true]);
@@ -3491,15 +3499,20 @@ export async function selfTest() {
34913499
t('⛔ a read-back that still lists the pull is FAILED, UNCONFIRMED, after the window — a 200 is never trusted alone', [still.exit, still.rows[0]?.result.includes('UNCONFIRMED'), still.rows[0]?.result.includes('still lists'), clock], [EXIT_ACTION_FAILED, true, true, DEQUEUE_WINDOW_MS]);
34923500
clock = 0;
34933501
const late = await run(stroke(), { ...happy, [GQL]: [before, dequeued, before, after] }, timing);
3494-
t('an entry gone on a later read lands, read again at the interval', [late.exit, clock], [EXIT_OK, DEQUEUE_POLL_MS]);
3502+
t('an entry gone on a later read lands, read again at the interval, then the pull read twice one interval apart', [late.exit, clock], [EXIT_OK, 2 * DEQUEUE_POLL_MS]);
34953503
clock = 0;
34963504
const merged = await run(stroke({ cause: 'seat-asks' }), { ...happy, ...asks(signed(RELAY_COMMENT_AUTHOR, SESSION)), [PULL_GET]: [pullAt({ mergeable: true, mergeable_state: 'clean' }), pullAt({ state: 'closed', merged: true, merged_at: '2026-11-15T08:40:12Z' })] }, timing);
34973505
t('⛔ a pull that MERGES inside the window left the queue by landing: FAILED naming the merge, never a landed dequeue, never UNCONFIRMED or re-read', [merged.exit, merged.rows[0]?.result.includes('MERGED at 2026-11-15T08:40:12Z'), merged.rows[0]?.result.includes('UNCONFIRMED'), clock], [EXIT_ACTION_FAILED, true, false, 0]);
34983506
const closed = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt({ state: 'closed' })] }, timing);
34993507
t('⛔ a pull read back closed unmerged is FAILED too — out of the queue and not open is no dequeue landing', [closed.exit, closed.rows[0]?.result.includes('state closed')], [EXIT_ACTION_FAILED, true]);
35003508
clock = 0;
35013509
const pullLate = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), { status: 502, json: { message: 'Bad Gateway' } }, pullAt()] }, timing);
3502-
t('a pull read that fails after the queue reads it gone is read again at the interval, and lands when it reads open and unmerged', [pullLate.exit, clock], [EXIT_OK, DEQUEUE_POLL_MS]);
3510+
t('a pull read that fails after the queue reads it gone is read again at the interval, and lands when it reads open and unmerged', [pullLate.exit, clock], [EXIT_OK, 2 * DEQUEUE_POLL_MS]);
3511+
clock = 0;
3512+
const mergedLate = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt(), pullAt({ state: 'closed', merged: true, merged_at: '2026-11-15T08:40:15Z' })] }, timing);
3513+
const mergedLateClock = clock;
3514+
const mergedAtOnly = await run(stroke(), { ...happy, [PULL_GET]: [pullAt(), pullAt(), pullAt({ merged: false, merged_at: '2026-11-15T08:40:15Z' })] }, timing);
3515+
t('⛔ a merge that shows only on the SECOND pull read, one interval after the first read it open and unmerged, is FAILED naming the merge — the queue\'s removal and `merged` arrive in either order; `merged_at` beside a false `merged` reads as merged too', [mergedLate.exit, mergedLate.rows[0]?.result.includes('MERGED at 2026-11-15T08:40:15Z'), mergedLateClock, mergedAtOnly.exit, mergedAtOnly.rows[0]?.result.includes('MERGED')], [EXIT_ACTION_FAILED, true, DEQUEUE_POLL_MS, EXIT_ACTION_FAILED, true]);
35033516
t('dequeuePullAfter: open and merged false lands; merged, closed or an unread merged flag does not', [dequeuePullAfter({ status: 200, json: { state: 'open', merged: false } }).ok, dequeuePullAfter({ status: 200, json: { state: 'closed', merged: true } }).pending, dequeuePullAfter({ status: 200, json: { state: 'closed', merged: false } }).pending, dequeuePullAfter({ status: 200, json: { state: 'open' } }).pending, dequeuePullAfter({ status: 404, json: {} }).pending], [true, false, false, true, true]);
35043517
t('dequeueReadBack: a truncated list is pending, a base with no queue lists nothing', [dequeueReadBack({ pull: 1, queue: { present: true, complete: false, entries: [] } }).pending, dequeueReadBack({ pull: 1, queue: { present: false, complete: true, entries: [] } }).ok], [true, true]);
35053518
const beside = await run(base([stroke().actions[0], { op: 'comment', issue: 1, body: 'x' }]), happy);

‎scripts/pm/fleet-write/ops.mjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,10 @@
427427
* The 200 is an acceptance, not a landing: the executor re-reads the queue
428428
* every `DEQUEUE_POLL_MS` for up to `DEQUEUE_WINDOW_MS` and lands only when
429429
* the pull is no longer listed (`dequeueReadBack`) AND its own GET reads it
430-
* still open with `merged` false (`dequeuePullAfter`) — out of the queue and
431-
* not landed, the two readings `platform-readings.md` asks for. A pull that
430+
* still open with `merged` false (`dequeuePullAfter`) on two reads one poll
431+
* apart — out of the queue and not landed, the two readings
432+
* `platform-readings.md` asks for, whose removal and `merged` arrive seconds
433+
* apart in either order. A pull that
432434
* left by MERGING inside the window is a FAILED action naming the merge; one
433435
* closed unmerged is FAILED too. A read-back that still lists it after the
434436
* window is a FAILED action, UNCONFIRMED — ⛔ a 200 is never trusted alone. WHEN a seat may send it is pm-dispatch's rule

0 commit comments

Comments
 (0)