Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/actions/report-lane-outcome/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ inputs:
fallback-reason:
description: >-
Why this run used a fallback credential: `credit-stop` (the key job
credit-stopped) or `no-key` (the key was empty). Printed as
credit-stopped), `auth` (the API refused the key job's key with status
401, disabled or deleted; 402, billing; or 403, permission) or `no-key`
(the key was empty). Printed as
`fallback=<reason>` right after `credential=`. Empty prints nothing;
any other value fails the step before it reports.
required: false
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/report-lane-outcome/classify.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ const MODEL_PATTERN = /^[\w.:@[\]-]{1,100}$/u;
const COUNT_PATTERN = /^\d{1,6}$/u;
const WINDOW_PATTERN = /^[a-z0-9_]{1,40}$/u;
// Why a subscription job ran in the two-job pattern: the key job's credit
// stop, or no key at all (ci-workflows#806).
const FALLBACK_REASONS = ["credit-stop", "no-key"];
// stop, its key refused with API status 401, 402 or 403, or no key at all.
const FALLBACK_REASONS = ["credit-stop", "auth", "no-key"];

// SDK `resetsAt` is epoch time; a value past 1e12 can only be milliseconds.
function isoFromEpoch(value) {
Expand Down
6 changes: 5 additions & 1 deletion .github/actions/report-lane-outcome/classify.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,13 @@ test("record tokens: a fallback reason prints right after the credential, only f
recordTokens(run, { credential, fallbackReason: "no-key" }),
"credential=AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN fallback=no-key turns=4",
);
assert.equal(
recordTokens(run, { credential, fallbackReason: "auth" }),
"credential=AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN fallback=auth turns=4",
);
for (const forged of [
"",
"auth",
"Auth",
"Credit-Stop",
" no-key",
"credit-stop\n::error::x",
Expand Down
23 changes: 21 additions & 2 deletions .github/actions/report-lane-outcome/outcome-step.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,30 @@ test("a fallback reason rides beside the credential on the notice and the class
assert.doesNotMatch(none.notices[0], /fallback=/u);
});

test("a fallback reason outside credit-stop and no-key fails the step and reports nothing", async () => {
test("an auth fallback reason, a rejected key, is recorded beside the credential", async () => {
const succeeded = writeExecutionFile([
{ type: "result", subtype: "success", is_error: false, num_turns: 2 },
]);
const run = await runOutcome({
outcome: "success",
executionFile: succeeded,
credential: "AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN",
fallbackReason: "auth",
});
assert.deepEqual(run.failed, []);
assert.equal(run.notices.length, 1);
assert.match(
run.notices[0],
/ credential=AUTOMATIONS_CLAUDE_CODE_OAUTH_TOKEN fallback=auth turns=2\b/u,
);
});

test("a fallback reason outside credit-stop, auth and no-key fails the step and reports nothing", async () => {
const file = writeExecutionFile([
{ type: "result", subtype: "success", is_error: false, num_turns: 5 },
]);
for (const outcome of ["success", "failure"]) {
for (const fallbackReason of ["auth", "Credit-Stop", " credit-stop"]) {
for (const fallbackReason of ["Auth", "Credit-Stop", " credit-stop"]) {
const run = await runOutcome({
outcome,
executionFile: file,
Expand All @@ -483,6 +501,7 @@ test("a fallback reason outside credit-stop and no-key fails the step and report
assert.equal(run.failed.length, 1, label);
assert.match(run.failed[0], /credit-stop/u, label);
assert.match(run.failed[0], /no-key/u, label);
assert.match(run.failed[0], /\bauth\b/u, label);
assert.deepEqual(run.notices, [], label);
assert.deepEqual(run.errors, [], label);
assert.deepEqual(run.warnings, [], label);
Expand Down
42 changes: 28 additions & 14 deletions .github/actions/run-claude-cli/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ description: >-
Run one prompt with headless `claude -p` for an agent-mode CI lane, on a
Linux runner, on exactly one credential: set `api-key` or
`subscription-token`, never both (the action fails closed otherwise). A
key leg that ends in a credit stop (classify.cjs isCreditStop) sets
lane-class `credit-stop`; a caller that falls back to the subscription
runs it as a second job on a fixed GitHub-hosted runner, gated on that
exact value (see the README's two-job pattern), never in this job.
key leg that ends in a credit stop (classify.cjs isCreditStop, lane-class
`credit-stop`) or a key the API refused with status 401, 402 or 403
(lane-class `auth`) sets handoff `true`;
a caller that falls back to the subscription runs it as a second job on a
fixed GitHub-hosted runner, gated on that exact value (see the README's
two-job pattern), never in this job.
The leg's CLI environment has every credential and file-command variable
removed and its one credential set, and the CLI runs with `--restricted`
and `--strict-mcp-config`; the step's GITHUB_ENV, GITHUB_PATH, GITHUB_OUTPUT,
Expand Down Expand Up @@ -122,15 +124,14 @@ inputs:
default: ""
cli-version:
description: >-
An exact major.minor.patch, or `latest`, which resolves the newest
@anthropic-ai/claude-code release with `npm view` at run time. The
default is pinned to 2.1.304 (`npm view @anthropic-ai/claude-code
version`, 2026-10-20). The resolved version is logged and output. The
`latest` (the default) resolves the newest @anthropic-ai/claude-code
release with `npm view` at run time; an exact major.minor.patch
reproduces a run. The resolved version is logged and output. The
install fails unless `npm audit signatures` verifies the wrapper and
platform packages and the binary matches the release's GPG-signed
manifest.json, so the version must be 2.1.89 or later.
required: false
default: 2.1.304
default: latest
watchdog-max-wait-ms:
description: CLAUDE_CODE_RETRY_WATCHDOG_MAX_WAIT_MS, the most each request waits out 429 and 529 errors.
required: false
Expand All @@ -146,11 +147,12 @@ outputs:
lane-class:
description: >-
The leg's failure class; empty on success. `credit-stop` (key leg only)
means the caller may run the subscription leg in a separate job; a
caller that does not reports it as `rate-limit`, the class
report-lane-outcome knows. Otherwise it is report-lane-outcome's
class: a failed install or integrity check reports `install-failed`,
and any other failure before the leg ran, or a leg whose stdout passes
means the key's credits are used up; a caller that does not fall back
reports it as `rate-limit`, the class report-lane-outcome knows.
`auth` means the credential is unusable: API status 401 (disabled or
deleted), 402 (billing) or 403 (permission). Otherwise it is
report-lane-outcome's class: a failed install or integrity check
reports `install-failed`, and any other failure before the leg ran, or a leg whose stdout passes
256 MiB, reports `other`. Report this class; do not reclassify execution-file, which
cannot see the credit-stop or leg-timeout rules. Set after the step
files are restored, so the leg cannot set it.
Expand All @@ -159,6 +161,18 @@ outputs:
|| (steps.isolation.outcome == 'success' && steps.install.outcome == 'failure' && 'install-failed')
|| (steps.run.outcome != 'success' && 'other')
|| '' }}
handoff:
description: >-
`true` when a key leg ended in `credit-stop`, or in `auth` with the
numeric API status 401, 402 or 403, so the caller may run the
subscription leg in a separate job; `false` otherwise; empty when the
step failed before the leg ran. A 403 hands off too: lane role keys
are whole-account Console keys with no per-key scope, so a 403 means
the key or its workspace is misconfigured; the run hands off so the
lane keeps running, and the caller's status job warns on every such
run until the owner replaces the key. lane-class keeps the reason.
Set after the step files are restored, so the leg cannot set it.
value: ${{ steps.run.outputs.handoff }}
lane-resets:
description: ISO 8601 time the blocking limit lifts, when the CLI's structured output gives it; else empty.
value: ${{ steps.run.outputs.lane-resets }}
Expand Down
77 changes: 58 additions & 19 deletions .github/actions/run-claude-cli/lane.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// Security contract:
// - One leg per invocation: readConfig fails closed unless exactly one of
// the two credentials is set. A caller that falls back to the
// subscription after a key-leg credit stop runs a second job, on a fresh
// runner, gated on this one's lane-class output being `credit-stop`.
// subscription after a key leg hands off (a credit stop, or class auth
// with api_error_status 401, 402 or 403, NEXT_STEPS) runs a second job,
// on a fresh runner, gated on this one's handoff output being `true`.
// - legEnv copies the step environment and removes every credential and
// file-command VARIABLE, then sets the leg's one credential. That is a
// denylist, not a sandbox: code the leg runs (a Bash tool call, a hook)
Expand Down Expand Up @@ -130,18 +131,51 @@ const UNSAFE_VARIABLES = new Set([
"NODE_EXTRA_CA_CERTS",
"NODE_TLS_REJECT_UNAUTHORIZED",
]);
// The job summary's closed token per class: the named stop and its recovery.
const SUMMARY_NOTES = {
"": "",
"credit-stop": "credit stop: add Console credit or raise the spend limit",
"rate-limit": "limit stop: rerun after the reset",
auth: "credential unusable: replace the secret",
overloaded: "API overloaded: rerun later",
"max-turns": "turn cap: raise max-turns or narrow the task",
timeout: "leg timeout: raise leg-timeout-minutes or narrow the task",
other: "see the step log",
// What each class means for the run. `handoff`: a key leg that ends in it
// hands the run to the caller's subscription job; `statuses`, when set,
// narrows that to these numeric api_error_status values, never an error-type
// string, which errors[] text could carry. `note`: the job summary's closed
// token, the named stop and what happens next.
const NEXT_STEPS = {
"": { handoff: false, note: "" },
"credit-stop": {
handoff: true,
note: "credits used up: the subscription job runs; the owner rotates a key by hand when needed",
},
// 401 (key disabled or deleted), 402 (billing) and 403 (permission) hand
// off; an auth class with no numeric status does not.
auth: {
handoff: true,
statuses: [401, 402, 403],
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
note: "credential unusable (rejected, unpaid or not permitted): the owner replaces the secret by hand",
},
"rate-limit": { handoff: false, note: "limit stop: rerun after the reset" },
overloaded: { handoff: false, note: "API overloaded: rerun later" },
"max-turns": {
handoff: false,
note: "turn cap: raise max-turns or narrow the task",
},
timeout: {
handoff: false,
note: "leg timeout: raise leg-timeout-minutes or narrow the task",
},
other: { handoff: false, note: "see the step log" },
};

function nextStep(failureClass) {
return Object.hasOwn(NEXT_STEPS, failureClass)
? NEXT_STEPS[failureClass]
: NEXT_STEPS.other;
}

// Only a key leg hands off: the subscription leg is the last one.
// `apiErrorStatus` is the last message's numeric api_error_status.
function handsOff(leg, failureClass, apiErrorStatus) {
const step = nextStep(failureClass);
if (leg.leg !== "api-key" || !step.handoff) return false;
return step.statuses === undefined || step.statuses.includes(apiErrorStatus);
}

class LaneError extends Error {
constructor(message) {
super(message);
Expand Down Expand Up @@ -262,8 +296,7 @@ function readConfig(env) {
}

// `latest` asks the registry for the newest release; anything else must be an
// exact version (the action's cli-version input defaults to a pinned one).
// Either way the value passes the shared exact-version check before it is
// exact version. Either way the value passes the shared exact-version check before it is
// installed.
function resolveCliVersion(input, npmView) {
const wanted = (input ?? "").trim() || "latest";
Expand Down Expand Up @@ -637,6 +670,7 @@ function runLeg(
const modes = [];
let record;
let judged;
let handoff = false;
try {
const readOnly = readOnlyPaths(
config,
Expand Down Expand Up @@ -681,6 +715,13 @@ function runLeg(
maxTurns: config.maxTurns,
});
}
// The same message classify.cjs reads its status from.
const status = judged.messages.at(-1)?.api_error_status;
handoff = handsOff(
leg,
judged.failureClass,
Number.isInteger(status) ? status : null,
);
record = legRecord({
config,
leg,
Expand All @@ -690,8 +731,7 @@ function runLeg(
messages: judged.messages,
failureClass: judged.failureClass,
resets: judged.resets,
// A credit stop hands the run to the caller's subscription job.
next: judged.failureClass === "credit-stop" ? "subscription" : null,
next: handoff ? "subscription" : null,
message,
});
} finally {
Expand All @@ -706,6 +746,7 @@ function runLeg(
records: [record],
outputs: {
"lane-class": judged.failureClass,
handoff: String(handoff),
"lane-resets": judged.resets ?? "",
"lane-turns": run.turns === null ? "" : String(run.turns),
"lane-models": run.models.join(","),
Expand All @@ -721,11 +762,9 @@ function summaryTable(records) {
String(value ?? "")
.replaceAll("|", "\\|")
.replaceAll("`", "'");
const note = (failureClass) =>
SUMMARY_NOTES[failureClass] ?? SUMMARY_NOTES.other;
const rows = records.map(
(r) =>
`| ${r.leg} | ${cell(r.secret)} | ${cell(r.class || "success")} | ${cell(r.num_turns)} | ${cell(r.denials.count)} | ${cell(r.resets)} | ${cell(r.next)} | ${cell(note(r.class))} |`,
`| ${r.leg} | ${cell(r.secret)} | ${cell(r.class || "success")} | ${cell(r.num_turns)} | ${cell(r.denials.count)} | ${cell(r.resets)} | ${cell(r.next)} | ${cell(nextStep(r.class).note)} |`,
);
return [
"| Leg | Secret | Class | Turns | Denials | Resets | Next | Stop |",
Expand Down
Loading
Loading