fix(cli): wait for daemon feature flags

Provider and pairing gates now wait for the daemon's server_info message instead of reading the cache immediately after connect. This removes a startup race where slower CLI cold starts could treat a supported daemon as missing the feature.
This commit is contained in:
Mohamed Boudra
2026-07-02 13:31:48 +02:00
parent 5d67032ef6
commit 02ec891fe4
11 changed files with 206 additions and 39 deletions
+7 -8
View File
@@ -33,10 +33,9 @@ export async function runPairCommand(options: PairOptions): Promise<void> {
if (host) {
const client = await tryConnectToDaemon({ host, timeout: 1500 });
if (client) {
const supportsDaemonStatusRpc =
client.getLastServerInfoMessage()?.features?.daemonStatusRpc === true;
if (supportsDaemonStatusRpc) {
try {
try {
const serverInfo = await client.waitForServerInfo(PAIRING_DAEMON_RPC_TIMEOUT_MS);
if (serverInfo.features?.daemonStatusRpc === true) {
const offer = await client.getDaemonPairingOffer({
timeout: PAIRING_DAEMON_RPC_TIMEOUT_MS,
});
@@ -46,11 +45,11 @@ export async function runPairCommand(options: PairOptions): Promise<void> {
options,
);
return;
} catch {
// COMPAT(daemon-rpc-rollout): fall back to CLI-side pairing generation while
// old daemons lack daemonStatusRpc. Remove once the daemon floor is past
// v0.1.76; pairing should come from daemon.get_pairing_offer.
}
} catch {
// COMPAT(daemon-rpc-rollout): fall back to CLI-side pairing generation while
// old daemons lack daemonStatusRpc. Remove once the daemon floor is past
// v0.1.76; pairing should come from daemon.get_pairing_offer.
}
await client.close().catch(() => {});
}
@@ -27,7 +27,7 @@ interface RecordingClientInput {
function createClient(input: RecordingClientInput) {
return {
getLastServerInfoMessage: () => ({
waitForServerInfo: async () => ({
status: "server_info",
serverId: "test-daemon",
features: input.features ?? { paseoAgentCatalog: true },
@@ -619,7 +619,7 @@ describe("provider add", () => {
},
write: () => {},
connectDaemon: async () => ({
getLastServerInfoMessage: () => ({
waitForServerInfo: async () => ({
status: "server_info",
serverId: "test-daemon",
features: {},
+2 -2
View File
@@ -48,7 +48,7 @@ interface ProviderConfiguredItem {
interface ProviderAddClient extends Pick<
DaemonClient,
| "getLastServerInfoMessage"
| "waitForServerInfo"
| "getPaseoAgentCatalog"
| "setPaseoAgentProvider"
| "startPaseoAgentOAuth"
@@ -462,7 +462,7 @@ export async function runAddCommand(
const deps = { ...defaultDependencies, ...dependencies };
const client = await deps.connectDaemon({ host: options.host });
try {
requirePaseoAgentCatalogFeature(client);
await requirePaseoAgentCatalogFeature(client);
const catalogResult = await client.getPaseoAgentCatalog();
if (catalogResult.error) {
throw {
@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";
import type { ServerInfoStatusPayload } from "@getpaseo/protocol/messages";
import { requirePaseoAgentCatalogFeature } from "./feature.js";
function createServerInfo(features: ServerInfoStatusPayload["features"]): ServerInfoStatusPayload {
return {
status: "server_info",
serverId: "test-daemon",
features,
};
}
describe("provider feature gate", () => {
it("waits for delayed server_info before allowing catalog commands", async () => {
let resolveServerInfo: ((serverInfo: ServerInfoStatusPayload) => void) | null = null;
const allowed = requirePaseoAgentCatalogFeature({
waitForServerInfo: async () =>
new Promise<ServerInfoStatusPayload>((resolve) => {
resolveServerInfo = resolve;
}),
});
expect(resolveServerInfo).not.toBeNull();
resolveServerInfo?.(createServerInfo({ paseoAgentCatalog: true }));
await expect(allowed).resolves.toBeUndefined();
});
it("surfaces the server_info wait timeout", async () => {
const timeoutError = new Error("Timed out waiting for server_info status message (5ms)");
await expect(
requirePaseoAgentCatalogFeature({
waitForServerInfo: async () => {
throw timeoutError;
},
}),
).rejects.toThrow("Timed out waiting for server_info status message (5ms)");
});
it("requires the catalog feature when server_info arrives without it", async () => {
await expect(
requirePaseoAgentCatalogFeature({
waitForServerInfo: async () => createServerInfo({ paseoAgentCatalog: false }),
}),
).rejects.toMatchObject({
code: "HOST_UPDATE_REQUIRED",
message: "Update the Paseo daemon to use this command.",
});
});
});
@@ -1,13 +1,13 @@
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import type { CommandError } from "../../output/index.js";
export interface PaseoAgentCatalogFeatureClient extends Pick<
DaemonClient,
"getLastServerInfoMessage"
> {}
export interface PaseoAgentCatalogFeatureClient extends Pick<DaemonClient, "waitForServerInfo"> {}
export function requirePaseoAgentCatalogFeature(client: PaseoAgentCatalogFeatureClient): void {
if (client.getLastServerInfoMessage()?.features?.paseoAgentCatalog === true) {
export async function requirePaseoAgentCatalogFeature(
client: PaseoAgentCatalogFeatureClient,
): Promise<void> {
const serverInfo = await client.waitForServerInfo();
if (serverInfo.features?.paseoAgentCatalog === true) {
return;
}
throw {
@@ -16,7 +16,7 @@ describe("provider ls", () => {
it("renders an empty configured-provider table with headers", async () => {
const result = await runLsCommand({ host: "localhost:7777" }, {} as never, {
connectDaemon: async () => ({
getLastServerInfoMessage: createServerInfo,
waitForServerInfo: async () => createServerInfo(),
getPaseoAgentCatalog: async () => ({
requestId: "catalog-1",
catalog: [],
@@ -42,7 +42,7 @@ describe("provider ls", () => {
connectDaemon: async (options) => {
expect(options.host).toBe("localhost:7777");
return {
getLastServerInfoMessage: createServerInfo,
waitForServerInfo: async () => createServerInfo(),
getPaseoAgentCatalog: async () => ({
requestId: "catalog-1",
catalog: [
@@ -142,7 +142,7 @@ describe("provider rm", () => {
connectDaemon: async (options) => {
expect(options.host).toBe("localhost:7777");
return {
getLastServerInfoMessage: createServerInfo,
waitForServerInfo: async () => createServerInfo(),
removePaseoAgentProvider: async (name: string) => {
removedNames.push(name);
return {
+2 -2
View File
@@ -25,7 +25,7 @@ export interface ProviderListItem {
interface ProviderLsClient extends Pick<
DaemonClient,
"getLastServerInfoMessage" | "getPaseoAgentCatalog" | "getPaseoAgentProviders" | "close"
"waitForServerInfo" | "getPaseoAgentCatalog" | "getPaseoAgentProviders" | "close"
> {}
export interface ProviderLsDependencies {
@@ -80,7 +80,7 @@ export async function runLsCommand(
const client = await deps.connectDaemon({ host: options.host });
try {
requirePaseoAgentCatalogFeature(client);
await requirePaseoAgentCatalogFeature(client);
const catalogResult = await client.getPaseoAgentCatalog();
if (catalogResult.error) {
throw {
+2 -2
View File
@@ -21,7 +21,7 @@ interface ProviderRemoveItem {
interface ProviderRmClient extends Pick<
DaemonClient,
"getLastServerInfoMessage" | "removePaseoAgentProvider" | "close"
"waitForServerInfo" | "removePaseoAgentProvider" | "close"
> {}
export interface ProviderRmDependencies {
@@ -49,7 +49,7 @@ export async function runRmCommand(
const deps = { ...defaultDependencies, ...dependencies };
const client = await deps.connectDaemon({ host: options.host });
try {
requirePaseoAgentCatalogFeature(client);
await requirePaseoAgentCatalogFeature(client);
const result = await client.removePaseoAgentProvider(name);
if (!result.success) {
throw {
+26 -12
View File
@@ -42,6 +42,20 @@ interface ProviderListRow {
models: string;
}
interface CliResult {
exitCode: number;
stdout: string;
stderr: string;
}
function assertExitCode(result: CliResult, expected: number, message: string): void {
assert.strictEqual(result.exitCode, expected, `${message}\nstderr:\n${result.stderr}`);
}
function assertNonZeroExitCode(result: CliResult, message: string): void {
assert.notStrictEqual(result.exitCode, 0, `${message}\nstderr:\n${result.stderr}`);
}
const EXPECTED_CLAUDE_MODELS = [
{
id: "claude-fable-5",
@@ -137,7 +151,7 @@ function parseProviderListJson(stdout: string): ProviderListRow[] {
async function getProviderRows(): Promise<ProviderListRow[]> {
const result = await ctx.paseo(["provider", "ls", "--json"]);
assert.strictEqual(result.exitCode, 0, "provider ls --json should exit 0");
assertExitCode(result, 0, "provider ls --json should exit 0");
return parseProviderListJson(result.stdout);
}
@@ -181,7 +195,7 @@ try {
{
console.log("Test 1: provider --help shows subcommands");
const result = await ctx.paseo(["provider", "--help"]);
assert.strictEqual(result.exitCode, 0, "provider --help should exit 0");
assertExitCode(result, 0, "provider --help should exit 0");
assert(result.stdout.includes("ls"), "help should mention ls");
assert(result.stdout.includes("add"), "help should mention add");
assert(result.stdout.includes("rm"), "help should mention rm");
@@ -193,12 +207,12 @@ try {
{
console.log("Test 2: provider ls on a fresh daemon shows no configured providers");
const result = await ctx.paseo(["provider", "ls"]);
assert.strictEqual(result.exitCode, 0, "provider ls should exit 0");
assertExitCode(result, 0, "provider ls should exit 0");
assertProviderTableHeader(result.stdout);
assert(!result.stdout.includes("OpenRouter"), "fresh output should have no provider rows");
const jsonResult = await ctx.paseo(["provider", "ls", "--json"]);
assert.strictEqual(jsonResult.exitCode, 0, "provider ls --json should exit 0");
assertExitCode(jsonResult, 0, "provider ls --json should exit 0");
assert.deepStrictEqual(parseProviderListJson(jsonResult.stdout), []);
console.log("✓ provider ls on a fresh daemon shows no configured providers\n");
}
@@ -209,7 +223,7 @@ try {
const result = await ctx.paseo(["provider", "add", "openrouter", "--api-key-stdin"], {
stdin: "dummy-openrouter-key\n",
});
assert.strictEqual(result.exitCode, 0, `provider add should exit 0\n${result.stderr}`);
assertExitCode(result, 0, "provider add should exit 0");
assert(result.stdout.includes("openrouter"), "add output should include the instance name");
assert(result.stdout.includes("OpenRouter"), "add output should include the catalog label");
assert(result.stdout.includes("Connected"), "add output should show connected auth state");
@@ -234,7 +248,7 @@ try {
const result = await ctx.paseo(["provider", "add", "openrouter", "--api-key-stdin"], {
stdin: "dummy-openrouter-key-2\n",
});
assert.strictEqual(result.exitCode, 0, `provider add should exit 0\n${result.stderr}`);
assertExitCode(result, 0, "provider add should exit 0");
const rows = await getProviderRows();
assert.strictEqual(rows.length, 1, "re-running add should not create another instance");
@@ -249,7 +263,7 @@ try {
const result = await ctx.paseo(["provider", "add", "nonsense-id", "--api-key-stdin"], {
stdin: "dummy-key\n",
});
assert.notStrictEqual(result.exitCode, 0, "provider add should fail for unknown ids");
assertNonZeroExitCode(result, "provider add should fail for unknown ids");
const output = result.stdout + result.stderr;
assert(output.includes("nonsense-id"), "error should mention the requested id");
assert(output.includes("Known provider ids"), "error should mention known provider ids");
@@ -262,14 +276,14 @@ try {
{
console.log("Test 6: provider rm removes a configured provider");
const result = await ctx.paseo(["provider", "rm", "openrouter"]);
assert.strictEqual(result.exitCode, 0, `provider rm should exit 0\n${result.stderr}`);
assertExitCode(result, 0, "provider rm should exit 0");
assert(result.stdout.includes("openrouter"), "rm output should include the instance name");
assert(result.stdout.includes("yes"), "rm output should report removal");
const rows = await getProviderRows();
assert.deepStrictEqual(rows, [], "provider ls should be empty after removing openrouter");
const table = await ctx.paseo(["provider", "ls"]);
assert.strictEqual(table.exitCode, 0, "provider ls should stay successful after removal");
assertExitCode(table, 0, "provider ls should stay successful after removal");
assertProviderTableHeader(table.stdout);
console.log("✓ provider rm removes a configured provider\n");
}
@@ -280,7 +294,7 @@ try {
const result = await ctx.paseo(["provider", "add", "kimi", "--api-key-stdin"], {
stdin: "dummy-kimi-key\n",
});
assert.strictEqual(result.exitCode, 0, `provider add kimi should exit 0\n${result.stderr}`);
assertExitCode(result, 0, "provider add kimi should exit 0");
assert(result.stdout.includes("kimi"), "add output should include the instance name");
assert(result.stdout.includes("Kimi Coding Plan"), "add output should include the label");
@@ -356,7 +370,7 @@ try {
{
console.log("Test 11: provider models unknown fails with error");
const result = await ctx.paseo(["provider", "models", "unknown"]);
assert.notStrictEqual(result.exitCode, 0, "should fail for unknown provider");
assertNonZeroExitCode(result, "should fail for unknown provider");
const output = result.stdout + result.stderr;
assert(
output.toLowerCase().includes("unknown") || output.toLowerCase().includes("provider"),
@@ -388,7 +402,7 @@ try {
"claude model IDs should be captured from --json output",
);
const result = await ctx.paseo(["provider", "models", "claude", "--quiet"]);
assert.strictEqual(result.exitCode, 0, "should exit 0");
assertExitCode(result, 0, "provider models claude --quiet should exit 0");
const lines = result.stdout.trim().split("\n").filter(Boolean);
assert.strictEqual(
lines.length,