mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
fix(cli): warn when run list stops at the server page cap (#16533)
## Thinking Path > - Bounding run history gave `GET /api/companies/:companyId/heartbeat-runs` a default page of 200 runs and a ceiling of 1,000, with no offset parameter and no truncation signal in the response. > - `paperclipai run list` sends `limit` only when `--limit` is passed, makes one request, and the HTTP client returns only the parsed body. So the command prints the newest 200 runs and stops, with no notice — and `--limit 5000` silently stops at 1,000 the same way. > - The issue's expected behavior is that the command either returns every run or says that it did not. > - Returning every run needs server work that is already scoped in open issue #14958 (an `offset` parameter plus `X-Result-Truncated` / `X-Total-Count` headers, and a client that surfaces headers). That is not this PR. > - What the CLI can do today: tell the truth. State the default and the ceiling in the help text, and when a page comes back exactly full — the only truncation sign the current route gives — say on stderr that more runs may exist. ## Linked Issues Fixes #16413 Refs #14958 ## What Changed - `cli/src/commands/client/run.ts`: the `run list` `--limit` help now reads "Maximum runs to return (server default 200, max 1000)", using the shared `HEARTBEAT_RUN_LIST_DEFAULT_LIMIT` / `HEARTBEAT_RUN_LIST_MAX_LIMIT` constants so the text cannot drift from the server values. - Same file: after printing, when the returned row count reaches the effective limit (the requested limit clamped to the server ceiling, or the 200 default), the command prints a notice on stderr: how many runs are shown, the cap that applied, that more runs may exist, and to raise `--limit` to see more. stderr keeps `--json` output on stdout clean and machine-readable. - Tests in `cli/src/__tests__/run.test.ts`: a full 200-row default page triggers exactly one stderr notice and sends no `limit` parameter; a partial page under `--limit 25` stays quiet. ## Verification - `vitest run src/__tests__/run.test.ts` — 5 of 5 pass, including the pre-existing run command tests (request shapes unchanged: no `limit` is sent unless `--limit` is passed). - Disclosure: the CLI package typecheck did not complete in my sandbox (the checker process is very slow against the shared package surface here and was cut off); CI runs the CLI typecheck and is the arbiter. The change uses two constants that are exported from `@paperclipai/shared` today and already imported the same way elsewhere. ## Risks - A company with exactly 200 (or exactly `--limit`) runs gets the notice even though nothing was hidden. The wording says more runs *may* exist, which is the strongest claim the current route supports; #14958's headers will let a later change make it exact. - This PR deliberately does not page or raise the default page size: the server bound exists to keep run-history reads cheap, and silently requesting 1,000 by default would change the command's cost profile for every user. Full retrieval lands with #14958. ## Model Used - **Provider / Model ID:** Meta, Muse Spark 1.3 - **Context window:** 1M+ tokens (exact limit not disclosed); large-repository tasks with long tool transcripts - **Capabilities:** agentic coding with tool use — file editing, shell execution, test execution, browser and API access, multi-step planning ## 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 `#NNN` / `github.com/paperclipai/paperclip` URLs) - [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 --------- Signed-off-by: Josh Cox <joshuacox@users.noreply.github.com> Co-authored-by: Review <review@local>
This commit is contained in:
1 parent
599867caac
commit
a072b17067
2 files changed
+124
-1
No files matched your search
@@ -217,4 +217,97 @@ describe("run inspection commands", () => {
|
||||
expect(fetchMock.mock.calls[3]?.[0]).toBe("http://localhost:3100/api/issues/PC-1/live-runs");
|
||||
expect(fetchMock.mock.calls[4]?.[0]).toBe("http://localhost:3100/api/issues/PC-1/active-run");
|
||||
});
|
||||
it("warns on stderr when run list returns a full server-capped page", async () => {
|
||||
const page = Array.from({ length: 200 }, (_, i) => ({
|
||||
id: `33333333-3333-4333-8333-${String(i).padStart(12, "0")}`,
|
||||
companyId: COMPANY_ID,
|
||||
agentId: AGENT_ID,
|
||||
status: "succeeded",
|
||||
invocationSource: "on_demand",
|
||||
}));
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify(page), { status: 200 }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
await createProgram().parseAsync([
|
||||
"run", "list",
|
||||
"--api-base", "http://localhost:3100",
|
||||
"--api-key", "board-token",
|
||||
"--company-id", COMPANY_ID,
|
||||
], { from: "user" });
|
||||
|
||||
// No limit is sent by default, and the full 200-row page is flagged.
|
||||
expect(fetchMock.mock.calls[0]?.[0]).toBe(
|
||||
`http://localhost:3100/api/companies/${COMPANY_ID}/heartbeat-runs`,
|
||||
);
|
||||
expect(errSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errSpy.mock.calls[0]?.[0]).toContain("newest 200 runs");
|
||||
expect(errSpy.mock.calls[0]?.[0]).toContain("1000 max");
|
||||
});
|
||||
|
||||
it("warns when a negative limit makes the server return a single run", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify([
|
||||
{ id: RUN_ID, companyId: COMPANY_ID, agentId: AGENT_ID, status: "succeeded", invocationSource: "on_demand" },
|
||||
]), { status: 200 }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
await createProgram().parseAsync([
|
||||
"run", "list",
|
||||
"--api-base", "http://localhost:3100",
|
||||
"--api-key", "board-token",
|
||||
"--company-id", COMPANY_ID,
|
||||
"--limit=-1",
|
||||
], { from: "user" });
|
||||
|
||||
expect(errSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errSpy.mock.calls[0]?.[0]).toContain("newest 1 runs");
|
||||
});
|
||||
|
||||
it("does not advise raising --limit when the page already hit the server ceiling", async () => {
|
||||
const page = Array.from({ length: 1000 }, (_, i) => ({
|
||||
id: `33333333-3333-4333-8333-${String(i).padStart(12, "0")}`,
|
||||
companyId: COMPANY_ID,
|
||||
agentId: AGENT_ID,
|
||||
status: "succeeded",
|
||||
invocationSource: "on_demand",
|
||||
}));
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify(page), { status: 200 }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
await createProgram().parseAsync([
|
||||
"run", "list",
|
||||
"--api-base", "http://localhost:3100",
|
||||
"--api-key", "board-token",
|
||||
"--company-id", COMPANY_ID,
|
||||
"--limit", "5000",
|
||||
], { from: "user" });
|
||||
|
||||
expect(errSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errSpy.mock.calls[0]?.[0]).toContain("newest 1000 runs");
|
||||
expect(errSpy.mock.calls[0]?.[0]).not.toContain("Raise --limit");
|
||||
});
|
||||
|
||||
it("stays quiet when run list returns a partial page", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify([
|
||||
{ id: RUN_ID, companyId: COMPANY_ID, agentId: AGENT_ID, status: "running", invocationSource: "on_demand" },
|
||||
]), { status: 200 }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
await createProgram().parseAsync([
|
||||
"run", "list",
|
||||
"--api-base", "http://localhost:3100",
|
||||
"--api-key", "board-token",
|
||||
"--company-id", COMPANY_ID,
|
||||
"--limit", "25",
|
||||
], { from: "user" });
|
||||
|
||||
expect(errSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { HEARTBEAT_RUN_LIST_DEFAULT_LIMIT, HEARTBEAT_RUN_LIST_MAX_LIMIT } from "@paperclipai/shared";
|
||||
import type { HeartbeatRun, HeartbeatRunEvent, Issue, WorkspaceOperation } from "@paperclipai/shared";
|
||||
import {
|
||||
addCommonClientOptions,
|
||||
@@ -50,7 +51,10 @@ export function registerRunCommands(command: Command): void {
|
||||
.description("List heartbeat runs for a company")
|
||||
.option("-C, --company-id <id>", "Company ID")
|
||||
.option("--agent-id <id>", "Filter by agent ID")
|
||||
.option("--limit <n>", "Maximum runs to return")
|
||||
.option(
|
||||
"--limit <n>",
|
||||
`Maximum runs to return (server default ${HEARTBEAT_RUN_LIST_DEFAULT_LIMIT}, max ${HEARTBEAT_RUN_LIST_MAX_LIMIT})`,
|
||||
)
|
||||
.action(async (opts: RunListOptions) => {
|
||||
try {
|
||||
const ctx = resolveCommandContext(opts, { requireCompany: true });
|
||||
@@ -62,6 +66,32 @@ export function registerRunCommands(command: Command): void {
|
||||
`${apiPath`/api/companies/${ctx.companyId}/heartbeat-runs`}${query ? `?${query}` : ""}`,
|
||||
)) ?? [];
|
||||
printRuns(rows, ctx.json);
|
||||
// The route returns one bounded page (200 by default, 1,000 at
|
||||
// most) with no offset and no truncation signal, so a full page
|
||||
// is the only sign that more runs may exist. Say so on stderr
|
||||
// instead of silently stopping; stdout stays clean for --json.
|
||||
// Real paging needs the offset/headers work in #14958.
|
||||
const requestedLimit = opts.limit ? Number.parseInt(opts.limit, 10) : Number.NaN;
|
||||
// Mirror the route's own clamp exactly: an unparsable or zero
|
||||
// limit falls back to the default, and any other value is
|
||||
// clamped into [1, MAX] (so a negative limit means one run).
|
||||
const effectiveLimit = Math.max(
|
||||
1,
|
||||
Math.min(
|
||||
requestedLimit || HEARTBEAT_RUN_LIST_DEFAULT_LIMIT,
|
||||
HEARTBEAT_RUN_LIST_MAX_LIMIT,
|
||||
),
|
||||
);
|
||||
if (rows.length >= effectiveLimit) {
|
||||
console.error(
|
||||
effectiveLimit >= HEARTBEAT_RUN_LIST_MAX_LIMIT
|
||||
? `Showing the newest ${rows.length} runs. The server caps this list at ${HEARTBEAT_RUN_LIST_MAX_LIMIT} runs per request, `
|
||||
+ "so more runs may exist, but this command cannot page past the cap yet."
|
||||
: `Showing the newest ${rows.length} runs. The server caps this list at ${effectiveLimit} runs per request `
|
||||
+ `(${HEARTBEAT_RUN_LIST_DEFAULT_LIMIT} by default, ${HEARTBEAT_RUN_LIST_MAX_LIMIT} max), so more runs may exist. `
|
||||
+ "Raise --limit to see more.",
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
handleCommandError(err);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user