Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

feat(advisor): warn when a panel call is billed unlike the notice said

Jack Rudenko5621fd46a86e
diff --git a/packages/cli/src/handlers/advisor-panel-gateway.ts b/packages/cli/src/handlers/advisor-panel-gateway.ts
index 356d70b6..61a4c2db 100644
--- a/packages/cli/src/handlers/advisor-panel-gateway.ts
+++ b/packages/cli/src/handlers/advisor-panel-gateway.ts
@@ -136,6 +136,18 @@ export function createAdvisorPanelGateway(runtime: AdvisorRuntime): AdvisorPanel
};
}
+ const plannedIndex = build.firstCallableHop;
+ const plannedHop = plannedIndex === null ? undefined : req.plan.hops[plannedIndex];
+ const planned = plannedHop
+ ? {
+ plannedHop: {
+ provider: plannedHop.provider,
+ displayName: plannedHop.displayName,
+ billing: plannedHop.billing,
+ },
+ }
+ : {};
+
const secrets = createSigningSecrets();
const controller = new AbortController();
const request = new Request(ADVISOR_INTERNAL_URL, {
@@ -170,6 +182,7 @@ export function createAdvisorPanelGateway(runtime: AdvisorRuntime): AdvisorPanel
bodyText: "",
streamFailure: false,
hops: snapshot(),
+ ...planned,
failure: {
kind: "timeout",
message: `timed out after ${Math.round(req.timeoutMs / 1000)}s`,
@@ -182,6 +195,7 @@ export function createAdvisorPanelGateway(runtime: AdvisorRuntime): AdvisorPanel
bodyText: outcome.text,
streamFailure: isStreamFailureResponse(outcome.res),
hops: snapshot(),
+ ...planned,
latencyMs: latencyMs(),
};
} catch (err) {
@@ -190,6 +204,7 @@ export function createAdvisorPanelGateway(runtime: AdvisorRuntime): AdvisorPanel
bodyText: "",
streamFailure: false,
hops: snapshot(),
+ ...planned,
failure: {
kind: "internal",
message: redactExactValues(redactForClient(errorMessage(err)), secrets.values),
diff --git a/packages/cli/src/handlers/advisor-route-plan.ts b/packages/cli/src/handlers/advisor-route-plan.ts
index b490e6b5..91afc887 100644
--- a/packages/cli/src/handlers/advisor-route-plan.ts
+++ b/packages/cli/src/handlers/advisor-route-plan.ts
@@ -701,6 +701,8 @@ export interface AdvisorPanelResult {
streamFailure: boolean;
/** Snapshot of the hop log: every hop whose `handle()` was entered, in order. */
hops: Array<HopAttempt & { uid: string | null; displayName: string }>;
+ /** The chain's first callable hop at startup: what the notice promised this member. */
+ plannedHop?: { provider: string; displayName: string; billing: AdvisorBilling };
failure?: { kind: "timeout" | "internal"; message: string };
latencyMs: number;
}
diff --git a/packages/cli/src/handlers/native-handler-advisor.ts b/packages/cli/src/handlers/native-handler-advisor.ts
index 5a57e30d..720ef3ad 100644
--- a/packages/cli/src/handlers/native-handler-advisor.ts
+++ b/packages/cli/src/handlers/native-handler-advisor.ts
@@ -63,6 +63,7 @@ import {
type AdvisorPanelGateway,
type AdvisorPanelResult,
type AdvisorTurn,
+ billingWord,
buildAdvisorPanelPayload,
describeAdvisorRefusal,
extractAdvice,
@@ -1023,6 +1024,7 @@ export function _debug_resetTrackedAdvisorIds(): void {
inFlightByToolUseId.clear();
streamFrameBuffer.reset();
reportedUnrecorded.clear();
+ servedUnlikePlan.clear();
clock = Date.now;
lastSweepAt = Number.NEGATIVE_INFINITY;
}
@@ -2996,7 +2998,7 @@ async function runAdvisorMember(
billing: null,
};
case "routed":
- return runRoutedMember(plan, req, params.gateway);
+ return runRoutedMember(plan, req, params.gateway, params.warn);
case "claude-native":
return runClaudeMember(plan, req, params, claudeAuth);
}
@@ -3005,7 +3007,8 @@ async function runAdvisorMember(
async function runRoutedMember(
plan: Extract<AdvisorModelPlan, { kind: "routed" }>,
req: MemberRequest,
- gateway: AdvisorPanelGateway | undefined
+ gateway: AdvisorPanelGateway | undefined,
+ warn?: (message: string) => void
): Promise<AdvisorModelOutcome> {
const recordRoute: AdvisorRecordRoute = {
kind: "routed",
@@ -3031,7 +3034,49 @@ async function runRoutedMember(
),
timeoutMs: req.timeoutMs,
});
- return { ...classifyPanelResult(result, base, paths), recordRoute };
+ const outcome = classifyPanelResult(result, base, paths);
+ warnWhenServedUnlikePlan(req, result.plannedHop, outcome.servedBy, warn);
+ return { ...outcome, recordRoute };
+}
+
+/**
+ * The hop that last served each routed member, when its billing differs from
+ * the hop the startup notice named, keyed `"<role>:<spec>"`. `FallbackHandler`
+ * starts every later call at the last hop that served (`lastSuccessIndex`), so
+ * after one transient subscription failure that a metered hop answered, every
+ * later call of that member is metered too — exactly as on main routing (R3).
+ * That is accepted, but never silent: one line per change.
+ */
+const servedUnlikePlan = new Map<string, string>();
+
+/**
+ * Warn once per change when a routed call was served by a hop whose billing
+ * differs from the startup notice's first callable hop:
+ * `[advisor] <spec> was served by <displayName> (<billing>), not <planned> as
+ * the notice said; later calls start there (routing keeps the last hop that
+ * served)`. A call served as planned clears the record, so a later drift warns
+ * again.
+ */
+function warnWhenServedUnlikePlan(
+ req: MemberRequest,
+ planned: AdvisorPanelResult["plannedHop"],
+ servedBy: AdvisorServedBy | null | undefined,
+ warn: (message: string) => void = warnAdvisor
+): void {
+ if (!planned || !servedBy?.billing) return;
+ const key = `${req.role}:${req.spec}`;
+ if (servedBy.billing === planned.billing) {
+ servedUnlikePlan.delete(key);
+ return;
+ }
+ const served = `${servedBy.provider}:${servedBy.billing}`;
+ if (servedUnlikePlan.get(key) === served) return;
+ servedUnlikePlan.set(key, served);
+ warn(
+ `${req.spec} was served by ${servedBy.displayName} (${billingWord(servedBy.billing)}), ` +
+ `not ${planned.displayName} (${billingWord(planned.billing)}) as the notice said; later ` +
+ "calls start there (routing keeps the last hop that served)"
+ );
}
/** The hop-log facts of a routed call: which hops were entered, and the last one. */