fix(pi-local): avoid embedding model catalogue in errors (#13628)

<!-- Write all pull request text in Simplified Technical English
(ASD-STE100): short sentences, one instruction per sentence, simple
approved vocabulary, and the active voice. -->

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The pi-local adapter discovers and validates models before it starts
a local Pi process
> - An unavailable-model error included model IDs from the discovered
catalogue
> - Repeating those IDs made persisted and rendered failures noisy and
exposed substitute choices
> - This pull request keeps the requested model, reports the available
count, and points to the existing lookup command
> - The benefit is a concise error without changing model discovery or
matching

## Linked Issues or Issue Description

Fixes #13612

## What Changed

- Replace model catalogue interpolation in unavailable-model errors with
the requested model, normalized model count, and `pi --list-models`.
- Add a regression test with 13 discovered models and exact
error-message matching.

## Verification

- `pnpm exec vitest run
packages/adapters/pi-local/src/server/models.test.ts`
- `pnpm exec vitest run packages/adapters/pi-local/src/server/*.test.ts`
- `pnpm --filter @paperclipai/adapter-pi-local typecheck`
- `git diff --check`

All listed checks pass locally. The test suite uses a temporary Pi
executable and verifies that model IDs are not appended to the error.

## Risks

Low risk. Only unavailable-model error wording changes. Model discovery,
matching, valid model execution, and failure handling remain unchanged.
Full repository CI was not run locally because the host uses Node
22.22.1 and the repository declares Node >=24.11.0.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI GPT-5.6 Luna (`gpt-5.6-luna`); tool-assisted code execution. The
context window size is not exposed in this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [ ] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub #13612)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
This commit is contained in:
lorenzozane authored and GitHub committed 2026-10-10 10:48:00 -05:00
1 parent 28e134873e
commit 0e37a385e6
2 files changed
+34 -2

No files matched your search

@@ -1,3 +1,6 @@
import { chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
ensurePiModelConfiguredAndAvailable,
@@ -30,4 +33,34 @@ describe("pi models", () => {
}),
).rejects.toThrow();
});
it("does not embed the model catalogue when the configured model is unavailable", async () => {
const directory = await mkdtemp(join(tmpdir(), "paperclip-pi-models-"));
const command = join(directory, "pi");
const modelIds = Array.from({ length: 13 }, (_, index) => `provider/model-${index}`);
await writeFile(
command,
`#!/bin/sh\nprintf 'provider model\\n';\n${modelIds
.map((id) => {
const [provider, model] = id.split("/");
return `printf '${provider} ${model}\\n'`;
})
.join(";\n")}\n`,
);
await chmod(command, 0o755);
try {
await expect(
ensurePiModelConfiguredAndAvailable({
command,
model: "provider/missing",
}),
).rejects.toMatchObject({
message:
"Configured Pi model is unavailable: provider/missing. 13 models are available; list them with `pi --list-models`.",
});
} finally {
await rm(directory, { recursive: true, force: true });
}
});
});
@@ -188,9 +188,8 @@ export async function ensurePiModelConfiguredAndAvailable(input: {
}
if (!models.some((entry) => entry.id === model)) {
const sample = models.slice(0, 12).map((entry) => entry.id).join(", ");
throw new Error(
`Configured Pi model is unavailable: ${model}. Available models: ${sample}${models.length > 12 ? ", ..." : ""}`,
`Configured Pi model is unavailable: ${model}. ${models.length} models are available; list them with \`pi --list-models\`.`,
);
}