Skip to content

Commit a5f1db4

Browse files
Bewinxedclaude
andcommitted
A machine's own OpenCode sign-in its provider refuses stands on the machine's row, with its fix
The Mac's own OpenCode Anthropic sign-in answered "401 OAuth access token is invalid", and nothing said so until a delegate on anthropic/… failed. A machine's sign-in faults stand on its row (426dfc1). - Core: HarnessReport.signInFaults (provider, words, at) and opencodeSignInFaultWords, the one sentence every surface shows: "OpenCode's own Anthropic sign-in on <machine> was refused: 401 …. Run `opencode auth login` on <machine> and pick Anthropic." - Agent: a session on the machine's own OpenCode server reports each turn's end on its provider (its last step's). A `provider.auth` failure is the sign-in's fault when the machine's own OpenCode holds an active credential for that provider (Zen's keyless free tier refusing is no sign-in's); the next turn that answers on that provider clears it. Kept across a restart (cawco-sign-in-faults.json), in the OpenCode report, and sent on the next beat when it moves. The provider is named as the held catalog names it. - Web (signInWarning, exceptionOf) and the Apple app (MachineHealth): the machine's row says OpenCode's words too, and every harness's sign-in words together: pi's no longer hides OpenCode's (it did on both). - Where CawCo reads an execution's end: a note that OpenCode 2.0.28 settles a failure before the first model step as succeeded (anomalyco/opencode#34839, fixed by #45959, unreleased in 2.0.29), to check on the upgrade that carries it. - scratch-fleet: a mock reply can refuse with a status (Reply.deny). - OpenAPI regenerated (SignInFault). Proof: scripts/probe-kit/specs/web/opencode-sign-in-fault.ts (scratch fleet, the machine's own anthropic credential, the mock answering 401 then 200): ALL PASS. The Apple app's change is not built here (no Xcode in this workspace). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2d1f8b9 commit a5f1db4

12 files changed

Lines changed: 525 additions & 14 deletions

File tree

‎apps/apple/Packages/CawCoKit/Sources/CawCoAPI/openapi.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32888,6 +32888,13 @@
3288832888
"$ref": "#/components/schemas/ModelInfo"
3288932889
}
3289032890
},
32891+
"signInFaults": {
32892+
"description": "OpenCode only: each of the machine's own OpenCode sign-ins (not a CawCo\naccount) whose provider refused it the last time a session here used\nit, until a turn on that provider succeeds. The home says each on the\nmachine's row, with the fix ({@link opencodeSignInFaultWords}).",
32893+
"type": "array",
32894+
"items": {
32895+
"$ref": "#/components/schemas/SignInFault"
32896+
}
32897+
},
3289132898
"version": {
3289232899
"description": "The CLI/SDK version, when it can be read.",
3289332900
"type": "string"
@@ -33108,6 +33115,29 @@
3310833115
"xhigh"
3310933116
]
3311033117
},
33118+
"SignInFault": {
33119+
"description": "One of a machine's own sign-ins its provider refused ({@link HarnessReport.signInFaults}).",
33120+
"type": "object",
33121+
"properties": {
33122+
"at": {
33123+
"description": "When the refusal came, epoch ms.",
33124+
"type": "number"
33125+
},
33126+
"provider": {
33127+
"description": "The provider's id in the harness (`anthropic`).",
33128+
"type": "string"
33129+
},
33130+
"words": {
33131+
"description": "What the home says, whole: what was refused, and the fix ({@link opencodeSignInFaultWords}).",
33132+
"type": "string"
33133+
}
33134+
},
33135+
"required": [
33136+
"at",
33137+
"provider",
33138+
"words"
33139+
]
33140+
},
3311133141
"MachineCapabilities": {
3311233142
"type": "object",
3311333143
"properties": {

‎apps/apple/Packages/CawCoKit/Sources/CawCoScreens/Shell/Machines.swift‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ import UIKit
1212
// MARK: Health
1313

1414
/// What is wrong with a machine, in a word or two (home-state.svelte.ts
15-
/// `exceptionOf`): it is unreachable, pi cannot sign in, its build is behind
16-
/// the hub's, or a fleet-sync row failed on it. Nil when nothing is.
15+
/// `exceptionOf`): it is unreachable, pi or OpenCode cannot sign in (one of
16+
/// the machine's own OpenCode sign-ins refused, with its fix), its build is
17+
/// behind the hub's, or a fleet-sync row failed on it. Nil when nothing is.
1718
enum MachineHealth {
1819
static func fault(_ machine: MachineRow, hubBuild: Components.Schemas.BuildInfo?) -> String? {
1920
if machine.status != "online" { return "unreachable" }
20-
if let reason = machine.harnesses?.first(where: { $0.harness == .pi })?.authReason { return reason }
21+
// Every harness's sign-in words: one never hides another's.
22+
let signIns = [signIn(machine, .pi), signIn(machine, .opencode)].compactMap { $0 }
23+
if !signIns.isEmpty { return signIns.joined(separator: " ") }
2124
if let commit = machine.build?.commit, let hub = hubBuild?.commit, commit != hub { return "behind hub" }
2225
if syncFailed(machine.fleet) { return "sync failed" }
2326
return nil
2427
}
2528

29+
/// A harness's own words on why it cannot sign in here (machine.ts
30+
/// `signInWarning`): its `authReason`, then each of the machine's own
31+
/// sign-ins its provider refused, in the report's words (core
32+
/// `opencodeSignInFaultWords`). Nil when there are none.
33+
static func signIn(_ machine: MachineRow, _ harness: Components.Schemas.HarnessKind) -> String? {
34+
guard let report = machine.harnesses?.first(where: { $0.harness == harness }) else { return nil }
35+
let said = [report.authReason].compactMap { $0 } + (report.signInFaults ?? []).map(\.words)
36+
return said.isEmpty ? nil : said.joined(separator: " ")
37+
}
38+
2639
/// Every row one machine's fleet report says it could not apply
2740
/// (fleet-faults.ts `machineFaults`), as a yes or no.
2841
static func syncFailed(_ report: Components.Schemas.FleetSyncReport?) -> Bool {

‎apps/dashboard/src/lib/cawco/home/home-state.svelte.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,13 @@ function exceptionOf(machine: (typeof cawco.machines)[number]): string | null {
663663
if (machine.status !== "online") {
664664
return "unreachable";
665665
}
666-
const signIn =
667-
signInWarning(machine, "pi") ?? signInWarning(machine, "opencode");
666+
// Every harness's sign-in words: one never hides another's.
667+
const signIn = [
668+
signInWarning(machine, "pi"),
669+
signInWarning(machine, "opencode"),
670+
]
671+
.filter(Boolean)
672+
.join(" ");
668673
if (signIn) {
669674
return signIn;
670675
}

‎apps/dashboard/src/lib/cawco/machine.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ export function machineOs(os: string) {
2828
* rail needs — which is the remedy, on which machine, and for the macOS case why
2929
* its existing login does not reach its agent. pi's and OpenCode's are their
3030
* reports' own words (`authReason`): pi's sign-in, OpenCode's server refusing
31-
* to start. Undefined when there is nothing to say.
31+
* to start; then OpenCode's own sign-ins their providers refused, each with
32+
* its fix (`signInFaults`, core `opencodeSignInFaultWords`). Undefined when
33+
* there is nothing to say.
3234
*/
3335
export function signInWarning(
3436
machine: AgentRow,
3537
harness: "claude" | "pi" | "opencode" = "claude"
3638
): string | undefined {
3739
if (harness !== "claude") {
38-
return machine.harnesses?.find((report) => report.harness === harness)
39-
?.authReason;
40+
const report = machine.harnesses?.find((one) => one.harness === harness);
41+
const said = [
42+
report?.authReason,
43+
...(report?.signInFaults ?? []).map((fault) => fault.words),
44+
].filter(Boolean);
45+
return said.length > 0 ? said.join(" ") : undefined;
4046
}
4147
switch (machine.auth) {
4248
case "unreadable-credentials":

‎packages/agent/src/daemon.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,10 @@ const attach = (
14861486
);
14871487

14881488
// A spawn also checks pi's sign-in, and any OpenCode call can find its
1489-
// server refusing to start or starting again: a changed word on either
1490-
// goes out on the next heartbeat, the other harnesses' reports kept.
1489+
// server refusing to start or starting again, or a turn find one of the
1490+
// machine's own OpenCode sign-ins refused or answering again: a changed
1491+
// word on either goes out on the next heartbeat, the other harnesses'
1492+
// reports kept.
14911493
const authed = [pi, harness("opencode")].filter(
14921494
(adapter): adapter is Harness => adapter !== undefined
14931495
);
@@ -1498,7 +1500,10 @@ const attach = (
14981500
);
14991501
return (
15001502
old !== undefined &&
1501-
(old.auth !== adapter.auth || old.authReason !== adapter.authReason)
1503+
(old.auth !== adapter.auth ||
1504+
old.authReason !== adapter.authReason ||
1505+
JSON.stringify(old.signInFaults ?? []) !==
1506+
JSON.stringify(adapter.signInFaults ?? []))
15021507
);
15031508
});
15041509
if (moved.length === 0) {
@@ -1509,11 +1514,18 @@ const attach = (
15091514
if (!adapter) {
15101515
return report;
15111516
}
1512-
const { authReason: _oldReason, ...rest } = report;
1517+
const {
1518+
authReason: _oldReason,
1519+
signInFaults: _oldFaults,
1520+
...rest
1521+
} = report;
15131522
return {
15141523
...rest,
15151524
auth: adapter.auth,
15161525
...(adapter.authReason ? { authReason: adapter.authReason } : {}),
1526+
...(adapter.signInFaults?.length
1527+
? { signInFaults: adapter.signInFaults }
1528+
: {}),
15171529
};
15181530
});
15191531
return reportedHarnesses;

‎packages/agent/src/harness.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
SendPayload,
2929
SentMessage,
3030
SessionMessage,
31+
SignInFault,
3132
SpawnPayload,
3233
TextAttachment,
3334
} from "@cawco/core";
@@ -368,6 +369,8 @@ export interface Harness {
368369
sessionsOn?(procId: string): string[];
369370
/** Lifecycle guards read the supervisor's one machine recovery barrier. */
370371
readonly setCustodyReadiness?: (read: () => boolean) => void;
372+
/** The machine's own sign-ins their providers last refused, cached beside {@link auth} (OpenCode's, {@link HarnessReport.signInFaults}). */
373+
readonly signInFaults?: SignInFault[];
371374
/** Start a session; resolves once the runtime handle is in place. */
372375
// biome-ignore lint/style/useConsistentMethodSignatures: method-style kept so implementers (opencode.ts, pi.ts) keep contravariant parameter checking; property-style would change signature variance
373376
spawn(spec: SpawnPayload, ctx: HarnessContext): Promise<HarnessSession>;

‎packages/agent/src/harnesses/opencode-models.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const ATTEMPT_DELAYS_MS = [0, 2000, 8000];
5353
interface CatalogProvider {
5454
env?: unknown;
5555
models?: Record<string, unknown>;
56+
name?: unknown;
5657
}
5758

5859
type Catalog = Record<string, CatalogProvider>;
@@ -243,6 +244,16 @@ class OpencodeModels {
243244
.slice(0, 16);
244245
}
245246

247+
/**
248+
* A provider's name as the catalog gives it, which `opencode auth login`
249+
* lists it under ("Anthropic"); its id when the agent holds no catalog, or
250+
* the catalog names it not.
251+
*/
252+
providerName(id: string): string {
253+
const name = this.#catalog?.[id]?.name;
254+
return typeof name === "string" && name ? name : id;
255+
}
256+
246257
/** The providers whose key OpenCode takes from an environment variable set in `env`. */
247258
providersKeyedIn(env: NodeJS.ProcessEnv): string[] {
248259
return Object.entries(this.#catalog ?? {}).flatMap(([id, provider]) =>

‎packages/agent/src/harnesses/opencode-session.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,12 @@ export interface OpencodeSessionOptions {
597597
ready: Promise<McpNotConnected[]>;
598598
registerChild: (childId: string, callID: string) => void;
599599
sessionId: string;
600+
/**
601+
* A turn ended on `provider` (its last model step's): refused by it with
602+
* `refusal` (an execution failed `provider.auth`, in the provider's words),
603+
* or answered (undefined). The harness keeps it as a sign-in's fault.
604+
*/
605+
turnOutcome: (provider: string, refusal: string | undefined) => void;
600606
workflowStepId?: string;
601607
}
602608

@@ -622,6 +628,12 @@ export class OpencodeSession implements HarnessSession {
622628
/** The instruction entries put on the session, by key, as the hash of the value put. */
623629
readonly #instructions = new Map<string, string>();
624630
readonly #registerChild: (childId: string, callID: string) => void;
631+
readonly #turnOutcome: (
632+
provider: string,
633+
refusal: string | undefined
634+
) => void;
635+
/** The provider of the open turn's last model step: whose answer or refusal its end is. */
636+
#turnProvider: string | undefined;
625637
readonly #onRelease: () => void;
626638
readonly #isConfigGateHeld: (joinsTurn?: boolean) => boolean;
627639
readonly #readActivity: () => Promise<boolean>;
@@ -723,6 +735,7 @@ export class OpencodeSession implements HarnessSession {
723735
this.#workflowStepId = options.workflowStepId;
724736
this.#canDelegate = options.canDelegate;
725737
this.#registerChild = options.registerChild;
738+
this.#turnOutcome = options.turnOutcome;
726739
this.#onRelease = options.onRelease;
727740
this.#isConfigGateHeld = options.isConfigGateHeld;
728741
this.#readActivity = options.readActivity;
@@ -962,6 +975,7 @@ export class OpencodeSession implements HarnessSession {
962975
break;
963976
}
964977
case "session.execution.started":
978+
this.#turnProvider = undefined;
965979
this.#turnRevision += 1;
966980
this.#busy = true;
967981
this.#turnOpen = true;
@@ -971,6 +985,7 @@ export class OpencodeSession implements HarnessSession {
971985
this.#drainQueue();
972986
break;
973987
case "session.step.started": {
988+
this.#turnProvider = event.data.model.providerID;
974989
const id = event.data.assistantMessageID;
975990
const timestamp = new Date(event.data.started).toISOString();
976991
this.#created.set(id, timestamp);
@@ -1187,10 +1202,31 @@ export class OpencodeSession implements HarnessSession {
11871202
session_id: this.sessionId ?? undefined,
11881203
});
11891204
break;
1205+
// A turn's end, as OpenCode 2.0.28 says it. A failure before its first
1206+
// model step (`models.resolve`, context preparation) is only logged
1207+
// ("Failed to drain Session") and the execution still settles
1208+
// `succeeded`, so such a turn ends here with no answer and no error:
1209+
// anomalyco/opencode#34839, fixed by #45959, unreleased as of 2.0.29.
1210+
// On the upgrade that carries it, check that the failure arrives here as
1211+
// `session.execution.failed`. A refusal by the provider itself (Zen's
1212+
// free tier, a 401) does arrive as `failed` on 2.0.28 (observed).
11901213
case "session.execution.succeeded":
1214+
if (this.#turnProvider) {
1215+
this.#turnOutcome(this.#turnProvider, undefined);
1216+
}
11911217
this.#turnEnded();
11921218
break;
11931219
case "session.execution.failed":
1220+
if (this.#turnProvider && event.data.error.type === "provider.auth") {
1221+
const { message, status } = event.data.error as {
1222+
message: string;
1223+
status?: number;
1224+
};
1225+
this.#turnOutcome(
1226+
this.#turnProvider,
1227+
status ? `${status} ${message}` : message
1228+
);
1229+
}
11941230
this.#turnEnded({
11951231
subtype: "error_during_execution",
11961232
is_error: true,

0 commit comments

Comments
 (0)