Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): make the prebuild selector's error paths name the real cause (#3768)
Andrew Mikofalvy0306ec6c40c3
diff --git a/.github/scripts/point-release-plan.mjs b/.github/scripts/point-release-plan.mjsindex 7127a5487..ca90f6d82 100644--- a/.github/scripts/point-release-plan.mjs+++ b/.github/scripts/point-release-plan.mjs@@ -1182,10 +1182,25 @@ function realIo() {// not an empty answer, and returning '' on an auth or rate-limit// failure would refuse the release naming native-config drift.const candidates = listPrebuildRuns();+ const treeAt = makeTreeAt();+ // An unreadable release ref is INFRA, not drift — the same line this+ // lane already draws for an unreadable `gh` answer. Returning it as a+ // reason would wrap it in guardNativeConfigProvenance's drift prose+ // ("promote through the normal stable path so the release contains the+ // native-config change its binaries were built from"), a remedy that+ // does not apply, under a code whose documented causes it is not. The+ // synthetic commit is local HEAD, so this means the working tree itself+ // did not read.+ if (treeAt(syntheticSha) === null) {+ throw new Error(+ `could not read packages/native-config at the synthetic commit (${syntheticSha}); ` ++ 'the working tree did not read, which is an infrastructure failure, not native-config drift',+ );+ }const selection = selectPrebuildRun({candidates,isAncestor: makeIsAncestor(),- treeAt: makeTreeAt(),+ treeAt,releaseRef: syntheticSha,});return selection@@ -1197,7 +1212,9 @@ function realIo() {if (draft) args.push('--draft');const res = spawnSync('gh', args, { encoding: 'utf8' });if (res.status !== 0) {- throw new Error(`gh release create ${tag} failed: ${String(res.stderr || '').trim()}`);+ throw new Error(+ `gh release create ${tag} failed: ${res.error?.message ?? String(res.stderr || '').trim()}`,+ );}},dispatch: ({ repo, eventType, clientPayload }) => {@@ -1212,7 +1229,9 @@ function realIo() {: process.env,});if (res.status !== 0) {- throw new Error(`gh dispatch ${eventType} to ${repo} failed: ${String(res.stderr || '').trim()}`);+ throw new Error(+ `gh dispatch ${eventType} to ${repo} failed: ${res.error?.message ?? String(res.stderr || '').trim()}`,+ );}},},diff --git a/.github/scripts/select-native-config-prebuild.mjs b/.github/scripts/select-native-config-prebuild.mjsindex eb50579cd..a21ad737b 100644--- a/.github/scripts/select-native-config-prebuild.mjs+++ b/.github/scripts/select-native-config-prebuild.mjs@@ -102,6 +102,27 @@ export function describeNoSelection(candidates = []) {);}+/**+ * Why no run was selected, distinguishing the two ways that happens.+ *+ * An unreadable release ref is NOT "no prebuild matches": it means we could not+ * read `packages/native-config` at the commit being released, so nothing could+ * have matched. Falling through to describeNoSelection there names the newest+ * prebuild run as the thing that does not fit and sends the operator off to+ * re-run a prebuild — the same confident-but-wrong diagnosis this module exists+ * to stop, one layer down.+ */+export function describeSelectionFailure({ candidates = [], treeAt, releaseRef = 'HEAD' }) {+ if (treeAt(releaseRef) === null) {+ return (+ `could not read ${NATIVE_CONFIG_PATH} at the release commit (${releaseRef}); ` ++ `the release ref is what did not resolve, not the prebuild runs — ` ++ `check that the ref exists and that the checkout reaches it (fetch-depth)`+ );+ }+ return describeNoSelection(candidates);+}+/*** Green prebuild runs on `main`, newest first.*@@ -135,7 +156,7 @@ export function listPrebuildRuns({ limit = DEFAULT_CANDIDATE_LIMIT, run = spawnS);if (res.status !== 0) {throw new Error(- `gh run list for ${PREBUILD_WORKFLOW} failed: ${String(res.stderr || '').trim()}`,+ `gh run list for ${PREBUILD_WORKFLOW} failed: ${res.error?.message ?? String(res.stderr || '').trim()}`,);}const parsed = JSON.parse(String(res.stdout || '[]').trim() || '[]');@@ -176,7 +197,7 @@ export function main(argv = process.argv.slice(2), io = {}) {const candidates = list();const selection = selectPrebuildRun({ candidates, isAncestor, treeAt, releaseRef });if (!selection) {- return { ok: false, reason: describeNoSelection(candidates) };+ return { ok: false, reason: describeSelectionFailure({ candidates, treeAt, releaseRef }) };}return { ok: true, line: `${selection.runId}\t${selection.headSha}` };}diff --git a/.github/scripts/select-native-config-prebuild.test.mjs b/.github/scripts/select-native-config-prebuild.test.mjsindex 8af8da926..aedc58132 100644--- a/.github/scripts/select-native-config-prebuild.test.mjs+++ b/.github/scripts/select-native-config-prebuild.test.mjs@@ -5,6 +5,7 @@ import { describe, expect, test } from 'vitest';import {DEFAULT_CANDIDATE_LIMIT,describeNoSelection,+ describeSelectionFailure,listPrebuildRuns,main,makeIsAncestor,@@ -156,6 +157,30 @@ describe('describeNoSelection', () => {});});+describe('describeSelectionFailure', () => {+ test('names the release ref when its native-config tree is unreadable', () => {+ const reason = describeSelectionFailure({+ candidates: CANDIDATES_NEWEST_FIRST,+ treeAt: () => null,+ releaseRef: 'v9.9.9',+ });+ expect(reason).toContain('v9.9.9');+ expect(reason).toContain('release ref');+ // The whole point: it must NOT blame the prebuild runs, which is the+ // misdirection this module exists to stop.+ expect(reason).not.toContain('32317026296');+ });++ test('falls back to the prebuild account when the release ref reads fine', () => {+ const reason = describeSelectionFailure({+ candidates: CANDIDATES_NEWEST_FIRST,+ treeAt: () => 'eb09e361',+ releaseRef: 'HEAD',+ });+ expect(reason).toContain('32317026296');+ });+});+describe('git boundary', () => {test('isAncestor reads a non-zero exit as "not an ancestor"', () => {const isAncestor = makeIsAncestor((_cmd, args) => ({@@ -199,6 +224,16 @@ describe('listPrebuildRuns', () => {expect(DEFAULT_CANDIDATE_LIMIT).toBeGreaterThan(1);});+ test('reports a spawn failure, which leaves stderr empty', () => {+ // `gh` missing from PATH sets status null and stderr '', so keying only on+ // stderr threw "…failed: " with nothing after the colon.+ expect(() =>+ listPrebuildRuns({+ run: () => ({ status: null, stdout: '', stderr: '', error: new Error('spawn gh ENOENT') }),+ }),+ ).toThrow(/spawn gh ENOENT/);+ });+test('throws on an unreadable answer rather than reading it as "no runs"', () => {expect(() =>listPrebuildRuns({ run: () => ({ status: 1, stdout: '', stderr: 'rate limited' }) }),@@ -225,6 +260,16 @@ describe('main', () => {expect(result.reason).toContain('32317026296');});+ test('blames the release ref, not the prebuild runs, when its tree is unreadable', () => {+ const result = main(['--release-ref', 'unknown-commit'], {+ list: () => CANDIDATES_NEWEST_FIRST,+ ...RELEASE_REGRESSION,+ });+ expect(result.ok).toBe(false);+ expect(result.reason).toContain('unknown-commit');+ expect(result.reason).not.toContain('32317026296');+ });+test('defaults to HEAD when no ref is given', () => {const graph = chainFixture([{ sha: 'prebuild', tree: 'T1' },@@ -261,9 +306,32 @@ describe('workflow wiring', () => {});test(`${name} still splits beta degradation from stable refusal`, () => {+ // Pin the BRANCH, not the token. `IS_STABLE` on its own also appears in+ // the step's `env:` block, which sits inside this slice, so the original+ // `toContain('IS_STABLE')` stayed green with the ENTIRE stable-refusal+ // branch deleted — caught by mutation testing in review. The `::error::`+ // wording differs between the two workflows (`stable release` vs+ // `stable @latest release`), so match that loosely and pin the structure+ // around it.const step = stagingStep(workflow(name));expect(step).toContain('degrade_or_fail');- expect(step).toContain('IS_STABLE');+ expect(step).toMatch(+ /if \[ "\$IS_STABLE" = "true" \]; then\n\s+echo "::error::[^\n]+\n\s+exit 1/,+ );+ expect(step).toMatch(/echo "::warning::[^\n]+\n\s+exit 0/);+ });++ test(`${name} asserts the selector's output shape, not just non-emptiness`, () => {+ // Pin the guard as ONE contiguous block, the rejecting branch included.+ // Asserting the shape pattern and the `if` separately leaves the+ // `degrade_or_fail` deletable with this test still green — the identical+ // hole the IS_STABLE ratchet had. Both were caught by mutation testing,+ // which is the only thing that proves a ratchet of this shape works.+ const step = stagingStep(workflow(name));+ expect(step).toContain("selection_shape='^[0-9]+'$'\\t''[0-9a-f]{7,40}$'");+ expect(step).toMatch(+ /if \[\[ ! \$selection =~ \$selection_shape \]\]; then\n\s+flattened=[^\n]*\n\s+degrade_or_fail[^\n]*\n\s+fi/,+ );});}});diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.ymlindex db2fca733..31c483293 100644--- a/.github/workflows/desktop-release.yml+++ b/.github/workflows/desktop-release.yml@@ -382,11 +382,20 @@ jobs:reason=$(tr '\n' ' ' < "$nc_err" | sed 's/ *$//')degrade_or_fail "${reason:-could not select a native-config prebuild run}" "0/8"fi+ # Assert the WHOLE shape, on ONE line. Testing for a tab anywhere is+ # not enough: a stray line ahead of the real answer still contains a+ # tab, so it passes and leaves that noise in run_id, which only+ # surfaces later as a confusing `gh run download` failure. Anchoring+ # the whole value is what actually rejects it. The message is flattened+ # because ::error:: annotations are single-line — an interpolated+ # multi-line value would truncate the page.+ selection_shape='^[0-9]+'$'\t''[0-9a-f]{7,40}$'+ if [[ ! $selection =~ $selection_shape ]]; then+ flattened=$(printf '%s' "$selection" | tr '\n' ' ')+ degrade_or_fail "native-config prebuild selector returned an unusable answer: $flattened" "0/8"+ firun_id="${selection%%$'\t'*}"head_sha="${selection##*$'\t'}"- if [ -z "$run_id" ] || [ -z "$head_sha" ]; then- degrade_or_fail "native-config prebuild selector returned an unusable answer" "0/8"- fiif ! gh run download "$run_id" --name native-config-bindings-all --dir /tmp/nc-bindings; thendegrade_or_fail "could not download native-config-bindings-all from run $run_id" "0/8"diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 9f268b305..0822e0e15 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -264,11 +264,20 @@ jobs:reason=$(tr '\n' ' ' < "$nc_err" | sed 's/ *$//')degrade_or_fail "${reason:-could not select a native-config prebuild run}" "0/8"fi+ # Assert the WHOLE shape, on ONE line. Testing for a tab anywhere is+ # not enough: a stray line ahead of the real answer still contains a+ # tab, so it passes and leaves that noise in run_id, which only+ # surfaces later as a confusing `gh run download` failure. Anchoring+ # the whole value is what actually rejects it. The message is flattened+ # because ::error:: annotations are single-line — an interpolated+ # multi-line value would truncate the page.+ selection_shape='^[0-9]+'$'\t''[0-9a-f]{7,40}$'+ if [[ ! $selection =~ $selection_shape ]]; then+ flattened=$(printf '%s' "$selection" | tr '\n' ' ')+ degrade_or_fail "native-config prebuild selector returned an unusable answer: $flattened" "0/8"+ firun_id="${selection%%$'\t'*}"head_sha="${selection##*$'\t'}"- if [ -z "$run_id" ] || [ -z "$head_sha" ]; then- degrade_or_fail "native-config prebuild selector returned an unusable answer" "0/8"- fiif ! gh run download "$run_id" --name native-config-bindings-all --dir /tmp/nc-bindings; thendegrade_or_fail "could not download native-config-bindings-all from run $run_id" "0/8"