Stop false phone-number holds on /ship run ids and name interactive /autoplan runs (#4747)

Posting a PR body that lists earlier /ship runs no longer stops for a
"phone number" that is really a run id, and an interactive /autoplan
approval is imported under its own run id instead of `autoplan`.

Every /ship that rewrote a body holding earlier runs waited for a
confirmation (#4725; about 1 in 10 run ids also reads as a card number
and still asks, fixed in a follow-up), and interactive /autoplan runs
could not be cited by run id (#4402).

Nothing to do after merge.

Co-authored-by: thomsjack <325974127+thomsjack@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Review-Finding: p1/outside-voice#3 reader=outside-voice
Review-Finding: p1/outside-voice#4 reader=outside-voice
Review-Finding: p2/red-team#1 reader=red-team
Review-Finding: p2/outside-voice#1 reader=outside-voice
Review-Finding: p2/outside-voice#2 reader=outside-voice
This commit is contained in:
authored and GitHub committed 2026-11-23 19:03:59 +00:00
1 parent b5eb401e45
commit 0d6cc1be56
10 files changed
+254 -18

No files matched your search

+23 -8
View File
@@ -186,10 +186,14 @@ function validDate(d: string): boolean {
export interface NewRow { ask: string; words: string; by: string; scope: string; pending?: string; outcome?: string; date?: string; source?: string }
/** An autoplan run id as gstack-autoplan mints it: the run directory's name, a hyphen, six random letters (since GST-3015), a hyphen, then a 14-digit time stamp. */
const MINTED_RUN_ID = /^[A-Za-z0-9._-]{1,64}-\d{14}$/;
/** The part of a minted run id the exemption covers: the 14-digit stamp and, when the name ends in a thread code, its digits. */
const RUN_ID_STAMP = /(?:(?<!\d)\d{1,6}-)?\d{14}$/;
/**
* An autoplan run id as gstack-autoplan mints it: the run directory's name, a hyphen, six random letters (since GST-3015), a hyphen, then a
* 14-digit time stamp; or as interactive /autoplan minted it before #4402: the branch name, a hyphen, then a YYYYMMDD-HHMMSS stamp that is
* a real calendar time.
*/
const MINTED_RUN_ID = /^[A-Za-z0-9._-]{1,64}-(?:\d{14}|\d{4}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])-(?:[01]\d|2[0-3])[0-5]\d[0-5]\d)$/;
/** The part of a minted run id the exemption covers: the stamp and, when the name ends in a thread code or issue number, its digits. */
const RUN_ID_STAMP = /(?:(?<!\d)\d{1,6}-)?(?:\d{14}|\d{8}-\d{6})$/;
/**
* A fix-check round grant's scope as gstack-approvals round-grant writes it (lib/review-round-grant.ts): its stop= token is the
@@ -389,11 +393,21 @@ export function approvalsGrantStopSpans(text: string): Array<{ line: number; fro
return spans;
}
interface DecisionLike { id?: string; title?: string; status?: string; chosen?: string | null; recommended?: string | null; gate_rev?: number; answered_at?: string; answered_by?: string; reply?: string; owner_reply?: string; answer_words?: string; words_by?: string; carried_from?: string; label?: string; chosen_text?: string;
interface DecisionLike { id?: string; run?: string; title?: string; status?: string; chosen?: string | null; recommended?: string | null; gate_rev?: number; answered_at?: string; answered_by?: string; reply?: string; owner_reply?: string; answer_words?: string; words_by?: string; carried_from?: string; label?: string; chosen_text?: string;
carried_gate_from?: string; carried_gate_rev?: number; carried_answered_by?: string; carried_under?: string; carry_check?: string }
const stripRef = (t: string) => t.replace(/\s*\[[^\]]*\]\s*$/, '').trim();
/**
* The run id an autoplan run directory answers to: run.json's, else the newest run its gate rows carry (an interactive
* /autoplan writes no run.json and appends every run to the same directory, #4402), else the directory name.
*/
export function autoplanRunId(runDir: string, run: Record<string, any>, rows: readonly { run?: unknown }[]): string {
if (run.run ?? run.id) return String(run.run ?? run.id);
const newest = [...rows].reverse().find(r => typeof r.run === 'string' && r.run.length > 0)?.run;
return typeof newest === 'string' ? newest : path.basename(runDir);
}
/**
* Rows for every answered gate in an autoplan run: one row per answer event (gate_rev, time, answerer), covering
* the items it settled. Item answers carried from an earlier revision were recorded when first given and are skipped;
@@ -417,8 +431,9 @@ export function importAutoplan(runDir: string, branch: string, by?: string): App
const plan = reviewedPlan(runDir, run);
const planTitle = firstTitle(plan.text) ?? 'the plan';
const planSha = plan.sha;
const runId = String(run.run ?? run.id ?? path.basename(runDir));
const answered = rows.filter(r => r.status && r.status !== 'pending' && r.answered_at && !r.carried_from);
const runId = autoplanRunId(runDir, run, rows);
const own = (run.run ?? run.id) || !rows.some(r => r.run === runId) ? rows : rows.filter(r => r.run === runId);
const answered = own.filter(r => r.status && r.status !== 'pending' && r.answered_at && !r.carried_from);
if (!answered.length) return { code: 'APPROVAL_IMPORT_UNANSWERED', message: `no answered gate in ${runDir}` };
const groups = new Map<string, DecisionLike[]>();
for (const r of answered) {
@@ -433,7 +448,7 @@ export function importAutoplan(runDir: string, branch: string, by?: string): App
const outcome: Outcome = !p1 ? 'pending' : p1.chosen === 'a' || p1.chosen === 'b' ? 'approved' : p1.chosen === 'e' ? 'rejected' : 'pending';
const items = group.filter(r => r !== p1);
const changed = items.filter(r => r.chosen && r.recommended && r.chosen !== r.recommended);
const stillPending = rows.filter(r => r.gate_rev === rev && r.status === 'pending');
const stillPending = own.filter(r => r.gate_rev === rev && r.status === 'pending');
const answerer = first.answered_by ?? 'unknown';
const carried = p1?.carried_gate_from ? p1 : undefined;
const relayed = carried?.carried_answered_by && carried.carried_answered_by !== 'human' ? `, relayed by ${carried.carried_answered_by}` : '';
+17 -3
View File
@@ -577,7 +577,9 @@ const lineIdSpans = (text: string, line: number): Span[] => RECEIPT_LINE_IDS.fla
* span of each value below. In every closed ```gstack-ship-receipt``` block whose JSON passes the receipt schema and is byte-identical to
* renderReceiptBlock's rendering of it: each ci_carried[].run, flaky_exception[].runs[] and issues.flakes[].run value that is a run id (11 to 20
* digits, with an optional /attempt), the run value when it is a gstack-skill-start session id, and the RECEIPT_LINE_IDS values inside the
* pregate and requires_remote[] values. On every line outside a fenced code block that opens with a receipt-line prefix (RECEIPT_LINE), its RECEIPT_LINE_IDS values. Only
* pregate and requires_remote[] values. In every closed ```gstack-receipt-runs``` block that opens outside any other fence (gstack#4725), the top-level run value of each line that is a
* JSON object byte-identical to its JSON.stringify rendering, with a 40-hex head and a run that is a gstack-skill-start session id. On every line
* outside a fenced code block that opens with a receipt-line prefix (RECEIPT_LINE), its RECEIPT_LINE_IDS values. Only
* those writers' own output qualifies, so a hand-written, schema-invalid, malformed or unclosed block exempts nothing, and the same number in
* prose, in any other code block (a receipt-prefixed line inside one included), on a line without a receipt prefix or under any other key still reports.
*/
@@ -585,10 +587,11 @@ function receiptIdSpans(text: string): Span[] {
const lines = text.split("\n");
const rows = (v: unknown): number => v !== null && typeof v === "object" && Object.keys(v).length ? 2 + Object.values(v).reduce((n: number, c) => n + rows(c), 0) : 1;
let fence = "";
const blocks: Array<{ open: number; close: number }> = [];
const spans: Span[] = lines.flatMap((l, i) => {
const f = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(l);
if (f && !fence) { fence = f[1]!; return []; }
if (f && f[1]![0] === fence[0] && f[1]!.length >= fence.length && !f[2]!.trim()) { fence = ""; return []; }
if (f && !fence) { fence = f[1]!; blocks.push({ open: i, close: -1 }); return []; }
if (f && f[1]![0] === fence[0] && f[1]!.length >= fence.length && !f[2]!.trim()) { fence = ""; blocks.at(-1)!.close = i; return []; }
return !fence && RECEIPT_LINE.test(l) ? lineIdSpans(l, i + 1) : [];
});
for (let open = 0; open < lines.length; open++) {
@@ -626,6 +629,17 @@ function receiptIdSpans(text: string): Span[] {
receipt.issues?.flakes?.forEach((_, i) => span(["issues", "flakes", i, "run"]));
open = close;
}
for (const { open, close } of blocks) {
if (close < 0 || lines[open] !== "```" + RUNS_FENCE) continue;
for (let i = open + 1; i < close; i++) {
let entry: Record<string, unknown>;
try { entry = JSON.parse(lines[i]!); if (entry === null || typeof entry !== "object" || Array.isArray(entry) || JSON.stringify(entry) !== lines[i]) continue; } catch { continue; }
if (typeof entry.head !== "string" || !/^[0-9a-f]{40}$/.test(entry.head) || typeof entry.run !== "string" || !SESSION_ID.test(entry.run)) continue;
const before = Object.keys(entry).slice(0, Object.keys(entry).indexOf("run"));
const from = JSON.stringify(Object.fromEntries(before.map(k => [k, entry[k]]))).length + (before.length ? 1 : 0) + '"run":'.length;
spans.push({ line: i + 1, from, to: from + JSON.stringify(entry.run).length - 1 });
}
}
return spans;
}
+8 -1
View File
@@ -147,7 +147,14 @@ const rowSha = (r: ApprovalRow) => createHash('sha256').update(JSON.stringify(r)
function runIdFor(token: string, cwd: string): string {
const dir = path.resolve(cwd, token.replace(/^~(?=\/)/, process.env.HOME ?? '~'));
if (!token.includes('/')) return token;
try { return String(JSON.parse(fs.readFileSync(path.join(dir, 'run.json'), 'utf8')).run ?? path.basename(dir)); } catch { return path.basename(dir); }
let run: Record<string, any> = {};
try { run = JSON.parse(fs.readFileSync(path.join(dir, 'run.json'), 'utf8')); } catch {}
if (run.run ?? run.id) return String(run.run ?? run.id);
const file = path.join(dir, 'decisions.jsonl');
if (!fs.existsSync(file)) return path.basename(dir);
let runs: Set<string>;
try { runs = new Set(fs.readFileSync(file, 'utf8').split('\n').filter(l => l.trim()).map(l => JSON.parse(l)?.run).filter((r): r is string => typeof r === 'string' && !!r)); } catch { return ''; }
return runs.size === 1 ? [...runs][0]! : runs.size ? '' : path.basename(dir);
}
/** Resolve a Plan line against the approval store; `changedOnly` lists the PR's changed paths for the changelog-only exemption. */