Skip to content

Commit 5938091

Browse files
committed
fix(pm): label-write judges a release comment on post-stamped's path and hands sendFleetWrite its read-back judge
--release now judges its composed body with judgeBody in comment mode, so an unsigned release text is refused with exit 2 before the stroke. Every relay send passes the read-back judge, so sendFleetWrite no longer imports post-stamped under label-write's top-level await, which never settled. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jR91pcCzC1k9n3p5ah
1 parent 7d50fb8 commit 5938091

1 file changed

Lines changed: 76 additions & 18 deletions

File tree

‎scripts/pm/label-write.mjs‎

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@
118118
* `pm:dispatched` off, every assignee off. The holder's seat post
119119
* is not an action here and cannot become one — every action
120120
* names the card.
121+
* judged the composed comment — the operator's text, the resume line and
122+
* the clock reading — by post-stamped's `judgeBody` in comment mode,
123+
* the ONE path `--comment-file` and post-stamped's own `--comment`
124+
* take (`composeReleaseBody`): the stamp contract, the signature
125+
* first line, the comment-mode keyed-line readers. An unsigned text
126+
* is exit 2 with zero writes, before the stroke, its refusal
127+
* post-stamped's own text naming this tool.
121128
* read-back the card's labels and assignees against the ② target, and the
122129
* release comment located on the board by its stored bytes
123130
* (post-stamped's `pickRelayComment`). A board that disagrees is
@@ -171,6 +178,17 @@
171178
* is exit 3 with zero writes — send the comment through post-stamped and the labels here, as before. A comment
172179
* with nothing to fold beside it is refused (exit 2): that write is post-stamped's.
173180
*
181+
* ## The read-back judge is HANDED to `sendFleetWrite`, never loaded by it
182+
*
183+
* Every send from this file passes `judge` (`readBackJudge`: post-stamped's `classifyReadBack` and
184+
* `sentBodyLanded`). Without it `sendFleetWrite` loads the judge with a dynamic `import('../post-stamped.mjs')`
185+
* once a stroke that carries a body has run, and that import never settles here: this file, post-stamped and
186+
* `fleet-write/dispatch.mjs` import one another, so the three evaluate as ONE cycle whose completion waits on
187+
* this file's top-level `await main(…)` — the very await the import sits under. Node then drains its event loop
188+
* and exits 13 ("unsettled top-level await") after the relay run succeeded, with no `④` line printed, and a seat
189+
* that re-runs posts the comment twice. The self-test drives both comment strokes through the REAL
190+
* `sendFleetWrite` (`realTransport`: only fetch, clock, sleeps and throttle file are fake) to pin it.
191+
*
174192
* ## A retired lane alias is written as its lane
175193
*
176194
* An `--add` naming a retired lane spelling (`domain:engine`, `domain:services`,
@@ -277,14 +295,29 @@ import {
277295
// reaches this file through `fleet-write/dispatch.mjs`, so a module-scope use
278296
// here would read a binding that has not been initialised yet when
279297
// post-stamped is the entrypoint.
280-
import { PLATFORM_COMMENT_FOOTER, judgeBody, pickRelayComment, readBackVerdict as commentReadBackVerdict, relayAction, renderBody, substitutionSummary } from './post-stamped.mjs';
298+
import {
299+
PLATFORM_COMMENT_FOOTER,
300+
classifyReadBack,
301+
judgeBody,
302+
pickRelayComment,
303+
readBackVerdict as commentReadBackVerdict,
304+
relayAction,
305+
sentBodyLanded,
306+
substitutionSummary,
307+
} from './post-stamped.mjs';
281308

282309
const SELF_PATH = fileURLToPath(import.meta.url);
283310
const REPO_ROOT = new URL('../../', import.meta.url);
284311
const API = 'https://api.github.com';
285312
const TOKEN = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? '';
286313
const PROXY_REARM_GUARD = 'OS_LABEL_WRITE_PROXY_REARMED';
287314

315+
/**
316+
* The read-back judge every `sendFleetWrite` from this file is HANDED (header: the read-back judge). Built at
317+
* call time, ⛔ never at module scope — the bindings are post-stamped's, unread until its evaluation is done.
318+
*/
319+
const readBackJudge = () => ({ classifyReadBack, sentBodyLanded });
320+
288321
export const EXIT_OK = 0;
289322
export const EXIT_USAGE = 2;
290323
export const EXIT_READ_BACK_MISMATCH = 4;
@@ -707,9 +740,12 @@ export function releaseTextRefusal(text) {
707740

708741
/**
709742
* The release comment as sent: the operator's text, then the resume line and
710-
* the clock reading this tool measured, rendered through post-stamped's stamp
711-
* contract (`{{NOW}}` substituted, its refusals applied). Pure given the
712-
* instants.
743+
* the clock reading this tool measured, judged by post-stamped's `judgeBody` in
744+
* comment mode — the ONE path `--comment-file` and post-stamped's own
745+
* `--comment` take: the stamp contract (`{{NOW}}` substituted, its refusals
746+
* applied), the signature first line, and the comment-mode keyed-line readers.
747+
* Returns `judgeBody`'s answer: `{ ok: true, rendered }` or `{ ok: false,
748+
* rendered, text }`. Pure given the instants.
713749
*/
714750
export function composeReleaseBody({ text, resume, knock, serverNow, age, nowMs } = {}) {
715751
// Both instants are READINGS taken off the board by this act, so they are
@@ -720,7 +756,7 @@ export function composeReleaseBody({ text, resume, knock, serverNow, age, nowMs
720756
`Released by \`label-write.mjs --release\`: re-check ${knock.id} ({{WAS:${seconds(knock.created_at)}}}) unanswered for ` +
721757
`${formatHoursMinutes(age.ageMs)} on the server clock {{WAS:${seconds(serverNow)}}}, at or past \`RECLAIM_AFTER_HOURS = ${RECLAIM_AFTER_HOURS}\`.`;
722758
const raw = `${String(text).replace(/\s+$/, '')}\n\n${resume.line}\n${provenance}`;
723-
return renderBody(raw, nowMs);
759+
return judgeBody(raw, { mode: 'comment' }, nowMs, 'label-write');
724760
}
725761

726762
/**
@@ -1082,7 +1118,7 @@ export async function runLabelWrite(options, deps = {}) {
10821118
return result(EXIT_USAGE, { stoppedAt: 3, labels, assignees, transport: route.transport });
10831119
}
10841120
record(`[${stamp()}] ③ 写 (relay) — ONE dispatch, request ${packed.payload.request_id}: ${actions.map((a) => a.op).join(' · ')}`);
1085-
const sent = await send(packed.payload, { token: TOKEN, log: (line) => record(` ${line}`) });
1121+
const sent = await send(packed.payload, { token: TOKEN, judge: readBackJudge(), log: (line) => record(` ${line}`) });
10861122
httpCalls.push({ op: 'relay', call: `dispatch ${packed.payload.request_id}`, status: sent.status, verdict: sent.state, detail: sent.run?.url ?? sent.detail ?? '' });
10871123
if (sent.ok) {
10881124
relay = sent;
@@ -1276,7 +1312,7 @@ async function foldStroke(c) {
12761312
return done(EXIT_OK, { dryRun: true, payload: packed.payload });
12771313
}
12781314
const sentAt = c.clock().getTime();
1279-
const sent = await c.send(packed.payload, { token: TOKEN, log: (line) => record(` ${line}`) });
1315+
const sent = await c.send(packed.payload, { token: TOKEN, judge: readBackJudge(), log: (line) => record(` ${line}`) });
12801316
c.httpCalls.push({ op: 'relay', call: `dispatch ${packed.payload.request_id}`, status: sent.status, verdict: sent.state, detail: sent.run?.url ?? sent.detail ?? '' });
12811317
if (sent.state === 'no-run' || sent.state === 'timeout') {
12821318
// ⛔ Under EVERY transport request: the stroke's first action is a comment, so a replay is a second comment.
@@ -1513,12 +1549,14 @@ export async function runRelease(options, deps = {}) {
15131549
}
15141550
const why = releaseTextRefusal(text);
15151551
if (why) return refuse(why, { stoppedAt: 2 });
1516-
const rendered = composeReleaseBody({ text, resume, knock: { id: knock.id, created_at: knock.created_at }, serverNow, age, nowMs: clock().getTime() });
1517-
if (!rendered.ok) {
1518-
record(`[${stamp()}] REFUSED — ${rendered.error}`);
1552+
// Judged on post-stamped's path, as `--comment-file` is (header): an unsigned body is exit 2 here, before the stroke.
1553+
const judged = composeReleaseBody({ text, resume, knock: { id: knock.id, created_at: knock.created_at }, serverNow, age, nowMs: clock().getTime() });
1554+
if (!judged.ok) {
1555+
record(judged.text);
15191556
record(nothing());
1520-
return result(EXIT_USAGE, { stoppedAt: 2, refusal: rendered.kind });
1557+
return result(EXIT_USAGE, { stoppedAt: 2, refusal: judged.rendered.ok ? 'comment' : judged.rendered.kind });
15211558
}
1559+
const { rendered } = judged;
15221560
const body = rendered.body;
15231561

15241562
// ── ③ RELAY-ONLY: one dispatch, or nothing ────────────────────────────────
@@ -1551,7 +1589,7 @@ export async function runRelease(options, deps = {}) {
15511589
return result(EXIT_OK, { dryRun: true, labels, assignees, payload: packed.payload, transport: route.transport });
15521590
}
15531591
const sentAt = clock().getTime();
1554-
const sent = await send(packed.payload, { token: TOKEN, log: (line) => record(` ${line}`) });
1592+
const sent = await send(packed.payload, { token: TOKEN, judge: readBackJudge(), log: (line) => record(` ${line}`) });
15551593
httpCalls.push({ op: 'relay', call: `dispatch ${packed.payload.request_id}`, status: sent.status, verdict: sent.state, detail: sent.run?.url ?? sent.detail ?? '' });
15561594
if (sent.state === 'no-run' || sent.state === 'timeout') {
15571595
// ⛔ Under EVERY transport request: the stroke's first action is the Release: comment, so a replay of a
@@ -1908,9 +1946,12 @@ const hoursAfterKnock = (h) => Date.parse(KNOCK_AT) + h * 3_600_000;
19081946
const RELEASE_BRANCH = 'claude/issue-7-silent';
19091947
const RELEASE_TIP = 'abcdef1234567890abcdef1234567890abcdef12';
19101948
const RELEASE_FILE = '/tmp/self-test/release.md';
1911-
const RELEASE_TEXT =
1949+
/** The operator's text WITHOUT its signature line — `judgeBody` refuses it before the stroke. */
1950+
const RELEASE_TEXT_UNSIGNED =
19121951
'Release: session `session_01TRIAGE000000000000000000` · reason: a silent claim — the owned-24h re-check 200 has had no answer · destination `pm:queue`\n\n' +
19131952
'Provenance, three items: the triage duties text (the reclaim clock); verbatim 「敲门后 `RECLAIM_AFTER_HOURS = 12` 小时无答复 ⇒ 一笔中继释放」; said in `triage-duties.md`. Stamped {{NOW}}.';
1953+
/** The text a triage seat sends: its signature line, then the `Release:` line (#27113). */
1954+
const RELEASE_TEXT = `triage#1 · os-justin · session_01TRIAGE000000000000000000\n${RELEASE_TEXT_UNSIGNED}`;
19141955
/** A silent card: claimed, knocked ~24 h later, nothing since. `serverNow` is what the fixture varies. */
19151956
const silentCard = (serverNowHoursAfterKnock, extra = {}) => ({
19161957
number: 7,
@@ -1982,9 +2023,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
19822023
'the retired lane aliases: an --add of domain:engine / services / cli / rest is written as domain:server before the target, step ② says so, the read-back is clean on either transport; --remove and a live domain:* label pass untouched': 8,
19832024
'the CLI: what a typo must never be allowed to mean': 8,
19842025
'the relay transport: ONE dispatch carrying the whole stroke, the same read-back, and an accepted dispatch with no run UNCONFIRMED under auto too — never a direct write': 14,
1985-
'the release: a silent claim reclaimed in ONE relay stroke — Release: comment → pm:queue on → pm:dispatched off → unassign — on the knock\'s SERVER-clock age, RELAY-ONLY, never a direct write': 32,
2026+
'the release: a silent claim reclaimed in ONE relay stroke — Release: comment → pm:queue on → pm:dispatched off → unassign — on the knock\'s SERVER-clock age, RELAY-ONLY, never a direct write': 34,
19862027
[FOLD_BATTERY]: 24,
1987-
[REAL_TRANSPORT_BATTERY]: 4,
2028+
[REAL_TRANSPORT_BATTERY]: 5,
19882029
});
19892030
const SELF_TEST_BATTERY_FLOOR = 15;
19902031
const UNATTRIBUTED_BATTERY = '(unattributed)';
@@ -2321,7 +2362,7 @@ export async function selfTest() {
23212362
// One leading signature line (#27113) stands ABOVE the first-line key, never in its place.
23222363
const SIG = 'domain:skills#2 · os-justin · session_01ABCDEFGHJKMNPQRSTVWXYZ';
23232364
t('a signed knock reads by the key on the line after its signature; a key on a later line, or under a near-miss signature, still does not', [isRecheckComment(`${SIG}\nOwned-24h re-check: x`), isRecheckComment(`${SIG}\n\n## Owned-24h re-check: x`), isRecheckComment(`${SIG}\nTriage\nOwned-24h re-check: x`), isRecheckComment('domain:skills#2 - os-justin - session_01ABCDEFGHJKMNPQRSTVWXYZ\nOwned-24h re-check: x')], [true, true, false, false]);
2324-
t('…and a signed release text is judged by its `Release:` line: accepted signed as unsigned, refused when no `Release:` line follows the signature', [releaseTextRefusal(`${SIG}\n${RELEASE_TEXT}`) === releaseTextRefusal(RELEASE_TEXT), typeof releaseTextRefusal(`${SIG}\nnote\nRelease: x`)], [true, 'string']);
2365+
t('…and a signed release text is judged by its `Release:` line: accepted signed as unsigned, refused when no `Release:` line follows the signature', [releaseTextRefusal(`${SIG}\n${RELEASE_TEXT_UNSIGNED}`) === releaseTextRefusal(RELEASE_TEXT_UNSIGNED), typeof releaseTextRefusal(`${SIG}\nnote\nRelease: x`)], [true, 'string']);
23252366

23262367
// The fixture card the protocol names, younger than the clock.
23272368
const young = await driveRelease(RELEASE_ARGV, silentCard(5));
@@ -2337,8 +2378,22 @@ export async function selfTest() {
23372378
t('…in ONE dispatch carrying comment → labels_add → labels_remove → unassign, every action on the card', [old.sent.length, old.sent[0].actions.map((a) => a.op), old.sent[0].actions.every((a) => a.issue === 7)], [1, ['comment', 'labels_add', 'labels_remove', 'unassign'], true]);
23382379
t('…and this process made ZERO direct writes — reads only', old.direct, []);
23392380
const landed = old.fake.board.comments.at(-1);
2340-
t('…the Release: comment landed with the resume line and the measured clock appended', [landed.body.startsWith('Release: session'), landed.body.includes(`\nResume-from: ${RELEASE_BRANCH}@abcdef1234\n`), landed.body.includes('unanswered for 13h 0m'), landed.body.includes(`RECLAIM_AFTER_HOURS = ${RECLAIM_AFTER_HOURS}`)], [true, true, true, true]);
2381+
t('…the Release: comment landed under its signature line, with the resume line and the measured clock appended', [landed.body.startsWith('triage#1 · os-justin · session_01TRIAGE000000000000000000\nRelease: session'), landed.body.includes(`\nResume-from: ${RELEASE_BRANCH}@abcdef1234\n`), landed.body.includes('unanswered for 13h 0m'), landed.body.includes(`RECLAIM_AFTER_HOURS = ${RECLAIM_AFTER_HOURS}`)], [true, true, true, true]);
23412382
t('…{{NOW}} in the operator text was stamped, and the read-back found the comment by its stored bytes', [landed.body.includes('{{NOW}}'), old.res.comment, old.text.includes('④ MATCHES — released')], [false, landed.id, true]);
2383+
// The comment is judged on post-stamped's path (`judgeBody`, comment mode), as `--comment-file`'s is.
2384+
const unsignedRelease = await driveRelease(RELEASE_ARGV, silentCard(13), { files: { [RELEASE_FILE]: RELEASE_TEXT_UNSIGNED } });
2385+
t('⭐ an UNSIGNED release text is refused by post-stamped\'s own judge BEFORE the stroke: exit 2, no dispatch, zero writes, the sender named', [unsignedRelease.exit, unsignedRelease.res.stoppedAt, unsignedRelease.sent.length, unsignedRelease.direct, unsignedRelease.text.includes('label-write: REFUSED'), unsignedRelease.text.includes('opens with no signature line'), unsignedRelease.text.includes('NOTHING WAS WRITTEN')], [EXIT_USAGE, 2, 0, [], true, true, true]);
2386+
{
2387+
const own = readFileSync(SELF_PATH, 'utf8');
2388+
const composeSource = own.slice(own.indexOf('export function composeReleaseBody('), own.indexOf('export function releaseActions('));
2389+
const releaseSource = own.slice(own.indexOf('export async function runRelease('), own.indexOf('function reportPrerequisite('));
2390+
t('structural: --release judges its composed body with post-stamped\'s judgeBody before it packs the stroke, and label-write defines no reader of its own', [
2391+
/return judgeBody\(raw, \{ mode: 'comment' \}, nowMs, 'label-write'\)/u.test(composeSource),
2392+
releaseSource.indexOf('composeReleaseBody(') > 0 && releaseSource.indexOf('composeReleaseBody(') < releaseSource.indexOf('packRequest('),
2393+
/\brenderBody\(/u.test(own),
2394+
/function\s+(renderBody|signatureRefusal|claimKeyedLineRefusals|recordKeyedLineRefusals|decisionFacetRefusals|vacantLedgerRefusals)\b/u.test(own),
2395+
], [true, true, false, false]);
2396+
}
23422397
const none = await driveRelease([...RELEASE_ARGV.slice(0, -1), 'none'], silentCard(13));
23432398
t('`--resume-from none` releases without a branch or pull read, writing `Resume-from: none`', [none.exit, none.fake.calls.some((c) => c.op === 'branch-read' || c.op === 'pulls-list'), none.fake.board.comments.at(-1).body.includes('\nResume-from: none\n')], [EXIT_OK, false, true]);
23442399

@@ -2498,7 +2553,10 @@ export async function selfTest() {
24982553
releaseWire.cleanup();
24992554
}
25002555
t('⭐ a RELEASE through the real sendFleetWrite SETTLES too: ONE dispatch, exit 0', [rel.res?.relay?.state, rel.exit, releaseWire.sent.length], ['success', EXIT_OK, 1], rel.text.slice(-600));
2501-
t('…and its ④ comment line prints', rel.text.includes('④ comment ✓') || rel.text.includes('comment ✓'), true, rel.text.slice(-600));
2556+
const own = readFileSync(SELF_PATH, 'utf8');
2557+
const sends = own.match(/\bsend\(packed\.payload, \{[^}]*\}/gu) ?? [];
2558+
t('structural: every send from this file hands sendFleetWrite the read-back judge, so it never imports one under this file\'s top-level await', [sends.length, sends.every((call) => call.includes('judge: readBackJudge()'))], [3, true]);
2559+
t('…and its ④ read-back prints after it, the release comment found by its stored bytes', [rel.text.includes('④ MATCHES — released'), rel.res?.comment === releaseBoard.board.comments.at(-1)?.id], [true, true], rel.text.slice(-600));
25022560
}
25032561

25042562
// ── the floor, BEFORE the verdict ────────────────────────────────────────

0 commit comments

Comments
 (0)