Start model-less Pi agents on Pi's configured default model (#5343)

A Pi agent created without a model took the first entry of Pi's model
list, which ignores defaultProvider/defaultModel in Pi's settings. The Pi
catalog now marks the model a fresh Pi session reports in get_state as
the default, so the daemon's default-model fallback picks it.

Closes #4918

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
paseo-bot[bot]
2026-09-25 01:59:26 +02:00
committed by GitHub
parent 28507224dc
commit 84304b5532
2 changed files with 36 additions and 5 deletions
@@ -2505,6 +2505,26 @@ describe("PiRpcAgentClient", () => {
expect(pi.recordedLaunches[0]).toMatchObject({ cwd: "/workspace/with-extension" });
});
test("marks the model Pi resolves from its own settings as the catalog default", async () => {
const pi = new FakePi();
const unconfigured = { provider: "openai", id: "gpt-4", name: "GPT-4", reasoning: false };
const configured = { provider: "zai", id: "glm-5.3", name: "GLM-5.3", reasoning: true };
pi.queueSessionSetup((session) => {
session.models = [unconfigured, configured];
session.state = { ...session.state, model: configured };
});
const catalog = await createClient(pi).fetchCatalog({
scope: "workspace",
cwd: "/workspace/project",
force: false,
});
expect(catalog.models.filter((model) => model.isDefault).map((model) => model.id)).toEqual([
"zai/glm-5.3",
]);
});
test("honors per-model Pi thinking maps and clamps the catalog default upward", async () => {
const pi = new FakePi();
pi.queueSessionSetup((session) => {
@@ -2664,12 +2664,23 @@ export class PiRpcAgentClient implements AgentClient {
});
if (!runtimeSession) throw new Error("Pi catalog runtime did not start");
const catalogSession = runtimeSession;
const piModels = await runProviderRefreshActivity(context, "get_available_models", () =>
catalogSession.getAvailableModels(null),
);
// A fresh Pi session starts on the model Pi resolves from its own settings.
const { model: configuredModel } = await runProviderRefreshActivity(
context,
"get_state",
() => catalogSession.getState(),
);
const models = transformPiModels(
(
await runProviderRefreshActivity(context, "get_available_models", () =>
catalogSession.getAvailableModels(null),
)
).map((model) => mapPiModel(model, PI_PROVIDER)),
piModels.map((model) => {
const mapped = mapPiModel(model, PI_PROVIDER);
const isConfigured =
model.provider === configuredModel?.provider && model.id === configuredModel?.id;
if (isConfigured) mapped.isDefault = true;
return mapped;
}),
);
return { models, modes: [] };
} finally {