Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Name a rejected Linear key in OK release alerts (PRD-9890) (#7399)
Andrew Mikofalvy6613a8dd62dc
diff --git a/.github/scripts/linear-release-shape.test.mjs b/.github/scripts/linear-release-shape.test.mjsindex 1845d37b8..9389aa58e 100644--- a/.github/scripts/linear-release-shape.test.mjs+++ b/.github/scripts/linear-release-shape.test.mjs@@ -4,6 +4,7 @@ import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';import { describe, expect, test } from 'vitest';import { parse } from 'yaml';+import { KEY_REJECTED_OUTPUT } from './stamp-by-containment.mjs';const WORKFLOWS = join(dirname(fileURLToPath(import.meta.url)), '..', 'workflows');const workflow = readFileSync(join(WORKFLOWS, 'linear-release.yml'), 'utf8');@@ -94,6 +95,28 @@ describe('linear release stamping workflow', () => {expect(alert).toContain('payload=$(jq -nc --arg text "$TEXT" \'{text: $text}\')');});+ test('a rejected Linear key pages a rotation instead of a re-run', () => {+ const containment = parse(workflow).jobs.stamp.steps.find(+ (step) => step.name === 'Correct the stable stamp by containment',+ );+ expect(containment.id).toBe('containment');++ const alert = alertBlock(workflow);+ expect(alert).toContain(+ `LINEAR_KEY_REJECTED: \${{ steps.containment.outputs.${KEY_REJECTED_OUTPUT} }}`,+ );+ const rejected = alert.match(+ /if \[\[ "\$\{LINEAR_KEY_REJECTED:-\}" == "true" \]\]; then\n\s+TEXT="([^\n]*)"\n\s+fi/,+ );+ if (!rejected) throw new Error('no rejected-key TEXT= branch in the alert step');+ const text = rejected[1];+ expect(text).toContain('gh secret set LINEAR_API_KEY -R ${GITHUB_REPOSITORY}');+ expect(text).toContain('release_tag=${TAG}');+ expect(text).toContain('${RUN_URL}');+ expect(text).toContain('Read and Write permissions');+ expect(text).not.toContain('Re-running is safe');+ });+test('the alert covers every working step', () => {assertAlertIsFinalStep(workflow);diff --git a/.github/scripts/stamp-by-containment.mjs b/.github/scripts/stamp-by-containment.mjsindex 70916a7cb..675ffe59b 100644--- a/.github/scripts/stamp-by-containment.mjs+++ b/.github/scripts/stamp-by-containment.mjs@@ -1,6 +1,7 @@#!/usr/bin/env node/* biome-ignore-all lint/suspicious/noUndeclaredEnvVars: GitHub Actions invokes this entrypoint outside Turbo. */import { execFileSync } from 'node:child_process';+import { appendFileSync } from 'node:fs';import { pathToFileURL } from 'node:url';import { realPublishedReleaseTags } from './published-release-tags.mjs';import { realFindMirroredCommits, resolveShippedVersion } from './resolve-shipped-version.mjs';@@ -9,6 +10,7 @@ import { createTagContainment } from './tag-containment.mjs';const BETA_VERSION_RE = /-beta\.\d+$/;const PRIVATE_PR_RE = /github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/;const PRIVATE_REPO = 'inkeep/agents-private';+export const KEY_REJECTED_OUTPUT = 'linear_key_rejected';function log(...args) {process.stderr.write(`${args.join(' ')}\n`);@@ -66,17 +68,37 @@ export function summarize(plans) {return counts;}-async function linear(query, variables) {- const res = await fetch('https://api.linear.app/graphql', {+export class LinearKeyRejectedError extends Error {+ constructor(body) {+ super(+ `Linear rejected LINEAR_API_KEY with HTTP 401, so the key has expired or been revoked; rotate the LINEAR_API_KEY secret: ${body.slice(0, 300)}`,+ );+ this.name = 'LinearKeyRejectedError';+ }+}++export function recordFailureOutputs(err, outputPath) {+ if (err instanceof LinearKeyRejectedError && outputPath) {+ appendFileSync(outputPath, `${KEY_REJECTED_OUTPUT}=true\n`);+ }+}++export async function linear(+ query,+ variables,+ { apiKey = process.env.LINEAR_API_KEY, fetchImpl = fetch } = {},+) {+ const res = await fetchImpl('https://api.linear.app/graphql', {method: 'POST',headers: {- authorization: process.env.LINEAR_API_KEY,+ authorization: apiKey,'content-type': 'application/json',},body: JSON.stringify({ query, variables }),signal: AbortSignal.timeout(20_000),});const text = await res.text();+ if (res.status === 401) throw new LinearKeyRejectedError(text);if (!res.ok) throw new Error(`linear HTTP ${res.status}: ${text.slice(0, 300)}`);const body = JSON.parse(text);if (body.errors) throw new Error(`linear graphql: ${JSON.stringify(body.errors).slice(0, 400)}`);@@ -265,6 +287,7 @@ async function main() {if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {main().catch((err) => {console.error(`::error::stamp-by-containment: ${err.message}`);+ recordFailureOutputs(err, process.env.GITHUB_OUTPUT);process.exit(1);});}diff --git a/.github/scripts/stamp-by-containment.test.mjs b/.github/scripts/stamp-by-containment.test.mjsindex d09b91b09..bd447ed4a 100644--- a/.github/scripts/stamp-by-containment.test.mjs+++ b/.github/scripts/stamp-by-containment.test.mjs@@ -1,7 +1,14 @@-import { describe, expect, test } from 'vitest';+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { afterEach, describe, expect, test } from 'vitest';import {isBetaRelease,+ KEY_REJECTED_OUTPUT,+ LinearKeyRejectedError,+ linear,planTicketReconciliation,+ recordFailureOutputs,summarize,} from './stamp-by-containment.mjs';@@ -157,3 +164,62 @@ describe('summarize', () => {expect(summarize(plans)).toEqual({ noop: 1, attach: 2, reattach: 1, skip: 1 });});});++describe('linear', () => {+ const reply = (status, body) => async () => ({+ ok: status < 400,+ status,+ text: async () => body,+ });++ test('a 401 names the rejected key so the alert can ask for rotation', async () => {+ const call = linear(+ 'query {}',+ {},+ {+ apiKey: 'k',+ fetchImpl: reply(401, '{"errors":[{"code":"AUTHENTICATION_ERROR"}]}'),+ },+ );+ await expect(call).rejects.toBeInstanceOf(LinearKeyRejectedError);+ await expect(call).rejects.toThrow(/rotate the LINEAR_API_KEY secret/);+ await expect(call).rejects.toThrow(/AUTHENTICATION_ERROR/);+ });++ test('other HTTP failures keep the generic error', async () => {+ const call = linear('query {}', {}, { apiKey: 'k', fetchImpl: reply(503, 'upstream') });+ await expect(call).rejects.toThrow('linear HTTP 503: upstream');+ await expect(call).rejects.not.toBeInstanceOf(LinearKeyRejectedError);+ });+});++describe('recordFailureOutputs', () => {+ const dirs = [];+ afterEach(() => {+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });+ });++ const outputFile = () => {+ const dir = mkdtempSync(join(tmpdir(), 'stamp-output-'));+ dirs.push(dir);+ const path = join(dir, 'output');+ writeFileSync(path, '');+ return path;+ };++ test('a rejected key leaves the output the alert step reads', () => {+ const path = outputFile();+ recordFailureOutputs(new LinearKeyRejectedError('{}'), path);+ expect(readFileSync(path, 'utf8')).toBe(`${KEY_REJECTED_OUTPUT}=true\n`);+ });++ test('any other failure leaves the output empty', () => {+ const path = outputFile();+ recordFailureOutputs(new Error('linear HTTP 503: upstream'), path);+ expect(readFileSync(path, 'utf8')).toBe('');+ });++ test('without an output file nothing is written and nothing throws', () => {+ expect(() => recordFailureOutputs(new LinearKeyRejectedError('{}'), undefined)).not.toThrow();+ });+});diff --git a/.github/scripts/write-back.mjs b/.github/scripts/write-back.mjsindex 55e4057dc..260cd5b7d 100644--- a/.github/scripts/write-back.mjs+++ b/.github/scripts/write-back.mjs@@ -789,6 +789,12 @@ export async function linearGraphql({) {throw new LinearRateLimitError(res.headers);}+ if (res.status === 401) {+ throw new LinearRequestError(+ `Linear GraphQL returned HTTP 401, so LINEAR_API_KEY has expired or been revoked; rotate the LINEAR_API_KEY secret: ${body.slice(0, 400)}`,+ { retryable: false },+ );+ }throw new LinearRequestError(`Linear GraphQL returned HTTP ${res.status}: ${body.slice(0, 400)}`,{diff --git a/.github/scripts/write-back.test.mjs b/.github/scripts/write-back.test.mjsindex a25851588..4b8fe9044 100644--- a/.github/scripts/write-back.test.mjs+++ b/.github/scripts/write-back.test.mjs@@ -1115,6 +1115,7 @@ describe('a Linear call that failed for reasons unrelated to the request', () =>const h = callLinear([fail(401, '{"errors":[{"type":"AUTHENTICATION_ERROR"}]}')]);await expect(h.call).rejects.toThrow(/HTTP 401/);await expect(h.call).rejects.toThrow(/AUTHENTICATION_ERROR/);+ await expect(h.call).rejects.toThrow(/rotate the LINEAR_API_KEY secret/);expect(h.attemptCount()).toBe(1);expect(h.slept).toEqual([]);});diff --git a/.github/workflows/linear-release.yml b/.github/workflows/linear-release.ymlindex cf8062fc3..732c7f544 100644--- a/.github/workflows/linear-release.yml+++ b/.github/workflows/linear-release.yml@@ -209,6 +209,7 @@ jobs:- name: Correct the stable stamp by containmentif: steps.derive.outputs.channel == 'stable'+ id: containmentenv:GH_TOKEN: ${{ github.token }}LINEAR_API_KEY: ${{ secrets.LINEAR_API_KEY }}@@ -241,6 +242,7 @@ jobs:SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}CHANNEL: ${{ steps.derive.outputs.channel }}JOB_STATUS: ${{ job.status }}+ LINEAR_KEY_REJECTED: ${{ steps.containment.outputs.linear_key_rejected }}run: |set -uo pipefailRUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"@@ -254,6 +256,9 @@ jobs:OUTCOME="failed"fiTEXT="Linear release stamping ${OUTCOME} for ${TAG}${CHANNEL:+ (${CHANNEL})}. The release itself is unaffected; Linear is now out of sync with what shipped. Re-running is safe for transient failures. After a stamping-code fix reaches main, dispatch linear-release.yml fresh on main with release_tag=${TAG}; re-running the old run keeps its old code. Stable dispatches re-verify every stable release's stamps, not just this one. ${RUN_URL}"+ if [[ "${LINEAR_KEY_REJECTED:-}" == "true" ]]; then+ TEXT="Linear release stamping failed for ${TAG}${CHANNEL:+ (${CHANNEL})}: Linear rejected the LINEAR_API_KEY secret on ${GITHUB_REPOSITORY} with HTTP 401, so the key has expired or been revoked. Re-running will not help and no code fix is needed. Create a new key in Linear (Settings > Security & access > Personal API keys) on a shared account, with Read and Write permissions (Admin is not needed) on all teams, store it with gh secret set LINEAR_API_KEY -R ${GITHUB_REPOSITORY}, then dispatch linear-release.yml fresh on main with release_tag=${TAG}. Reporter write-back uses the same key, so it is failing too. ${RUN_URL}"+ fi{echo "## Linear stamping ${OUTCOME}"echo "Tag: \`${TAG}\`"