Skip to content

Commit 32b7ca4

Browse files
committed
feat(pm): relay deletes a closed mailbox's claude/mailbox-* head, and mailbox-open --close sends it
The relay gains mailbox_branch_delete, its one ref op: a DELETE of one refs/heads/claude/mailbox-* ref, refused unless the pull it names is closed, carries pm:mailbox, has that branch as its head on this repository, and no open pull has that head. The fences are judged by the executor on the pull's own answers immediately before the DELETE, and the delete lands only when the ref reads back absent. REFUSED_PATH_FAMILIES keeps refusing every other /git/ path; contents: write is already a literal grant on every stroke, so the workflow is untouched. mailbox-open --close appends the delete to its close stroke when the head it reads is claude/mailbox-*, so a cloud seat's mailbox leaves no branch. Claude-Session: https://claude.ai/code/session_016WV4cwSv11c8FvyR8ZuWhv Co-authored-by: Claude <noreply@anthropic.com>
1 parent b309866 commit 32b7ca4

4 files changed

Lines changed: 211 additions & 44 deletions

File tree

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

Lines changed: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@
190190
* read the parent and ⛔ never re-send. Every read is an unpaced GET, and the
191191
* one write is paced like every write verb.
192192
*
193+
* ## The mailbox branch delete — `mailbox_branch_delete`, fenced on the PULL and read back
194+
*
195+
* The fences (`ops.mjs` header, "The one row that deletes a ref") are facts
196+
* about the pull, so they are AUTHORITATIVE here (`mailboxBranchPreflight`):
197+
* the pull's own `GET` and the open pulls on `{owner}:{branch}`, the last two
198+
* reads before the DELETE, each fence that fails named, the DELETE NOT SENT.
199+
* The 204 is not the landing: `confirmMailboxBranch` reads the ref back, and
200+
* only an absent ref lands — a ref already gone (the DELETE's 422) is an
201+
* idempotent landing, a ref still there is a FAILED action.
202+
*
193203
* ## The advisory rows that write — fenced on the ADVISORY, printing none of its text
194204
*
195205
* `ops.mjs`'s header section "The rows that write a security advisory"
@@ -467,6 +477,7 @@ import {
467477
GOVERNED_REVIEW_FILES_PAGE_SIZE,
468478
GOVERNED_REVIEW_OPS,
469479
LOGIN_SHAPE,
480+
MAILBOX_LABEL,
470481
OPS,
471482
PERMISSIONS,
472483
PR_LANDED_STATE,
@@ -893,6 +904,42 @@ export async function confirmSubIssue(req, answer, pre, payload, api, t, { sleep
893904
return { ok: false, why: `${platform} accepted, but ${last} ${windowMs} ms later — UNCONFIRMED: read #${parent}'s sub-issues before anything else, ⛔ do not re-send` };
894905
}
895906

907+
/**
908+
* The mailbox branch delete's fences on the reads (header): `[]` to send, else one sentence per fence that fails —
909+
* an unread pull is one, judged alone. `pull` and `open` are `rest` answers. Pure.
910+
*/
911+
export function mailboxBranchFenceFailures({ repo, branch, pull, open }) {
912+
if (pull?.status !== 200 || !pull.json || typeof pull.json !== 'object') return [`${pull?.call} -> HTTP ${pull?.status}: the pull could not be read`];
913+
const pr = pull.json;
914+
const out = [];
915+
if (pr.state !== 'closed') out.push(`the pull is ${pr.state}, not closed`);
916+
if (!labelNames(pr.labels).includes(MAILBOX_LABEL)) out.push(`the pull does not carry ${MAILBOX_LABEL}`);
917+
if (pr.head?.ref !== branch) out.push(`the pull's head is ${pr.head?.ref ?? 'unread'}, not ${branch}`);
918+
if (String(pr.head?.repo?.full_name ?? '').toLowerCase() !== repo.toLowerCase()) out.push(`the pull's head lives on ${pr.head?.repo?.full_name ?? 'no repository'}, not ${repo}`);
919+
if (open?.status !== 200 || !Array.isArray(open.json)) out.push(`${open?.call} -> HTTP ${open?.status}: the open pulls on ${branch} could not be read`);
920+
else if (open.json.length) out.push(`open pull(s) ${open.json.map((p) => `#${p?.number}`).join(', ')} have ${branch} as head — the DELETE would close them`);
921+
return out;
922+
}
923+
924+
/** The fences, AUTHORITATIVE (header): the two reads, then `{}` to send or `{ fail }`, the DELETE NOT SENT. Never throws. */
925+
export async function mailboxBranchPreflight(req, payload, api, t) {
926+
const { pull, branch } = req.mailboxBranch;
927+
const repo = payload.repo;
928+
const pr = await rest(api, `/repos/${repo}/pulls/${pull}`, {}, t);
929+
const open = await rest(api, `/repos/${repo}/pulls?state=open&head=${encodeURIComponent(`${repo.split('/')[0]}:${branch}`)}`, {}, t);
930+
const failures = mailboxBranchFenceFailures({ repo, branch, pull: pr, open });
931+
return failures.length ? { fail: `REFUSED at the relay's fence on #${pull}'s head ${branch}, nothing sent — ${failures.join('; ')}` } : {};
932+
}
933+
934+
/** Did the delete LAND? The ref read back absent (header); a ref still there, or unread, is FAILED. Never throws. */
935+
export async function confirmMailboxBranch(req, answer, payload, api, t) {
936+
const { branch } = req.mailboxBranch;
937+
const back = await rest(api, `/repos/${payload.repo}/git/ref/heads/${branch}`, {}, t);
938+
const platform = `HTTP ${answer.status}${answer.detail ? ` — ${answer.detail}` : ''}`;
939+
if (back.status !== 404) return { ok: false, why: `${platform}, but ${back.call} answered HTTP ${back.status}: the branch ${back.status === 200 ? 'is still there' : 'could not be read back'} — read it before anything else` };
940+
return { ok: true, why: '', idempotent: !(answer.status >= 200 && answer.status < 300), result: `deleted ${branch} (read back absent)` };
941+
}
942+
896943
/**
897944
* The advisory's fences, AUTHORITATIVE (header: "The advisory rows that write"): its own GET, judged against
898945
* `ADVISORY_FENCES` — for `advisory_collaborators_add` an open advisory (`ADVISORY_OPEN_STATES`), for
@@ -1424,8 +1471,8 @@ export async function executeFleetWrite({ payload: raw, sender, token, api = DEF
14241471
break;
14251472
}
14261473
const req = filled.req;
1427-
// The failed-jobs re-run (header): its fences on the run and its pull, judged HERE on the reads before the POST — refused, NOT SENT.
1428-
const pre = req.rerunFailed ? await rerunFailedPreflight(req, payload, api, t) : null;
1474+
// The failed-jobs re-run and the mailbox branch delete (header): their fences, judged HERE on the reads before the write — refused, NOT SENT.
1475+
const pre = req.rerunFailed ? await rerunFailedPreflight(req, payload, api, t) : req.mailboxBranch ? await mailboxBranchPreflight(req, payload, api, t) : null;
14291476
if (pre?.fail) {
14301477
const why = scrub(pre.fail, [token]);
14311478
rows.push({ action: i + 1, op: action.op, call: `${req.verb} ${req.path}`, status: 'not sent', result: `FAILED: ${why}` });
@@ -1510,15 +1557,18 @@ export async function executeFleetWrite({ payload: raw, sender, token, api = DEF
15101557
// The failed-jobs re-run is confirmed by reading the run back (header): attempt 2, its failed jobs queued or in progress.
15111558
// The hierarchy link is confirmed by reading the parent's list back (header): the child's id listed, or no longer.
15121559
// The advisory rows are confirmed by their own answer (header): an id, every login sent, the state asked for — never by resultOf.
1560+
// The mailbox branch delete is confirmed by reading the ref back (header): absent, or it is FAILED.
15131561
const landed = req.updateBranch
15141562
? await confirmUpdateBranch(req, r, payload, api, t, ub)
15151563
: req.rerunFailed
15161564
? await confirmRerunFailed(req, r, pre, payload, api, t, rr)
1517-
: sub
1518-
? await confirmSubIssue(req, r, sub, payload, api, t, si)
1519-
: adv || req.advisoryReport || req.advisoryCreate
1520-
? confirmAdvisory(req, r, adv)
1521-
: requestLanded(req, r);
1565+
: req.mailboxBranch
1566+
? await confirmMailboxBranch(req, r, payload, api, t)
1567+
: sub
1568+
? await confirmSubIssue(req, r, sub, payload, api, t, si)
1569+
: adv || req.advisoryReport || req.advisoryCreate
1570+
? confirmAdvisory(req, r, adv)
1571+
: requestLanded(req, r);
15221572
const call = req.graphql ? `POST /graphql ${req.graphql.mutation}` : r.call;
15231573
rows.push({ action: i + 1, op: action.op, call, status: r.status, result: landed.ok ? (landed.idempotent ? 'already absent (idempotent)' : scrub(landed.result ?? resultOf(req, r.json, r.status), [token])) : `FAILED: ${scrub(landed.why, [token])}` });
15241574
if (!landed.ok) {
@@ -1593,11 +1643,13 @@ const SELF_TEST_BATTERIES = Object.freeze({
15931643
"the run_rerun_failed: the five fences judged HERE on the run and its pull, read immediately before ONE bodiless POST — the pull's current head by its own GET, never the run's embedded copy, and a run naming no pull refused by name; each refused with the POST not sent and accepted on the measured run; a run, pull, baseline or fence that fails is zero writes; the 201 confirmed only by reading attempt 2 back with its failed jobs queued or in progress, naming their job ids; attempt 2 never seen, a failed job completed, or a job list unread is FAILED; no annotation": 21,
15941644
"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,
15951645
"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,
1646+
"the mailbox branch delete: the pull's own answer and the open pulls on its head 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, 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,
15961647
"advisory_read: ONE GET after the sender gate and nothing written; the read, advisory and sender fences judged on that answer — target-write by the maintainer's ruling, a sender off the advisory's collaborators sealed for, one without write refused before the GET, any other gate closed — then the answer sealed to the seat's key and emitted as notice parts the reader parses back, opening byte for byte for that key and read alone; a failed or unsealed seal and an over-cap answer FAILED with nothing emitted; ⛔ the marker in the summary, description and vulnerabilities, and the advisory's id, reach no log line, row, step summary or annotation, and the sealed answer alone carries no marker": 18,
15971648
});
15981649
// Raised 17 → 18 with the governed-review follow-up battery, 18 → 19 with the run_rerun_failed battery, 19 → 20 with the
1599-
// hierarchy link battery, 20 → 21 with the advisory rows' battery, 21 → 22 with advisory_read's: one battery, one row.
1600-
const SELF_TEST_BATTERY_FLOOR = 22;
1650+
// hierarchy link battery, 20 → 21 with the advisory rows' battery, 21 → 22 with advisory_read's, 22 → 23 with the mailbox
1651+
// branch delete's: one battery, one row.
1652+
const SELF_TEST_BATTERY_FLOOR = 23;
16011653
const UNATTRIBUTED_BATTERY = '(unattributed)';
16021654

16031655
const batteryCases = new Map();
@@ -2457,6 +2509,46 @@ export async function selfTest() {
24572509
t('⛔ the parser is the reader\'s, imported — this file spells no pattern for the message of its own', [readReal(SELF_PATH, 'utf8').includes(['number=', '(['].join('')), typeof parseRelayAnnotation], [false, 'function']);
24582510
}
24592511

2512+
// ── the mailbox branch delete ───────────────────────────────────────────
2513+
battery("the mailbox branch delete: the pull's own answer and the open pulls on its head 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, 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");
2514+
{
2515+
const PR = 30141;
2516+
const BR = 'claude/mailbox-ui-3';
2517+
const PULL = `GET /repos/${REPO}/pulls/${PR}`;
2518+
const OPEN = `GET /repos/${REPO}/pulls`;
2519+
const DEL = `DELETE /repos/${REPO}/git/refs/heads/${BR}`;
2520+
const BACK = `GET /repos/${REPO}/git/ref/heads/${BR}`;
2521+
const box = (o = {}) => ({ number: PR, state: 'closed', labels: [{ name: 'pm:mailbox' }, { name: 'pinned' }], head: { ref: BR, repo: { full_name: REPO } }, ...o });
2522+
const good = { ...allowed, [PULL]: { status: 200, json: box() }, [OPEN]: { status: 200, json: [] }, [DEL]: { status: 204, json: null }, [BACK]: { status: 404, json: { message: 'Not Found' } } };
2523+
const drop = base([{ op: 'mailbox_branch_delete', pull: PR, branch: BR }]);
2524+
const ok = await run(drop, good);
2525+
t('the good case: the pull, then the open pulls on its head, then ONE DELETE of the ref under the App token, then the ref read back absent — exit 0, the row naming it deleted', [ok.exit, ok.seen.slice(1).map((s) => s.call), writes(ok.seen).map((s) => [s.call, s.body, s.auth]), ok.rows[0].result, ok.annotations], [EXIT_OK, [PULL, OPEN, DEL, BACK], [[DEL, null, `Bearer ${TOKEN}`]], `deleted ${BR} (read back absent)`, []]);
2526+
const urls = [];
2527+
await mailboxBranchPreflight(OPS.mailbox_branch_delete.requests({ op: 'mailbox_branch_delete', pull: PR, branch: BR }, REPO)[0], { repo: REPO }, 'https://api.test', { token: TOKEN, fetch: async (url) => (urls.push(url), { status: 200, headers: new Headers(), json: async () => [] }) });
2528+
t("the open-pulls read is filtered to this repository's owner and the branch — an unfiltered or mis-owned read would answer for other heads", urls[1], `https://api.test/repos/${REPO}/pulls?state=open&head=objectstack-ai%3Aclaude%2Fmailbox-ui-3`);
2529+
const fences = [
2530+
[{ [PULL]: { status: 200, json: box({ state: 'open' }) } }, 'the pull is open, not closed'],
2531+
[{ [PULL]: { status: 200, json: box({ labels: [{ name: 'pinned' }] }) } }, 'does not carry pm:mailbox'],
2532+
[{ [PULL]: { status: 200, json: box({ head: { ref: 'claude/mailbox-ui-2', repo: { full_name: REPO } } }) } }, "the pull's head is claude/mailbox-ui-2, not claude/mailbox-ui-3"],
2533+
[{ [PULL]: { status: 200, json: box({ head: { ref: BR, repo: { full_name: 'someone/objectstack' } } }) } }, "head lives on someone/objectstack, not objectstack-ai/objectstack"],
2534+
[{ [OPEN]: { status: 200, json: [{ number: 30999 }] } }, 'open pull(s) #30999 have claude/mailbox-ui-3 as head — the DELETE would close them'],
2535+
[{ [PULL]: { status: 404, json: { message: 'Not Found' } } }, 'the pull could not be read'],
2536+
[{ [OPEN]: { status: 503, json: { message: 'down' } } }, 'the open pulls on claude/mailbox-ui-3 could not be read'],
2537+
];
2538+
const fenced = await Promise.all(fences.map(async ([over, phrase]) => { const r = await run(drop, { ...good, ...over }); return [r.exit, writes(r.seen).length, r.rows[0]?.status, r.rows[0]?.result.includes(phrase)]; }));
2539+
t('⛔ each fence refuses with the DELETE NOT SENT and names itself: an open pull, no pm:mailbox, another head, a forked head, an open pull on the head, an unread pull, an unread open-pulls list', fenced, fences.map(() => [EXIT_ACTION_FAILED, 0, 'not sent', true]));
2540+
const kept = await run(drop, { ...good, [BACK]: { status: 200, json: { ref: `refs/heads/${BR}` } } });
2541+
t('⛔ a 204 whose ref still reads back is a FAILED action, never a landing', [kept.exit, kept.rows[0].status, kept.rows[0].result.includes('the branch is still there')], [EXIT_ACTION_FAILED, 204, true]);
2542+
const gone = await run(drop, { ...good, [DEL]: { status: 422, json: { message: 'Reference does not exist' } } });
2543+
t('a ref already gone — the DELETE answers 422, the ref reads back absent — is an idempotent landing', [gone.exit, gone.rows[0].result], [EXIT_OK, 'already absent (idempotent)']);
2544+
const { planClose } = await import('../mailbox-open.mjs');
2545+
const closing = { ...good, [`POST /repos/${REPO}/issues/${PR}/comments`]: { status: 201, json: { id: 9 } }, [`PATCH /repos/${REPO}/issues/${PR}`]: { status: 200, json: { number: PR, state: 'closed' } } };
2546+
const closed = await run(base(planClose({ repo: REPO, pull: PR, head: BR }).actions), closing);
2547+
t("⭐ after close, no branch: mailbox-open's close stroke sends the comment, the close and then the DELETE, reads the pull only after closing it, and ends on the ref read back absent — exit 0", [closed.exit, writes(closed.seen).map((s) => s.call), closed.seen.map((s) => s.call).indexOf(PULL) > closed.seen.map((s) => s.call).indexOf(`PATCH /repos/${REPO}/issues/${PR}`), closed.seen.at(-1).call, closed.rows.at(-1).result], [EXIT_OK, [`POST /repos/${REPO}/issues/${PR}/comments`, `PATCH /repos/${REPO}/issues/${PR}`, DEL], true, BACK, `deleted ${BR} (read back absent)`]);
2548+
const other = await run(base(planClose({ repo: REPO, pull: PR, head: 'claude/project-thread-mvsts5' }).actions), closing);
2549+
t('…while a head outside claude/mailbox-* — a thread branch the seat still works on — is closed and left: no DELETE, nothing under /git/', [other.exit, writes(other.seen).map((s) => s.call), other.seen.some((s) => s.call.includes('/git/'))], [EXIT_OK, [`POST /repos/${REPO}/issues/${PR}/comments`, `PATCH /repos/${REPO}/issues/${PR}`], false]);
2550+
}
2551+
24602552
// ── the advisory rows that write ────────────────────────────────────────
24612553
battery("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");
24622554
{

0 commit comments

Comments
 (0)